0
votes

I used to display AdMob banner on my future apps, and I'dl 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 insterstitial 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 they googly play service library is of course imported. I use this example : https://developers.google.com/mobile-ads-sdk/docs/admob/advanced

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

Thanks in advance !

2

2 Answers

0
votes

There is nothing wrong with your code.

But there may not be any ads to show. Suggest you

  1. add your device as a test device so you can see some test ads.
  2. Add some log into displayInterstitial so you can see when it is being called and if an ad is loaded.
  3. Attach an AdListsner to interstitialAd that logs the various states so you get a bit more insight on what is occurring.
  4. You will also need to call interstitial.loadAd again after you have display an ad to get another one.
0
votes

I think you followed the official admob guideline and you forgot about adding the listener within your onCreate method as shown below:

interstitial.setAdListener(new AdListener() {
     public void onAdLoaded() {
          displayInterstitial(interstitial);
     }
});

If you need further help, for example about using the interstitials from a non-UI thread you can find more details in the following post: http://www.6020peaks.com/2015/01/how-to-use-admob-interstitials-from-a-non-ui-thread-in-android/