Admob interstitial ad won't display

前端 未结 7 1873
心在旅途
心在旅途 2020-12-09 16:34

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

相关标签:
7条回答
  • 2020-12-09 16:49

    Try initializing it in onCreate, but only call the show() method from an event, such as a button click.

    You can use this code, the test ids work:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        ...
    
            MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713"); //test id
    
            mInterstitialAd = new InterstitialAd(this);
            mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); //test ad
    
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
    
    
            btn_test.setOnClickListener(view -> {
                showInterstitial();
            });
    ...
        }    
        private void showInterstitial()
        {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            } else {
                Log.d("TAG", "The interstitial wasn't loaded yet.");
            }
        }
    
    0 讨论(0)
  • 2020-12-09 16:52

    I had the same problem. The issue was that admob activity was not defined in manifest. Please make sure you have folllowing activity tag in your manifest file

    <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    
    0 讨论(0)
  • 2020-12-09 16:53

    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..

    0 讨论(0)
  • 2020-12-09 16:53

    You didn't call displayInsterstitial().

    But what you should do is call the listener for the interstitial :

    interstitial.setAdListener(this);
    

    It will then implements the Listener to your Activity and then display it onAdLoaded (or something).

    0 讨论(0)
  • 2020-12-09 16:55

    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();
              }
    });
    
    0 讨论(0)
  • 2020-12-09 16:56

    in your AndroidManifest you must put the tags

        <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:theme="@android:style/Theme.Translucent"
            tools:replace="android:theme" />
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="APP_ID" />
        <meta-data
            android:name="com.google.android.gms.ads.AD_MANAGER_APP"
            android:value="true" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    

    Ad Manager

    Ad Mob

    0 讨论(0)
提交回复
热议问题