Firstly, smaato supports many countries and it has the SOMA SDK that is compatible with XNA.
Secondly, it allows for transfering of ad revenue through http://www.paypal.com/.
Note: this tutorial is for Windows Phone 7 XNA framework and not for Silverlight framework.
1) Sign up for a smaato account at http://www.smaato.com/
2) Generate AdSpace under the tab My Sites & Apps
3) Select - App (Windows Phone 7)
Note: This will generate your PublisherID and AdSpaceID -- these are very important and will be required as identifiers for you and your app.
4) Download the SOMA SDK for Windows Phone 7
5) From the SOMA SDK zip file place the SOMAWP7.dll and SOMAWP7.pdb files into your Windows Phone 7 project where the projectname.csproj file is located.
6) In your Windows Phone 7 project Right click on References in your Solution Explorer and ad SOMAWP7.DLL from Add Reference Browse tab and Microsoft.Phone from Add Reference .Net tab
7) Create a 480x79 png file called sampleAd.png in the project content folder and add sampleAd.png into the project's Content area inside the Solution Explorer.
8) In your project.cs file place the following line of code at the top your file
using Microsoft.Phone.Tasks;
using System.IO.IsolatedStorage;
using SOMAWP7;
9) In your project class that inherits the XNA framework place the following code
{ public class Project1 : Microsoft.Xna.Framework.Game
{
SomaAd somaAd;
Texture2D textureSomaAd;
SpriteBatch spriteBatch;
10) Initialize SOMA SDK using the AdSpaceID and PublisherID
protected override void Initialize()
{
//Set up SomaAd to get ads
somaAd = new SomaAd();
somaAd.Adspace = 12345678;
somaAd.Pub = 12345678; //gets user location from device
somaAd.LocationUseOK = true;
//information about the app running
somaAd.Kws = "games, windows phone, entertainment";
//search string for ads to show
somaAd.Qs = "games, windows phone, entertainment, fun, exciting";
//Ask the user this informaton about them
//somaAd.Age = 30;
//somaAd.Gender = "m";
//By default, the SDK sets this to the current location
//somaAd.City = "Fremont";
//somaAd.State = "Ca";
//somaAd.Zip = "94539";
//somaAd.Country = "United States";
//somaAd.Countrycode = "us";
//somaAd.adInterval = 60000;
somaAd.GetAd();
base.Initialize();
}
somaAd.GetAd();
base.Initialize();
}
11) Load content into app for SOMA
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
textureSomaAd = null;
// setup touch
TouchPanel.EnabledGestures = GestureType.Tap;
12) Make sure to Dispose SOMA with the UnloadContent function
protected override void UnloadContent()
protected override void UnloadContent()
{
somaAd.Dispose();
}
13) Check for screen touch in the SOMA image. Get the file name of the SOMA image and load up browser with link if touch detected.
string currentAdImageFileName = "";
protected override void Update(GameTime gameTime)
{
// if the back button is pressed then go back to the main menu
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
{
Exit();
}
Vector2 somaAdPosition = new Vector2(0, GraphicsDevice.PresentationParameters.BackBufferHeight - 80);
Vector2 somaAdSize = new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth, 80);
while (TouchPanel.IsGestureAvailable)
{
GestureSample gestureSample = TouchPanel.ReadGesture();
if (gestureSample.GestureType == GestureType.Tap && somaAd.Uri != "" && textureSomaAd != null)
{
Vector2 touchPosition = gestureSample.Position;
if (touchPosition.X >= 0 &&
touchPosition.X < somaAdSize.X &&
touchPosition.Y >= somaAdPosition.Y &&
touchPosition.Y < (somaAdPosition.Y + somaAdSize.Y))
{
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.URL = somaAd.Uri;
webBrowserTask.Show();
}
}
}
// if there is a new ad, get it from Isolated Storage and show it
if (somaAd.Status == "success" && somaAd.AdImageFileName != null && somaAd.ImageOK)
{
try
{
if (currentAdImageFileName != somaAd.AdImageFileName)
{
currentAdImageFileName = somaAd.AdImageFileName;
IsolatedStorageFile myIsoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream myAd = new IsolatedStorageFileStream(somaAd.AdImageFileName, FileMode.Open, myIsoStore);
textureSomaAd = this.Content.Load<Texture2D>("sampleAd");
textureSomaAd = Texture2D.FromStream(this.GraphicsDevice, myAd);
myAd.Close();
myAd.Dispose();
myIsoStore.Dispose();
}
}
catch (IsolatedStorageException ise)
{
string message = ise.Message;
}
}
base.Update(gameTime);
}
14) Draw the texture of the SOMA image
protected override void Draw(GameTime gameTime)
{
// draw ad
//cubeToDraw.RenderToDevice(GraphicsDevice);
if (textureSomaAd != null)
{
this.spriteBatch.Begin();
this.spriteBatch.Draw(textureSomaAd, new Rectangle(0, GraphicsDevice.PresentationParameters.BackBufferHeight - 80, GraphicsDevice.PresentationParameters.BackBufferWidth, 80), Color.White);
this.spriteBatch.End();
}
base.Draw(gameTime);
}
15) Create your app on Microsoft App Hub and submit it.
16) Go to http://www.smaato.com/ and click on Add New App. For the Download URL field copy and paste the Deep link example from your App Hub app information page.
17) Something to be aware of is that your phone must have 3G or a WIFI connection to the internet for your ads to show up.
Note: when you are debugging your app and the phone is connected to Visual Studio 2010 Express for Windows Phone the ads do not show up even with a working internet connection on the phone. You must disconnect the phone from the computer in order for the ads to appear.
Written by: Paul