Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Make Money During your WP7 App's Free Trial

DZone's Guide to

Make Money During your WP7 App's Free Trial

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

With the big news about the Windows Store yesterday and the new flexible app trials it will bring (time OR feature-based trials), DZone thought it would be good to share a tutorial about how to create a free trial and also make money with ads during the free trial.

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 a free trial application doesn't mean you can’t make money doing so. You can display a Microsoft ad when the application is deployed as trial app and make money off of advertising! Today we 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 the Ad SDK and sign up for Microsoft advertising.

Preparing advertising you want to display in Windows Phone apps

Once you are registered at Microsoft advertising and have installed the 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 an 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 a Windows Phone project you would need to add a 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 the figure below.

image

Add Ad Control to XAML

In XAML, you need to add two things to the 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 need to properly display ad control when your app is in trial mode. In the Microsoft.Phone.Marketplace namespace you will find the LicenseInformation class that contains the IsTrial() method that returns '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 test mode by setting the AdControl.TestMode to false. Also you would want to set ApplicationId and AdUnitId properties using the values obtained in Microsoft ad center in the 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 allow the user to install you app in trial mode and still make money using a Microsoft Ad.

Source: http://blog.toetapz.com/2010/11/03/how-to-create-trial-mode-application-with-microsoft-ad-support/

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}