Using the AdMob Service
Go Up to Creating an Android App
Advertising services enable you to display ads in your applications to gain some income. AdMob is the Google advertising service for Android. This topic describes how to place ads from AdMob on your applications using FireMonkey.
- Note: The following information complements the main documentation topic about Android development. Read Android Mobile Application Development before you continue.
- 1 Supported Devices
- 2 Prerequisites
- 3 Creating an Ad Unit for Your Application in AdMob
- 4 Adding AdMob Support to Your Mobile Apps
- 5 Testing Your Ads
- 6 Troubleshooting Loading an Ad from AdMob
- 7 See Also
FireMonkey supports AdMob on devices running Android 2.3 or later. See also FireMonkey Platform Prerequisites, Android Requirements.
Creating an Ad Unit for Your Application in AdMob
To be able to configure TBannerAd to connect to the AdMob service, first you must create an ad unit in AdMob. When you configure your instance of TBannerAd to connect to AdMob, you must copy the ID of your ad unit into the AdUnitID property.
Adding AdMob Support to Your Mobile Apps
Here is the general procedure for adding ads to your multi-device applications on mobile platforms:
- Add an instance of the TBannerAd component to your application.
- Configure TBannerAd to load an ad from AdMob.
- Handle how your user interacts with this ad.
Loading an Ad
Configuring the Connection Data for AdMob
To connect to the AdMob service on Android:
- 1. Create your ad unit ID.
- 2. Copy your ad unit ID into the AdUnitID property of TBannerAd on an event such as the OnCreate event of your form:
BannerAd1.AdUnitID := 'YourAdUnitID';
BannerAd1->AdUnitID = "YourAdUnitID";
- 3. Go to Project > Options > Entitlement List, and select AdMob Service. Set its value to
Loading an Ad from AdMob
To load an ad from AdMob, call LoadAd. The LoadAd procedure is asynchronous, and when it finishes, it triggers one of the following events:
- OnDidFail is triggered if there is an error. OnDidFail provides a parameter,
Error, that provides detailed information about the error that prevented the banner from loading an ad.
- OnDidLoad is triggered if the request is successful.
You usually want to call LoadAd from a form event such as OnShow, to load an ad as soon as the form is displayed.
Handling User Interaction with Ads
When your user taps an ad, this triggers an action. This action typically consists of a full-screen version of the ad, or of opening a URL on a Web browser.
You might also want to use your handler for the OnActionCanBegin event to pause some running features of your applications, to avoid wasting processing during the ad action. Then you can define an event handler for the OnActionDidFinish event where you resume these features of your application.
Testing Your Ads
To show test ads in Android, simply set the TBannerAd.TestMode property to
Troubleshooting Loading an Ad from AdMob
The following table lists some problems that prevent your application from showing an ad, and potential solutions:
No network connectivity to the ad server
Verify your Wi-Fi or data connection
Internal server error
An invalid response was received from the ad server
Invalid ad request
Use a valid unit ID (AdUnitID)
Lack of ad inventory
No ads are currently available to download from the ad server
|Wrong ad properties
|Visible property of TBannerAd is set to
|Set TBannerAd visible property to
|Fixed-size of the banner is too big for the screen resolution
|Set ad size property to a proper value
Wrong application configuration
Ad service configuration parameters of your application are wrong
Set the AdMob Service property of your application (see step 3)