Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob interstitial ad won't display

I used to display AdMob banner on my future apps, and I'd like to give a try to the interstitial ads.

I checked the AdMob SDK for implementation, and I copied their example source because it was exactly what I want (i.e. the interstitial shown when the activity launch).

I tried it on emulator and on my Galaxy, no ad has been displayed.

Here is the source code:

public class Asscreed extends Activity {
    private InterstitialAd interstitial;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_asscreed);

        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("ca-app-pub-6046034785851961/xxxxxx");

        // Create ad request.
        AdRequest adRequest = new AdRequest.Builder().build();

        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);
    }

    // Invoke displayInterstitial() when you are ready to display an interstitial.
    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }
}

The imports are OK and the Google Play Services library is of course imported.

I use this example: AdMob Android Guides - Interstitial Ad.

Could someone tell me what's wrong in my code?

like image 315
user2661663 Avatar asked Sep 10 '25 08:09

user2661663


2 Answers

You should wait for the ad to be loaded. Only then, you can call displayInterstial() method, which would show the ad.

You can register for a listener, that will let you know when the loading is done.

interstitial.setAdListener(new AdListener(){
          public void onAdLoaded(){
               displayInterstitial();
          }
});
like image 137
Kumar Bibek Avatar answered Sep 12 '25 22:09

Kumar Bibek


this did it for me.

// Begin listening to interstitial & show ads.
interstitial.setAdListener(new AdListener(){
     public void onAdLoaded(){
          interstitial.show();
     }
});

i still wonder why all the guys at google upload code implementing directions that just don't work after one follows them to the dot..

like image 36
Philly Robo-arch Kintu Avatar answered Sep 12 '25 23:09

Philly Robo-arch Kintu