Saturday, October 4, 2014

NEW ADMOB FOR ANDROID

NEW ADMOB INTEGRATIONS

Sign up as an Admob Publisher here. Log in to your dashboard once you have your account approved.
Identify your publisher ID on the top right of your dashboard.


publisherIDAdmob



create an ad unit for your application.
Download the new Google Play Services Library using the Android SDK Manager in your Eclipse IDE
SDKManager
Import Google Play Services Library into your Eclipse IDE. I’ve found mine in D:\Eclipse\sdk\extras\google\google_play_services\libproject .
GooglePlayServices
BANNER EXAMPLE
Create a new project in Eclipse
NewAdmobTutorial
Package Name : com.androidbegin.newadmobtutorial
Open your MainActivity.java and paste the following code.


package com.androidbegin.newadmobtutorial;
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("ca-app-pub-123456789/123456789");
        //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("CC5F2C72DF2B356BBF0DA198")
                .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();
        }
    }
}
In this MainActivity.java, a test device is being used to run test ads. Its highly recommended to test your ads using test ads to prevent invalid clicks that will cause suspension of your AdMob publisher account. To generate a Test Device ID, simply type in some random text into addTestDevice as shown below.


        // Request for Ads
        AdRequest adRequest = new AdRequest.Builder()
        // Add a test device to show Test Ads
         .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
         .addTestDevice("abc") //Random Text
                .build();
        // Load ads into Banner Ads
        adView.loadAd(adRequest)



Run your app, and filter your logcat with the word “ads” as shown below. You should be able to generate some unique strings
Now paste the Test Device ID into addTestDevice. You have to generate your own Test Device ID, because each Android Device has an unique ID.

Showing INTERSTITIALS Ads

To show real ads, just remove the two lines by commenting it as shown below.
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.
activity_main.xml
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.
AndroidManifest.xml
Output:



AdmobAdsSPECIAL THANKS TO PRAKASH UJJWAL AND ANDROID BEGIN


 
 


  

2 comments:

  1. hai apakah kmu bisa menyediakan link download nya?

    send in my email : coupethunter@yahoo.co.id

    ReplyDelete