Friday, January 28, 2011

Windows Phone 7 Silverlight, Adcontrol step by step, tricks and issues

Went through interesting experience in implementing the adcontrol in Windows Phone 7 and I thought I will share it here.

First go and register your application in

Microsoft Pubcenter

This site gives you the following steps

  1. Register mobile application
  2. Create application ad unit
  3. Download the Microsoft Advertising SDK for Windows Phone 7
  4. Integrate the Microsoft Advertising SDK for Windows Phone 7 into your application.
  5. Manage your existing applications and ad units

In the XAML insert the ad control

<StackPanel Grid.Row="5"   x:Name="SP_ADControl" Visibility="Visible"   >

<ad:AdControl RotationEnabled="True" AdModel="Contextual" Width="450" Height="80"
AdUnitId="your adunit id" ApplicationId="your application id" />

<!--<ad:AdControl Width="450" Height="80"
AdUnitId="TextAd" ApplicationId="test_client" />-->

</StackPanel>



In my application Grid.Row=”5” is the bottom portion of the screen. Do not forget to pu your own ApplicationID and AdUnitId. The commented out portion is what you can use to test the app without getting an app id from the pub center.



In the Xaml.cs file put the following in the code right after InitializeComponent();



  if (!CheckIsTrial())
{
SP_ADControl.Visibility = Visibility.Collapsed;
}
else
{
// Show_Buy_Now_Page();
SP_ADControl.Visibility = Visibility.Visible;
AdControl.TestMode = false;
}



Add this method to the code



private bool CheckIsTrial()
{
#if DEBUG
MessageBoxResult result = MessageBox.Show
("CLICK OK TO SIMULATE FULL LICENSE", "BUY NOW!", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
return false;
}
else
{
return true;
}
#else
return licenseInfo.IsTrial();
#endif
}



This would help to test the app in the debug mode by showing you a dialog to test the ap. Check reference 5 given below.



The most interesting line of code is  AdControl.TestMode = false;  This is required because the Adcontrol.TestMode default value is True! Check reference 1 and 2 on this.



Do not forget to submit the release version to the marketplace.



References




  1. Making the MS Adcontrol REALLY work on phone 7


  2. WP7 – Using the Microsoft AdControl


  3. Integrating the AdControl into an Application Programmatically (C#)


  4. Microsoft Advertising SDK for Windows Phone 7


  5. How to: Test and Debug your Trial Application


  6. Tips on Using the AdControl in Windows Phone 7

3 comments:

  1. This is one of the amazing post.This is one of the nice collection.I like this post.
    Android app developers

    ReplyDelete
  2. Windows Phone Development
    may be the latest smart phone platform, but it has already taken significant market share and poses a big aggressive threat to iPhone, Android, and BlackBerry.

    ReplyDelete
  3. If you're looking for a solid contextual advertising network, I suggest that you check out Chitika.

    ReplyDelete