Posted by : Unknown Sunday, July 27, 2014

Monetize and Analyze your Android apps with  Google's AdMob

In this tutorial, you will learn how to integrate the new Google Admob with banner and interstitial ads into your Android application. The new AdMob is a streamlined user interface, to make it even easier for you to monetize and promote your apps in minutes.Monetize your apps with ads from over a million Google advertisers worldwide. Get access to programmatic demand and best-in class mediation tools to maximize revenues effortlessly.On Aug. 1 2014, Google Play will stop accepting new or updated apps using the standalone Google Mobile Ads SDKs v6.4.1 or lower.So Google Mobile Ads is now offered through Google Play services. This is the recommended way of enabling ads on your Android app.
Getting Started:
1.Sign up as an Admob Publisher here. Log in to your dashboard once you have your account approved.
2.Open the Monetize tab and create an ad unit for your application. You should be able to see your ad unit after selecting an app on your left panel.
3.Download the new Google Play Services Library using the Android SDK Manager in your Eclipse IDE.

4.Import Google Play Services Library into your Eclipse IDE. I’ve found mine in D:\Eclipse\sdk\extras\google\google_play_services\libproject . You will have to search the folder yourself.

5.Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project AdmobTutorial.
Application Name : AdmobTutorial
Project Name : AdmobTutorial
Package Name : com.srinoid.admobtutorial
6.After created your project, You have to set Google Play Services Library as a reference project to your project.
7.Import Google Play Services Library into your App.

8.In your AndroidManifest.xml, we need to declare an activity for Google Play Services and permissions to allow the application to access to the Internet and check network status. Open your AndroidManifest.xml and paste the following code.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.srinoid.admobtutorial"
    android:versionCode="1"
    android:versionName="1.0" >
     <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 <!--Google Play Service Meta-data Info -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
 <!-- AdActivity Declaration-->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
    </application>
</manifest>
9.Next, create an XML graphical layout for your MainActivity. Go to res > layout > Right Click on layout > New > Android XML File
Name your new XML file activity_main.xml and paste the following code.
<?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:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 <!--Creating AdView in XML and loading an ad-->
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="Place adunitid here" />
</LinearLayout>

10.Open your MainActivity.java and paste the following code
package com.srinoid.admobtutorial;
//Importing Library Classes  
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
 import android.os.Bundle;
import android.app.Activity;
 public class MainActivity extends Activity {
    private InterstitialAd interstitial;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from activity_main.xml
        setContentView(R.layout.activity_main);
         // Prepare the Interstitial Ad
        interstitial = new InterstitialAd(MainActivity.this);
        // Insert the Ad Unit ID
        interstitial.setAdUnitId("Place your AdUnitId Here");
         //Locate the Banner Ad in activity_main.xml
        AdView adView = (AdView) this.findViewById(R.id.adView);
         // Request for Ads
        AdRequest adRequest = new AdRequest.Builder()
         // Add a test device to show Test Ads
         .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
         .addTestDevice("Place your test device id here")
                .build();
         // Load ads into Banner Ads
        adView.loadAd(adRequest);
         // Load ads into Interstitial Ads
        interstitial.loadAd(adRequest);
         // Prepare an Interstitial Ad Listener
        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
                // Call displayInterstitial() function
                displayInterstitial();
            }
        });
    }
    public void displayInterstitial() {
        // If Ads are loaded, show Interstitial else show nothing.
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }
}
11. For More Information about Google Play Services Migration please go through the following  link


Leave a Reply

Subscribe to Posts | Subscribe to Comments

Copyright © Srinoid