I'm developing a new application and using Admob for interstitial ads. I coded the ads before 1-2 months and everything was great. These days I'm close to launch, but I noticed that ads are never displayed anymore since maybe 2 weeks. So I decided to debug. Everything seems alright with no exceptions, however the Admob SDK always reports that interstitial is not loaded, although the callback onAdLoaded
is called by the SDK.
Here is my configuration, I have omitted unrelated stuff:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}
}
dependencies {
compile "com.android.support:support-v4:18.0.+"
compile "com.google.android.gms:play-services-analytics:9.0.2"
compile 'com.google.android.gms:play-services-ads:9.0.2'
}
apply plugin: 'com.google.gms.google-services'
Here is the code snippet that has strange behaviour:
private com.google.android.gms.ads.InterstitialAd mInterstitialAd;
public void loadInterstitial() {
mInterstitialAd = new InterstitialAd(context);
mInterstitialAd.setAdUnitId(adUnitId);
mInterstitialAd.setAdListener(new AdListener()
{
@Override
public void onAdLoaded() {
super.onAdLoaded();
Log.d(TAG, "is loaded = " + mInterstitialAd.isLoaded()); // FALSE!!!
}
}
}
public void showInterstitial() {
if(mInterstitialAd.isLoaded()) { // ALWAYS FALSE!!!
mInterstitialAd.show();
} else {
loadInterstitial(); // FAILED TO LOAD AD with error code = 1
}
}
When I call showInterstitial
, after I have called loadInterstitial
and I can see that onAdLoaded
has been called, the check if interstitial is loaded always returns false, and loadInterstitial
method is called again and now Admob SDK gives me error that it failed to load ad with error code = 1.
This has been tested on multiple devices and there were no changes to the project related to ads or the Google Play Services library, it just stopped working.
Do you know what can be the problem or what can I do to debug more successfully these errors?
Thank you very much.
Add the latest gradle
compile 'com.google.android.gms:play-services-ads:9.2.1'
and remove
dependencies {
...
classpath 'com.google.gms:google-services:3.0.0'
}
also remove plugin
apply plugin: 'com.google.gms.google-services'
Update:
I think you are missing AdRequest
?
InterstitialAd mInterstitialAd = new InterstitialAd(mContext);
AdRequest adRequest = new AdRequest.Builder().build();
mInterstitialAd.setAdUnitId(mContext.getString(R.string.full_screen_id));
mInterstitialAd.loadAd(adRequest);