×
Namespaces

Variants
Actions
Revision as of 04:29, 10 April 2013 by hamishwillee (Talk | contribs)

Using Microsoft Advertising Control in Windows Phone apps

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
05 Feb
2012

This article explains how to monetize Windows Phone 7 application using Microsoft Advertising Ad control.

SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Code Example
Source file: Media:WP AdApp.zip
Tested withCompatibilityArticle
Created: pavan.pareta (13 Jan 2012)
Last edited: hamishwillee (10 Apr 2013)

Introduction

In mobile application development the term monetization is used to mean the ability to generate revenue thorough your mobile application. It can be from affiliate programs, e- commerce, premium content and advertising.

The market for Windows Phone 7 applications is wide open for developers wanting to monetize their mobile applications. That means endless opportunities for any developer looking to monetize mobile applications. One way of monetization can be advertisement i.e. displaying ads in your apps. In this article we'll see how to achieve such kind of functionality using Microsoft Advertising Ad Rotator Control.

Implementation

Following are the basic steps to be implemented in a Windows Phone 7 application.

Step-1: Download Microsoft Advertising SDK.

Download Microsoft Advertising SDK for Windows Phone. After download Microsoft Advertising SDK, install it on your development machine.

Step-2: Register mobile App at Microsoft pubCenter.

Register Your Mobile App: Sign up and register your Windows Phone apps using Microsoft pubCenter. Here you can use your live or pubCenter Id.

Ad 001.png

Register your first application and create an ad unit (optional).

Ad 002.png

Enter required information to register your application.

Enter application name:

Device type:

Ad unit name:

Ad unit size:

Select Ad category:

Excluded url:

Ad 003.png

Step-3: Creating the Windows Phone application

1) Create a Windows Phone 7 Application project

Wp Ad 001.png

2) Right click on project in solution explorer panel and click on Add Reference dialog box, click the Browse tab. Navigate to the location where you installed the Microsoft.Advertising.Mobile.UI.dll previously. Click the Microsoft.Advertising.Mobile.UI.dll to select it, and click OK.

Wp Ad 002.png

Wp Ad 003.png

3) Now configure Application Id and Ad Unit Id properties in the Ad Control. Here is two ways to add “Ad Control” in the application using XAML and C# code behind.

Using XAML Drag and drop the Ad Control to Windows Phone 7 xaml page and configure Application Id and Ad Unit Id properties in xaml. See below code snippet:

<my:AdControl Foreground="Red" AdUnitId="AdUnitId" ApplicationId="AppId" Height="80" HorizontalAlignment="Left" Margin="0,6,0,0" Name="adControl1" VerticalAlignment="Top" Width="480" IsAutoRefreshEnabled="True" />

Wp Ad 004.png

Using (C#) code behind Double click on the Windows Phone7 Page, it will automatically open the code behind of a page. And using the AdControl API which is a managed api. Include the Microsoft.Advertising.Mobile.UI namespace in the project. And create an instance of the AdControl Class and set the properties of the AdControl class instance or you can directly pass it to AdControl constructor. See below code snippet:

private const string APPLICATION_ID = "";
private const string AD_UNIT_ID = "";
private AdControl adControl;
 
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
this.Unloaded += new RoutedEventHandler(MainPage_Unloaded);
}
 
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(APPLICATION_ID) && !string.IsNullOrEmpty(AD_UNIT_ID))
{
adControl = new AdControl(
APPLICATION_ID,
AD_UNIT_ID,
true);
 
// Make the AdControl size large enough that it can contain the image
adControl.Width = 480;
adControl.Height = 80;
adControl.Keywords = "Windows Phone 7, Hotels, Travels, Gold";
ContentPanel.Children.Add(adControl);
}
else
{
MessageBox.Show("To show ads in this application, insert the application ID and an ad unit ID into your code as explained..");
}
}
 
void MainPage_Unloaded(object sender, RoutedEventArgs e)
{
ContentPanel.Children.Remove(adControl);
}

Run the application by using F5 button, and you will see a sample of Monetization in Windows Phone 7 Application.

Wp Ad 005.png

Example source code

778 page views in the last 30 days.
×