Programmatically close an interstitial ad

前端 未结 4 2065
离开以前
离开以前 2020-12-10 14:23

I want to make sure that interstitial ads on Android, using the Android AdMob SDK, can be closed. After some research, it seems to me that this is not possible due to the ad

4条回答
  •  渐次进展
    2020-12-10 15:03

    For new readers. use:

    Intent intent = new Intent(activity, activity.getClass());
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        activity.startActivity(intent);
    
    
    
            @Override
            public void onAdOpened() {
                // Code to be executed when the ad is displayed.
                Log.d("mInterstitialAd", "onAdOpened  ");
                fullscreenAdShowing = true;
                new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if(!fullscreenAdShowing){
                            return;
                        }
                        Log.d("mInterstitialAd", "onAdOpened  Handler 5 seconds run");
                        Intent intent = new Intent(activity, activity.getClass());
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        activity.startActivity(intent);
    
                    }
                }, 5000);
            }
    
            @Override
            public void onAdClosed() {
                // Code to be executed when when the interstitial ad is closed.
                Log.d("mInterstitialAd", "onAdClosed  loadAd");
                fullscreenAdShowing = false;
    
                mInterstitialAd.loadAd(new AdRequest.Builder().build());
    
            }
    

提交回复
热议问题