Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Adobe AIR Developer Center /

Using the AdMob Adobe AIR native extension for Android

by Alex Liebert

Alex Liebert
  • Milkman Games

Content

  • Including the AdMobAPI Library
  • Getting started with the AdMob extension API
  • Updating your AIR application descriptor file
  • Building and troubleshooting the application
  • Where to go from here

Created

14 May 2012

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
ActionScriptAdobe AIRadvertisingAndroidFlash BuilderFlash Professionalgame developmentgamingmonetizationnative extensionsscreen size
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Experience building apps for Android with Flash Builder and Adobe AIR will help you make the most of this article.

 

Additional required other products

  • Milkman Games AdMob Android Extension

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flash Professional (Download trial)
  • Adobe AIR SDK

With the AdMob Extension for Android from Milkman Games, you can rapidly integrate Google AdMob ads into your mobile AIR application using ActionScript 3.

The AdMob Extension for Android is a 100 percent native AdMob Java solution that enables you to:

  • Monetize free games via Google AdMob
  • Display your first ad with just two lines of code
  • Jumpstart development with a complete sample application, ActionScript 3 documentation, and a getting started guide
  • Reposition ads automatically when your app changes orientation
  • Support AdMob banner formats on both phones and tablets
  • Register your test devices so you can develop without affecting your metrics
  • Create, destroy, show, and hide ads with simple commands

This tutorial provides details on getting started with the AdMob Android extension. If you want to follow all the steps below, you'll need to purchase and download the AdMob Android extension.

Including the AdMobAPI Library

The first step in using the AdMob Android extension is to add the com.milkmangames.nativeexetnsions.AdMob.ane library to your project. (If you are not using Flash Builder 4.6 and later or Flash Professional CS6 and later you'll need to add the AdMobAPI.swc library instead.)

In Flash Professional CS6:

  1. Create a new project of the type AIR for Android.
  2. Choose File > Publish Settings.
  3. Click the wrench icon next to Script for ActionScript Settings.
  4. Select the Library Path tab.
  5. Click Browse For Native Extension (ANE) File and select the com.milkmangames.nativeextensions.AdMob.ane file.

In Flash Builder 4.6:

  1. Go to Project Properties (right-click your project in Package Explorer and select Properties).
  2. Select ActionScript Build Path and click the Native Extensions tab.
  3. Click Add ANE and navigate to the com.milkmangames.nativeextensions.AdMob.ane file.

In FlashDevelop:

  1. Copy the AdMobAPI.swc file to your project folder.
  2. In the explorer panel, right-click the SWC and select Add To Library.
  3. Right-click the SWC file in the explorer panel again, select Options, and then select External Library.

Getting started with the AdMob extension API

You can get your code up and running with the AdMob extension with a few simple calls. See example/AdMobExample.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:

  1. Import the API Classes:
com.milkmangames.nativeextensions.android.*; com.milkmangames.nativeextensions.android.events.*;
  1. Verify that AdMob is supported on your current platform, using the AdMob.isSupported property, and initialize the API with your AdMob publisher ID (you can retrieve your publisher ID from the AdMob web site control panel):
if(AdMob.isSupported) { AdMob.init("YOUR_PUBLISHER_ID"); } else { trace(“AdMob only runs on Android.”); return; }
  1. Show your first ad. The following call displays a banner ad, with bottom-left alignment:
AdMob.showAd(AdMobAdType.IAB_BANNER,AdMobAlignment.LEFT,AdMobAlignment.BOTTOM);
  1. To avoid making ad impressions while testing, you can set a list of testDevice IDs. You can retrieve the test ID for your device by running adb logcat (the command is android-sdk\platform-tools\adb logcat ) once while running the app. Look for the following line in the output:
I/Ads ( 834): To get test ads on this device, call adRequest.addTestDevice("THIS_IS_YOUR_TEST_ID");

Note: This is not the same as the Device ID. You'll need to run logcat at least this one time to find your ad test ID.

var testDevices:Vector.<String>=new Vector.<String>(); testDevices.push("YOUR_TEST_DEVICE_ID_HERE"); AdMob.showAd(AdMobAdType.IAB_BANNER, AdMobAlignment.LEFT, AdMobAlignment.BOTTOM, testDevices);

When you are done with testing, pass an empty testDevices Vector object or null instead.

  1. To use absolute pixel positions for your ad you can supply x and y offsets as the fifth and sixth parameters to showAd() respectively. Note that the pixel offsets are relative to the true size of the screen (which you can read with stage.stageWidth and stage.stageHeight ) as the AdMob 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):
AdMob.showAd(AdMobAdType.IAB_BANNER,AdMobAlignment.LEFT, AdMobAlignment.TOP, testDevices,20,32);

Google has designed the AdMob API in such a way that the absolute physical pixel dimensions of the ads will vary based on the physical size of the device's screen. To precisely layout your application, you may need to know what dimensions the ad will have on the particular device. You can access these dimensions with the getPixelSize() function, which returns a Rectangle object that's width and height represent the real size in pixels, on the current phone or tablet, that an IAB_BANNER will display. For convenience, you can also read the .dimensions property of the AdMobAdEvent object to get this in an event listener function. You can use this information to accurately perform layouts based on the size of the ad. Here is an example function call:

var realSize:Rectangle=AdMobAdType.getPixelSize(AdMobAdType.IAB_BANNER);

Unfortunately, this means the size of the ad (in pixels) will vary based on the phone or tablet the ad runs on. However, the vast majority of Android devices will run in one of two modes that Google calls large and xlarge.

Almost all Android phones fall into the large category and will have banners that are 480 x 75 pixels. Almost all Android tablets and some of newer, larger Android phones are in the xlarge category and will have banners that are 640 x 100 pixels.

The large and xlarge dimensions are intended as guidelines; you should use the getPixelSize() method described above for accurately determining banner sizes on your own devices.

Updating your AIR application descriptor file

You need to configure your AIR application descriptor file to use the AIR 3.0 SDK (or later), include the AdMob extension, and update the Android manifest additions with some AdMob specific settings. For a working example, see example/app.xml.

  1. Set your AIR SDK to 3.0 or later in the app descriptor file:
<application xmlns="http://ns.adobe.com/air/application/3.0">
  1. Include a link to the extension in the descriptor:
<extensions> <extensionID>com.milkmangames.extensions.AdMob</extensionID> </extensions>
  1. Update your Android manifest additions. The android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permissions must be present for AdMob to work. You also must add the com.google.ads.AdActivity activity within the <application> element, as shown below:
<android> <manifestAdditions> <![CDATA[<manifest android:installLocation="auto"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation" /> </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 AdMob 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 com.milkmangames.nativeextensions.AdMob.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 AdMob.init().
  • Ensure you have ad inventory. You can guarantee an ad will display by setting your test Device's ID when you call showAd(). See example/AdMobExample.as for a sample of how to do this.
  • Check for errors retrieving ads by listening for the FAILED_TO_RECEIVE_AD event:
AdMob.addEventListener(AdMobErrorEvent.FAILED_TO_RECEIVE_AD, onFailedReceiveAd);
  • Execute android-sdk/platform-tools/adb logcat to review full debug text from the AdMob extension.
  • Make sure you're handling all possible AdMobErrorEvent events. Uncaught errors may cause your code to halt.

Where to go from here

Now that you have the AdMob Android extension up and running, you may want to explore the ActionScript 3 documentation or check out the other tools from available from Milkman Games.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.

More Like This

  • Developing cross-platform Adobe AIR applications
  • Performance-tuning Adobe AIR applications
  • Using Badger for Adobe AIR applications
  • Building a native extension for iOS and Android – Part 2: Developing the ActionScript library
  • Creating your first Adobe AIR application on Android
  • Using web fonts with Adobe AIR 2.5
  • Using push notifications in AIR iOS apps
  • Building Lupo: A case study in building commercial AIR applications
  • Using the Push Notifications native extension for iOS
  • Building a native extension for iOS and Android – Part 5: Building the ANE file

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement