AdMob interstitial ad not loading

2019-08-06 09:46发布

The interstitial ad won't show in my application, I don't know what to do anymore.

Note: My app isn't listed in Google's Play store yet. I hope this isn't causing the fault.

What have I done:

  • I have created a new interstitial ad on the admob's site.

  • I have added Google Play to my project:

-

<activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@style/AppTheme.NoActionBar" />

<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

The Google Play service version is:

<integer name="google_play_services_version">6171000</integer>
  • I have added the InterstitialAd object

-

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

private InterstitialAd mInterstitialAd;

@Override
protected void onCreate(Bundle savedInstance) {
   //

   mInterstitialAd = new InterstitialAd(this);
   mInterstitialAd.setAdUnitId(AD_UNIT_ID);
   mInterstitialAd.setAdListener(mAdListener);

   AdRequest.Builder builder = new AdRequest.Builder();

   mInterstitialAd.loadAd(builder.build());
}
  • And the ad listener:

-

private AdListener mAdListener = new AdListener() {
   @Override
   public void onAdLoaded() {
      super.onAdLoaded();
      Functions.log("Ad loaded !");
   }
}

The method: onAdLoaded() isn't called. I left the application for 5 minutes but I got no response.

I have even tried to force show()

findViewById(R.id.btn_testAd).setOnClickListener(new View.OnCliclIstener() {
   @Override
   public void onClick(View v) {
      mInterstitialAd.show();
   }
});

What have I got in the logcat:

The interstitial has not loaded.

1条回答
做自己的国王
2楼-- · 2019-08-06 10:25

Sometimes programming is a pain.

I forgot to declare the permissions in the manifest file.

<!-- Used to request banner and interstitial ads. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Used to avoid sending an ad request if there is no connectivity. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Required permissions for video ads. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
查看更多
登录 后发表回答