Copy link to clipboard
Copied
With the Keymob Extension for Android and IOS from www.keymob.com, you can rapidly integrate Google AdMob ads ,Chartboost,Inmobi,Iad ,MMedia,Adcolony,Amazon,Baidu and GDT into your mobile AIR application using ActionScript 3.
The Keymob Extension for Android and IOS is a 100 percent native Java and OC solution that enables you to:
Monetize free games via Keymob,Google AdMob Chartboost,Inmobi,Iad ,MMedia,Adcolony,Amazon,Baidu and GDT
Display your first ad with just two lines of code
This tutorial provides details on getting started with the Keymob IOS and Android extension. If you want to follow all the steps below, you'll need to download the AdMob Android extension.
Including the Keymob API Library
The first step in using the Keymob extension is to add the keymob1.0.ane library to your project.
In Flash Professional CC:
In Flash Builder 4.6:
In FlashDevelop:
Getting started with the Keymob extension API
You can get your code up and running with the Keymob extension with a few simple calls. See keymobdemo.as for a full example that shows how to handle errors, destroy and refresh ads, set ad visibility, and handle ad status changes.
Follow these steps to get started:
Import the API Classes:
import com.keymob.*;
Verify that Keymob is supported on your current platform, using the KeymobAd.getInstance().supportDevice property, and initialize the API with your AdMob publisher ID (you can retrieve your publisher ID from the AdMob web site control panel):
if(KeymobAd.getInstance(). supportDevice)
{
KeymobAd.getInstance().initFromKeymobService("app id");
} else
{
trace(“Keymob only runs on Android and IOS device.”);
return;
}
Show your first ad. The following call displays a banner ad, with bottom-left alignment and padding y 0:
KeymobAd.getInstance().showRelationBanner(AdSizes.BANNER,AdPositions.BOTTOM_CENTER,0);
To avoid making ad impressions while testing, you can set test mode when init keymobad
KeymobAd.getInstance().initFromKeymobService("app id",true);
Note: Chang Test mode to false when release your app.
To use absolute pixel positions for your ad you can supply x and y offsets as the second and third parameters showBannerABS() respectively. Note that the pixel offsets are relative to the true size of the screen (which you can read withstage.stageWidth and stage.stageHeight ) as the Keymob extension has no knowledge of any scaling being done by AIR (with the fullscreen property or otherwise). The following example shows an ad at the pixel position 20, 32 (relative to top left of the device):
KeymobAd.getInstance().showBannerABS (AdSizes. FULL_BANNER, 0,32);
Updating your AIR application descriptor file
You need to configure your AIR application descriptor file to use the AIR 17.0 SDK (or later), include the Keymob extension, and update the Android manifest additions with some Keymob specific settings. For a working example, see keymobdemo-app.xml. Set your AIR SDK to 17.0 or later in the app descriptor file:
<application xmlns="http://ns.adobe.com/air/application/17.0">
Include a link to the extension in the descriptor:
<extensions>
<extensionID> com.keymob.KeymobAd</extensionID>
</extensions>
Update your Android manifest additions. The android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permissions must be present for Keymob to work. You also must add the activity of third platform within the <application> element, as shown below:
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application >
<!-- Admob Mobile Ads -->
<meta-data android:name="com.google.android.gms.version" android:value="7327000" />
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent"/>
<!-- Amazon Mobile Ads -->
<activity android:name="com.amazon.device.ads.AdActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- InMobi -->
<activity android:name="com.inmobi.androidsdk.IMBrowserActivity"
android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar" android:hardwareAccelerated="true" />
<!-- Millennial Media -->
<activity android:name="com.millennialmedia.android.MMActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="keyboardHidden|orientation|keyboard|screenSize" ></activity>
<!-- Keymob -->
<activity android:name="com.keymob.sdk.core.KeymobActivity" android:theme="@android:style/Theme.Dialog"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- baidu -->
<activity android:name="com.baidu.mobads.AppActivity" android:configChanges="keyboard|keyboardHidden|orientation"/>
<!-- adcolony -->
<activity android:name="com.jirbo.adcolony.AdColonyOverlay"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyFullscreen"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<activity android:name="com.jirbo.adcolony.AdColonyBrowser"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
<!-- gdt -->
<service android:name="com.qq.e.comm.DownloadService" android:exported="false"/>
<activity android:name="com.qq.e.ads.ADActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"/>
</application>
</manifest>
]]></manifestAdditions> </android>
Building and troubleshooting the application
If you're using Flash Builder 4.6 or later, or Flash Professional CS6 or later, and have added the Keymob IOS and Android extension library as described above, then you can compile as you usually do directly from the IDE. If not and you are building your app with the extension from the command line, then you'll need to specify the directory containing the keymob1.0.ane file.
Here is an example build command line:
[PATH_TO_AIR_SDK]\bin\adt -package -target apk-debug -storetype pkcs12 –keystore [YOUR_KEYSTORE_FILE] -storepass
[YOUR_PASSWORD] anesample.apk app.xml anesample.swf –extdir [DIRECTORY_CONTAINING_ANE_FILE]
If you're having trouble displaying ads, try these tips: Ensure that your publisher ID is correctly set via KeymobAd.getInstance().initFromKeymobService(). And you have set your ad id in www.keymob.com