3
interstitial.setAdListener(new AdListener(){
    public void onAdLoaded(){
        display();
    }
});

I tried with the debugger, the 1st line was run, but the second line was simply not run. This is how I initialize the ad in the onCreate method:

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("******************************");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);

and InterstitialAd interstitial; outside of the method inside the class. The AdUnitId was deliberately blanked out.

Logcat:

05-17 20:10:49.802: E/GooglePlayServicesUtil(17509): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-17 20:10:49.807: E/GooglePlayServicesUtil(17509): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-17 20:10:51.597: I/GATE(17509): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
05-17 20:10:51.597: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.
05-17 20:10:51.602: I/Ads(17509): Ad finished loading.
05-17 20:10:51.632: D/TilesManager(17509): Starting TG #0, 0x5b3446f0
05-17 20:10:51.632: D/TilesManager(17509): new EGLContext from framework: 593202c0 
05-17 20:10:51.632: D/GLWebViewState(17509): Reinit shader
05-17 20:10:51.632: D/GLWebViewState(17509): Reinit transferQueue
05-17 20:10:56.262: D/AbsListView(17509): Get MotionRecognitionManager
05-17 20:11:31.987: I/Ads(17509): Ad is not visible. Not refreshing ad.
05-17 20:11:31.992: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.
zbz.lvlv
  • 3,597
  • 6
  • 34
  • 38

4 Answers4

0

Hope you have added following in AndroidManifest.xml

Internet permission

<uses-permission android:name="android.permission.INTERNET"/>

AdActivity

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

Google Play service lib under application tag

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

And added code as

    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(getResources().getString(R.string.admob_inst));
    // interstitial.setAdUnitId("01010101");
    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();
    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);
    interstitial.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            // TODO Auto-generated method stub
            super.onAdLoaded();
            interstitial.show();
        }
    });
MAC
  • 15,799
  • 8
  • 54
  • 95
  • It won't work. By the way the ad unit id was deliberately blanked out. @MAC – zbz.lvlv May 17 '14 at 11:13
  • I already had those in AndroidManifest. I have another banner ad in the main activity which works. This interstitial ad is not in the main activity. – zbz.lvlv May 17 '14 at 12:21
  • did check logcate ? and sure you have added this line `interstitial.show();` – MAC May 17 '14 at 12:22
  • I just checked. I found something fishy. I will update my question. I have the line interstitial.show() @MAC – zbz.lvlv May 17 '14 at 12:24
  • is your problem resolved? I am facing the same issue. onAdLoaded is never hit. – Sanmoy Oct 22 '14 at 06:45
0

Are you missing @override before onAdLoaded() method

essess
  • 277
  • 3
  • 7
  • yes. Even I added in the (at)Override still nothing came out. @essess – zbz.lvlv May 17 '14 at 11:15
  • add this and see if this is getting called (at)Override public void onAdFailedToLoad(int errorCode) – essess May 17 '14 at 11:52
  • I assume you are calling interstitial.show() in display() method. If not, then call interstitial.show(). Alternatively check if you are using latest google-play-services_lib – essess May 17 '14 at 12:10
  • I can't update on Android SDK tools. Does that mean I have the latest version of the google play lib? @essess – zbz.lvlv May 17 '14 at 12:17
  • yes then you have latest one. Please see MAC's answer below, you need to check the permissions & meta data in manifest file. – essess May 17 '14 at 12:23
0

Do NOT call display() from #onAdLoaded. This will results is a very poor UX. Instead call display from a natural break point in your application (if an ad has been loaded).

Also these lines in your logs suggest that you also have banner ads.

05-17 20:11:31.987: I/Ads(17509): Ad is not visible. Not refreshing ad.
05-17 20:11:31.992: I/Ads(17509): Scheduling ad refresh 60000 milliseconds from now.

If that is not the case then you have misconfigured your adUnit because you are getting auto refresh which does not happen for an interstitial. You need to explicitly load an interstitial each time.

William
  • 20,150
  • 8
  • 49
  • 91
0

Use the following code to display the ad's listener on AdLoaded(). I used the same. It was worked for me.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");

AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}

Outside oncreate function use below code:

public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
arunkumar
  • 67
  • 2
  • 10
  • 4
    Why do you check interstitial.isLoaded() if it was called by a listener method called onAdLoaded? – Ricardo Jan 23 '15 at 23:44