Skip to content
Search

AdMob

lastmod 2024-01-28created 2014-02-1517 edits

AdMob is an American mobile advertising company founded in 2006. The name AdMob is a portmanteau of 'Advertising on Mobile'. Google agreed to acquire it for 750 million dollars in November 2009, and the acquisition was completed on May 27, 2010.

Incorporating the SDK

Incorporating Google Mobile Ads into your app is a straightforward process:

  • Add and reference the Google Play services library project in your Eclipse workspace.
  • Add a meta-data tag in AndroidManifest.xml.
<meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>
  • Declare com.google.android.gms.ads.AdActivity in the manifest.
<activity android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
  • Set up network permissions in the manifest.
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Create your banner in XML

Defining a com.google.android.gms.ads.AdView

The easiest way to incorporate an ad is to simply define your AdView as you would any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
  <com.google.android.gms.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"/>
</LinearLayout>

As usual you must replace MY_AD_UNIT_ID with your AdMob ad unit ID. Note the inclusion of the ads namespace referenced in specifying adUnitId and adSize.

Look up and Load

To fetch ads, look up the AdView as a resource via findViewById, create an AdRequest, and invoke loadAd:

import com.google.android.gms.ads.*;

public class BannerExample extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
  }
}

Google Mobile Ads SDK FAQ

I keep getting the error 'The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.'
You can safely ignore this message. Your app will still fetch and serve banner ads.

AdMob vs AdSense vs AdManager

AdMob
AdMob is a mobile advertising network and monetization platform for mobile developers who want to earn revenue from ads, gain actionable analytics insights, and grow their app business. Using AdMob as a network, you can serve ads worldwide to monetize your mobile apps. Using AdMob as a monetization platform for developers who use multiple ad networks, you can maximize ad revenue from all your third-party network partners.
AdSense
AdSense acts as an ad network, helping you find advertiser demand and set up your ad inventory. AdSense is best suited for publishers who want a more automated ad solution and a small dedicated ad management team.
Ad Manager
Google Ad Manager is an ad management platform for large publishers with significant direct sales. Ad Manager provides detailed management features and supports multiple ad exchanges and networks, including AdSense, Ad Exchange, third-party networks, and third-party ad exchanges.

See also

Favorite site

Beginning AdMob banner

in Android

References


  1. Android_insert_admob_advertisement.pdf ↩

author Zer0 sitemap