admob interstitals

Sup guys, I need some help getting admob interstitals to work, I have the banners working but admob interstitals not working.

Can someone give me working code to have it display immediately, since this will be in live wallpapers.

I need the imports as well. I want it to display as soon as the app is launched. Also is it allowed to have an interstitial ad popup when there is an admob banner on the screen as well?

https://developers.google.com/mobile-ads-sdk/docs/

I passed that info to our website developers already but it doesn’t seem to click with them.

Following is the code for showing InterstitialAd on start off app.


import com.google.android.gms.ads.*;

public class BannerExample extends Activity {

  private InterstitialAd interstitial;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the interstitial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId(MY_AD_UNIT_ID);

    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();

    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);

  }

  // Invoke displayInterstitial() when you are ready to display an interstitial.
  public void displayInterstitial() {
    if (interstitial.isLoaded()) {
      interstitial.show();
    }
  }
}


I think you should pass above code to android developers instead on web developers. :wink:

The above codes definitely doesn’t work, you need to call displayInterstitial() when your ad is ready. Go read about listener of Admob’s interstitial.

Here it is. Just insert the logic to go to your desired activity after the ad is clicked, or gives error or is canceled. This code is for when you exit the app.

package com.xxxxxxxx;

import android.provider.Settings;
import android.view.ViewGroup;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**

  • An {@link Activity} that requests and can display an InterstitialAd.
    /
    public class InterstitialAd extends Activity {
    /
    * The log tag. */
    private static final String LOG_TAG = “InterstitialSample”;

    /** Your ad unit id. Replace with your actual ad unit id. */
    private static final String AD_UNIT_ID = “ca-app-pub-3448205561637334/9xxxxxx”;

    /** The interstitial ad. */
    private com.google.android.gms.ads.InterstitialAd interstitialAd;

    /** The button that show the interstitial. */
    private Button showButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.interstitial);

     // Create an ad.
     interstitialAd = new com.google.android.gms.ads.InterstitialAd(this);
     interstitialAd.setAdUnitId(AD_UNIT_ID);
    
    
     loadInterstitial();
    
     interstitialAd.setAdListener(new AdListener() {
         @Override
         public void onAdLoaded() {
             Log.d(LOG_TAG, "onAdLoaded");
    
             showInterstitial(((ViewGroup)findViewById(android.R.id.content)).getChildAt(0));
    
    
         }
    
         @Override
         public void onAdFailedToLoad(int errorCode) {
             String message = String.format("onAdFailedToLoad (%s)", getErrorReason(errorCode));
             Log.d(LOG_TAG, message);
             finish();
    
         }
    
    
     });
    

    }

    public void loadInterstitial() {

     AdRequest adRequest = new AdRequest.Builder()
             .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
             .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
             .build();
    
     // Load the interstitial ad.
     interstitialAd.loadAd(adRequest);
    

    }

    /** Called when the Show Interstitial button is clicked. */
    public void showInterstitial(View unusedView) {

     if (interstitialAd.isLoaded()) {
         interstitialAd.show();
     } else {
         Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");
     }
    

    }

    /** Gets a string error reason from an error code. */
    private String getErrorReason(int errorCode) {
    String errorReason = “”;
    switch(errorCode) {
    case AdRequest.ERROR_CODE_INTERNAL_ERROR:
    errorReason = “Internal error”;
    break;
    case AdRequest.ERROR_CODE_INVALID_REQUEST:
    errorReason = “Invalid request”;
    break;
    case AdRequest.ERROR_CODE_NETWORK_ERROR:
    errorReason = “Network Error”;
    break;
    case AdRequest.ERROR_CODE_NO_FILL:
    errorReason = “No fill”;
    break;
    }
    return errorReason;
    }

}

Thank you for posting this information!)