How to integrate Admob into your app
You want to monetize your free app by showing ads within it.
Using Admob Libraries you can start using ads in your free app, getting money for each click.
AdMob is one of the world's largest mobile advertising networks, offering solutions for discovery, branding and monetization on mobile phones.
The AdMob Android SDK contains the code necessary to install AdMob ads in your application.
In your project's root directory create a subdirectory libs
. This will already be done for you if you used Android's activitycreator tool. Copy the AdMob JAR (admob-sdk-android.jar) file into that libs directory.
For Eclipse projects:
#Right-click on your project from the Package Explorer tab and select '''Properties'''
#Select '''Java Build Path''' from left panel
#Select '''Libraries''' tab from the main window
#Click on '''Add JARs...'''
#Select the JAR copied to the libs directory
#Click '''OK''' to add the SDK to your Android project
Add your publisher ID to your ''AndroidManifest.xml'' . Just before the closing ''</application> '' tag add a line to set your publisher ID. If your publisher ID were 149afxxxx
, the line would look like this:
To find your publisher ID, log into your AdMob account, select the '''Sites and Apps''' tab, and click on the '''Manage Settings''' link for your site. On this page, you can find your publisher ID as shows figure 1.
''figure 1. Showing where you can find your Publisher ID''
Add the INTERNET permission to your ''AndroidManifest.xml'' just before the closing </manifest>
Optionally, you can add the ACCESSCOARSELOCATION
permissions to allow AdMob the ability to show geo- targeted ads.
Your final AndroidManifest.xml may look something like figure 2.
''figure 2. This is how it would look after pasting some code''
Paste the following into your attrs.xml
If your project does not already have an attrs.xml
file, then create one in the /res/values/ directory of your project, and paste the following:
Create a reference to the attrs.xml
file in your layout element by adding xmlns line that includes your package name specified in AndroidManifest.xml
. For example, if your package name were com.example.sampleapp
you would include this line:
So for a simple screen with only one ad, your layout element would look like this:
When integrating AdMob ads into your application it is recommended to use test mode. In test mode test, ads are always returned.
Test mode is enabled on a per-device basis. To enable test mode for a device, first request an ad, then look in LogCat for a line like the following:
To get test ads on the emulator use AdManager.setTestDevices...
Once you have the device ID you can enable test mode by calling in your main activity AdManager.setTestDevices:
Once you have successfully requested test ads, try clicking on each type of test ad to make sure it works properly from your application. The type of test ad returned is changed with AdManager.setTestAction
. You can see the result in figure 3.
''figure 3. The result of this snippet''
(not handled yet)