How to create Trial mode application with Microsoft ad support?

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.

SNAGHTML1d7bdeb

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.

image

Then you would need to create Ad units which will give you Ad Unit ID as show in below figure.

image

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.

image

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&#8221;

   xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml&#8221;

   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&#8243;

   xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006&#8243;

   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.

About toetapz

Henry Lee is founder of NewAgeSolution.Net and is passionate about the technology. He is also the author of the book Beginning Windows Phone 7 Development 2nd from Apress (http://www.apress.com/9781430235965). He works with various Fortune 500 companies delivering mobile applications and rich internet applications. He recently formed start-up company called ToeTapz.com focusing his energy on delivering mobile applications in Windows Phone 7, Android and iPhone. In his spare time, he dedicates his effort to help his .NET community by delivering sessions at the technology events. He enjoys talking with other technologist about current trends in the technology and sharing business insights with fellow colleagues. Often you will find Henry at local cigar bar enjoying a cigar and a drink trying to come up with next big mobile application.
This entry was posted in Windows Phone 7 and tagged , . Bookmark the permalink.

5 Responses to How to create Trial mode application with Microsoft ad support?

  1. am says:

    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!

    • toetapz says:

      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

      • am says:

        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!

      • toetapz says:

        Only thing I could think of is to make sure to set AdControl.TestMode = false;

  2. am says:

    I did that thanks,… I think I’ll write the MS support. Thanks for your help!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s