AdMob interstitial ad not loading

被刻印的时光 ゝ 提交于 2019-12-11 12:38:33

问题


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:


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" />


来源:https://stackoverflow.com/questions/27953046/admob-interstitial-ad-not-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!