Tuesday, January 8, 2013

Advertising services: AdMob

Advertising services: AdMob
AdMob - a mobile advertising service from Google. In this article I will discuss how to use this service in their applications and games.

What does the AdMob:
  • Create your own ads;
  • SDK for Android, iPhone and Windows Phone 7;
  • Flexible and powerful management tools advertising platforms;
  • Stable automatic payments (to earn more than $ 100).

Getting Started

To get started, to sign up or sign in: www.google.com/ads/admob/ and download the sdk (at this link: developers.google.com/mobile-ads-sdk/download). For each application, you must get your Publisher ID. So go to Sites & Apps, and click Add Site/App. After filling out the required fields, your application will be assigned an ID. You can watch it by clicking the button in the application Manage Settings.

Code integration

To work with the SDK AdMob should place the downloaded jar in libs folder of the project (if it does not, you need to create it) and add the library to the project.  Click on «Properties» in the «Project» menu bar.  Select «Java Build Path» on the left and then select the “Libraries” tab. Click «Add JARs...» and select the downloaded file. The file should now appear under your project’s Referenced Libraries.
Для рекламного сервиса необходимо добавить следующие разрешения в AndroidManifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
For advertising service you must add the following permissions in AndroidManifest:
android:name="com.google.ads.AdActivity"   android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

There are two ways to add an advertising banner in View:
1. From xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent" >

        ads:adUnitId="Publisher ID Here!"
        ads:loadAdOnCreate="true" />

2. From code
String ADMOBID = “Publisher ID Here!";
AdView adview = new AdView(this, AdSize.BANNER, ADMOBID);

Advertising management service

After adding View advertising service, you must download advertising when the application opens and stops loading when the application is minimized.
public class MainActivity extends Activity {
 private AdView adView = null;
 protected void onCreate(Bundle savedInstanceState) {
  adView = (AdView)findViewById(R.id.adview_banner_view);
 protected void onPause() {
  if (adView.isRefreshing())
 protected void onResume() {
  adView.loadAd(new AdRequest());


  • The source codes of this project can be downloaded here: zip