Test Ads in the Android Admob Unity Plugin

If you have an application all set up with the Android Admob Unity Plugin and you want some test ads so you can test clicking and such without upsetting Admob, here is how to do this.

First you will need your ‘Test Device ID’. The only way I know of to get this is to check the logcat in Eclipse while you device is plugged in (and running your game with Ads showing), search for a line that looks like:

To get test ads on this device, call adRequest.addTestDevice(“Your Test Device ID”);

After you have the device id, add the following method to the AdMobUnityPlugin class:

public static void SetTestMode(string test_device_id){
  AndroidJavaClass jc = new AndroidJavaClass(classname);
  jc.CallStatic("SetTestMode",test_device_id);			
}

Then this should be called before you call StartAds(), i.e.

void Start(){
  AdMobUnityPlugin.SetTestMode("My Test Device ID in here");
  AdMobUnityPlugin.StartAds();
}

That’s it, you should now get test ads. Obviously please remember to remove the call to the SetTestMode method before you deploy for real, however if you forget you can disable test mode in your application settings on the Admob website (just below where you can set the refresh rate).

The Facebook Graph API Part 1

I’ve had a few requests for a tutorial on using the facebook graph api with my social plugin, so here it is!

My Social Unity Plugin for Android supports the Facebook Graph API. So what does that mean exactly? Well facebook expose their functionality via a rather cool but perhaps slightly confusing web interface. This interface is driven by HTTP requests and the data you get back is in the JSON format. Quickly check those links so you know what both of these are then come back here…

The Graph API is well documented and you can easily test a query by using the Graph API Explorer. So if I said you can get the current user’s profile by using a graph path of ‘me’, you can easily check this by going to the Graph API Explorer and doing this:

In my plugin you can do the same thing on the demo screen:

Or in code:

FacebookUnityPlugin.GenericRequest("me","","GET","");

In all the above cases, the response you would get will be in JSON, similar to:

{
  "id": "1234565", 
  "name": "Fred Bloggs", 
  "first_name": "Fred", 
  "last_name": "Bloggs", 
  "location": {
    "id": "111112222", 
    "name": "London, United Kingdom"
  }, 
  "gender": "male", 
  "timezone": 0, 
  "locale": "en_GB", 
  "verified": true, 
  "updated_time": "2012-07-24T09:52:15+0000"
}

So how do we extract all that information out in C# within Unity? Well the latest version of my plugin includes ‘LitJSON‘ which is remarkably good at doing this, for example if the above JSON was in a string variable ‘response’, you could get the user’s last name by:

JsonData jdata = JsonMapper.ToObject(response);
lastname = (string)jdata["last_name"];

Nice and simple! In my plugin, all responses from a GenericRequest come back via the gameobject ‘UnityGameObjectReceiver’, and you need a script attached to this gameobject that has a ‘OnRequestResponse’ method (see the demo for an example).

Part Two of this tutorial will cover more complex queries…

Merging Android Manifest Files

So you’ve purchased a couple of Android Unity plugins and want to use them both within your game, however they both come with their own AndroidManifest.xml file so you need to combine them somehow. Hopefully the next few tips will help you out.

The first thing to find out is whether the plugin has to set up it’s own activity as the main launcher activity. For example, all my plugins don’t have to be the main launcher activity, however my facebook(social) plugin loses SSO capability if not set up as the main launcher activity. The line in the manifest file that sets this up will look something like this:

 
<activity android:name="com.platoevolved.socialpluginunity.SocialPluginUnityActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

Also note that at least one of the plugins will need to set itself up as the main launcher activity otherwise the plugins will not be able to respond to user clicks (but will appear to work in all other ways).

So once you have decided which plugin gets the main launcher activity, you now need to merge the important information from the other manifest file. So for example if the other manifest file has extra activities,services, meta-data lines, uses-permissions etc, you should merge these in. Make note whether these should appear before or after the /application tag.

For example here are the important lines from my Admob manifest that should appear just before the tag:

<activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<meta-data android:name="admob_pub_id" android:value="Enter AdMob Publisher ID here"/>
<meta-data android:name="adposition_x" android:value="right"/>
<meta-data android:name="adposition_y" android:value="top"/>
<meta-data android:name="start_hidden" android:value="false"/>

And here are the lines that should appear just after the /application tag:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Note that for my AdMob plugin, if it is not the main launcher activity you will now need to call StartAds() somewhere in your code so that the plugin can get itself initialised.

For an example of three of my plugin manifests getting merged, see here.

For an example of the Admob and InAppBilling plugins merged see here.

Android Unity Plugin Bundle Released!

Fancy an Android Unity plugin that does everything?! Washes dishes, makes a nice cup of tea, tucks you in at night…. erm… This isn’t it but…

If you want ad banners, in-app billing and facebook integration added to your game in one fell swoop here is the bundle for you! Avoid the hassle of having to merge manifest files or integrate with other conflicting plugins. This bundle is ready to go and does it all! (note that I have redefined ‘all’ here to mean ads, in-app billing and facebook)

Find this awesome plugin bundle here.

In-App Purchasing Unity Plugin for iOS released

Just released my In-App Purchasing Unity Plugin for iOS.

Add an In-App store to your game. Sell items like potions, swords, new levels, new monsters… anything, it’s your game, you decide!

This works very similar to my popular Android equivalent so until I do a dedicated iOS tutorial it is worth checking out this youtube video.

Hope you find the plugin useful, get it here!