androidadmobinterstitial

Why are interstitial ads not showing on device


I developed an Android app and I integrated Google's adMob interstitial ad. The problem is that on the emulator the ad is successfully shown but on my device it is not showing up. I created the Ad Unit Id that I created on AdMob and I linked the App to adMob.

Here is My code :

InterstitialAd mInterstitialAd;

mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
        AdRequest adRequest = new AdRequest.Builder().build();
        // Load ads into Interstitial Ads
        mInterstitialAd.loadAd(adRequest);
        mInterstitialAd.setAdListener(new AdListener() {
            public void onAdLoaded() {
                showInterstitial();
            }
        });

Now the showInterstitial() function :

private void showInterstitial() {
    Random r = new Random();
    if (mInterstitialAd.isLoaded()) {
        new android.os.Handler().postDelayed(
                new Runnable() {
                    public void run() {

                        mInterstitialAd.show();
                        AdRequest adRequest = new AdRequest.Builder().build();
                        mInterstitialAd.loadAd(adRequest);
                    }
                },
                r.nextInt(7000 - 5000) + 5000);

    }
}

I added a random timeout and when the ad is loaded it will be displayed.

and In my gradle file I added the following :

compile 'com.google.android.gms:play-services-ads:9.8.0'

NB. I have another banner ad in the App.

on the emulator it works just fine here is a screenshot :

enter image description here

Any One have any idea why the Interstitial Ad isn't showing on devices? . Thank You.


Solution

  • I fixed the issue but changing how I call my showInterstitial() function . The problem was related to the loading of the ad. Here is my fix :

      @Override
        public void onResume() {
            // Start or resume the game.
            super.onResume();
            showInterstitial();
        }
        @Override
        protected void onStart() {
            super.onStart();
            showInterstitial();
        }
    

    I show the Ad when the Activity Starts or when it is resumed , we need an event to show the Ad.

    This is how I declared the interstitial Ad and my showInterstitial() function :

    //Interstitial
                private InterstitialAd mInterstitialAd;
                mInterstitialAd = new InterstitialAd(this);
                mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_interstitial));
                AdRequest adRequestInterstitial = new AdRequest.Builder().addTestDevice("deviceid").build();
                mInterstitialAd.loadAd(adRequestInterstitial);
    
                mInterstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdClosed() {
    
                    }
    
                    @Override
                    public void onAdLoaded() {
                        mAdIsLoading = false;
                        showInterstitial();
                    }
    
                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        mAdIsLoading = false;
                    }
                });
    

    This is my Result on my Samsung Device :

    enter image description here

    I Think that was the issue.