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:
<activity
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"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.google.ads.AdView
        android:id="@+id/adview_banner_view"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        ads:adSize="BANNER"
        ads:adUnitId="Publisher ID Here!"
        ads:loadAdOnCreate="true" />

</RelativeLayout>
2. From code
String ADMOBID = “Publisher ID Here!";
AdView adview = new AdView(this, AdSize.BANNER, ADMOBID);
parentView.addView(adview);

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;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  adView = (AdView)findViewById(R.id.adview_banner_view);
  
 }
 @Override
 protected void onPause() {
  super.onPause();
  if (adView.isRefreshing())
   adView.stopLoading();
 }
 @Override
 protected void onResume() {
  super.onResume();
  adView.loadAd(new AdRequest());
 }
 
 
}

Links

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