Showing posts with label AdControl. Show all posts
Showing posts with label AdControl. Show all posts

Sunday, March 27, 2011

Windows Phone 7 XNA Games advertising

My earlier post Windows Phone 7 Silverlight, Adcontrol step by step, tricks and issues was mainly about admanager on WP7 Silverlight.

To implement admanager in XNA games, especially when you use XNA Gamestatemanagement sample Game State Management

Insert the following code in the GameplayScreen.cs file LoadContent method.

#if DEBUG
Guide.SimulateTrialMode = true;
#endif
if (Guide.IsTrialMode)
{
// adManager = new AdManager(this.ScreenManager.Game, "test_client");
adManager = new AdManager(this.ScreenManager.Game, "applicationid");
adManager.TestMode = false;

// Create a banner ad for the game
// bannerAd = adManager.CreateAd("Image300_50", new Rectangle(0, 700, this.ScreenManager.GraphicsDevice.Viewport.Bounds.Width, 120), RotationMode.Manual, false);
bannerAd = adManager.CreateAd("unitid", new Rectangle(0, 700, this.ScreenManager.GraphicsDevice.Viewport.Bounds.Width, 120), RotationMode.Manual,false);

this.ScreenManager.Game.Components.Add(adManager);

}



When you want to test it with the testad set adManager. TestMode true, uncomment the test_client admanager constructor and comment out the applicationid admanager contructor.



When you want to test with real ads, set adManager.TestMode false, comment out adManager test_client method and uncomment adManager applicationid constructor.



applicationid and unitid Identifies the application and is assigned to you during the publisher registration process.



Interesting discussion on this in this thread in which I participated!Where to insert the admanager in Gamestatemanagment sample

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