Home > OS >  admob interstital ad listener not defined
admob interstital ad listener not defined

Time:10-01

i had an android project that contained interstitial ad that was working perfectly , after i updated the admob libraries the listeners are not working and showing undefined

 //setAdListener not defined
 mInterstitialAd.setAdListener(new AdListener() {
     @Override
     public void onAdLoaded() {
         Toast.makeText(MyActivity.this,
                 "The interstitial is loaded",    Toast.LENGTH_SHORT).show();
     }

     @Override
     public void onAdClosed() {
         // Proceed to the next level.
         goToNextLevel();
     }
 });

i have searched for new implementation documentation but didn't find anything similar to this case where i want to use the onAdClosed method to open a new intent

CodePudding user response:

Sorry my english (:

i'm using :

implementation 'com.google.android.gms:play-services-ads:20.2.0'

in class...

AdRequest adRequest = new AdRequest.Builder().build();

InterstitialAd mInterstitialAd = null;

Call Method:

public void adInterstitialCall(){

        if(mInterstitialAd == null){

            InterstitialAd.load(this,this.getString(R.string.ad_interstitial), adRequest, new InterstitialAdLoadCallback() {
                @Override
                public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { mInterstitialAd = interstitialAd; }

                @Override
                public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                    mInterstitialAd = null;
                }

            });
        }

    }

Show and close listener:

public void adInterstitialShow(){

        if (mInterstitialAd != null) {

            mInterstitialAd.show(this);

            mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){

                @Override
                public void onAdDismissedFullScreenContent() {
                    mInterstitialAd = null;
                    adInterstitialCall();
                }

            });
        }
        else{adInterstitialCall();}
    }
  • Related