It provides attractive option when the user can download and try your application before he/she can purchase your app. But just because you provide trial application means you can’t make money doing so. You can display Microsoft ad when the application is deployed as trial app and make money off of advertising. You will be building demo as shown below that displays the ad.
Preparing your Microsoft Ad control SDK
You can go to
http://advertising.microsoft.com/mobile-apps
and download Ad SDK and sign up for Microsoft advertising.
Preparing for advertising you want to display in Windows Phone app
Once you are registered at Microsoft advertising and installed Microsoft Ad SDK on your machine you will need to login to
https://pubcenter.microsoft.com/
and create “apps” that will give you Application ID as show in figure below.
Then you would need to create Ad units which will give you Ad Unit ID as show in below figure.
Create Windows Phone with Microsoft Ad SDK in Trial Mode
Add Microsoft Ad SDK assembly
Once you created Windows Phone project you would need to add reference to Microsoft.Advertising.Mobile.UI.dll found in C:\Program Files (x86)\Microsoft Advertising SDK for Windows Phone 7 (64 bit) or C:\Program Files\Microsoft Advertising SDK for Windows Phone 7 (32 bit) as show in below figure.
Add Ad Control to XAML
In XAML, you would need to add two things xml namespace and the ad control as shown below.
<phone:PhoneApplicationPage
x:Class=”HowToCreateTrialAppWithAdSdk.MainPage”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:phone=”clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone”
xmlns:shell=”clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
mc:Ignorable=”d” d:DesignWidth=”480″ d:DesignHeight=”768″
FontFamily=”{StaticResource PhoneFontFamilyNormal}”
FontSize=”{StaticResource PhoneFontSizeNormal}”
Foreground=”{StaticResource PhoneForegroundBrush}”
SupportedOrientations=”Portrait” Orientation=”Portrait”
shell:SystemTray.IsVisible=”True”
xmlns:my=”clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI”>
<Grid x:Name=”LayoutRoot” Background=”Transparent”>
<my:AdControl Height=”80″ HorizontalAlignment=”Left” Margin=”0,688,0,0″ x:Name=”ad” VerticalAlignment=”Top” Width=”480″/>
</Grid>
</phone:PhoneApplicationPage>
Add Code to Codebehind
Then in code behind you would need to properly display ad control when your app is in trial mode. In Microsoft.Phone.Marketplace namespace you will find LicenseInformation class that contains IsTrial() method that return true if the current app is in trial mode. If the app is in trial mode simply collapse the control. BY DEFAULT IsTrial() method ALWAYS RETURNS FALSE.
By default your AdControl will be in test mode and before shipping out your application you want to make sure to test AdControl in none test mode by setting AdControl.TestMode to false. Also you would want to set ApplicationId and AdUnitId properties using the values ontained in Microsoft ad center in above steps. See below for the code that shows these explanations.
using Microsoft.Phone.Controls;
using Microsoft.Advertising.Mobile.UI;
using Microsoft.Phone.Marketplace;
namespace HowToCreateTrialAppWithAdSdk
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
// Ad if trial
AdControl.TestMode = false;
ad.ApplicationId = “your app id”;
ad.AdUnitId = “your ad unit id”;
ad.Visibility = System.Windows.Visibility.Collapsed;
if (new LicenseInformation().IsTrial())
{
ad.Visibility = System.Windows.Visibility.Visible;
}
}
}
}
Download Code
Conclusion
In this demo you learn about how to make money while you allow the user to install you app in trial mode and still make money using Microsoft Ad.


hi
Thank you for your tutorial. Unfortunately when I test the App (with Ads) the Ad part is only shown for a few milli-seconds and vanishes immediately… (I commented the trial part out). I took your ApplicationId and AdUnitId and I also choose my own (the one I got in the Microsoft PubCenter) in order to test… what am I doing wrong?
Thank you!
You are doing nothing wrong. I deleted applicationid and adunitid from my ad center and below ids will not work which is in the downloaded code.
ad.ApplicationId = “760bcf5d-1c7e-47db-b12d-9b021a8724e2″;
ad.AdUnitId = “10011959″;
You would need to go to https://pubcenter.microsoft.com/ and create your own
hi
Thank you for your fast answer. Actually, I registered to the pubcenter and got an ApplicationId and an AdUnitId. But this didn’t work. When I tried
ad.ApplicationId = “test_client”;
ad.AdUnitId = “TextAd”;
this worked… Perhaps, there is something wrong with the AdUnit-Size?
Thanks, for your help!
Only thing I could think of is to make sure to set AdControl.TestMode = false;
I did that thanks,… I think I’ll write the MS support. Thanks for your help!