the killer
the killer

Reputation: 35

admob interstitial not showing with google play services?

I'm trying to upgrade to google play services Admob version, However i can't seem to find the right way to show interstitial ads after trying for a few days, banner views seem to be displayed fine, its only the interstitial that's a problem.

This is my current code after referencing the google play services.

private InterstitialAd interstitial;



  public void onCreate(Bundle savedInstanceState)
  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("TEST_DEVICE_ID")
            .build();
        adView.loadAd(adRequest);



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

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

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


      }



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

Banners are showing normally, interstitial nothing and there is nothing significant in the log cat either. thanks

    <?xml version="1.0" encoding="utf-8"?>

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <supports-screens android:smallScreens="true"
    android:normalScreens="true" android:largeScreens="true"
    android:anyDensity="true" />
                    <uses-permission android:name="android.permission.INTERNET"/>
                    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>




    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:hardwareAccelerated="true"
         >



       <activity android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:theme="@android:style/Theme.Translucent"/>
<meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version"
           />

Upvotes: 1

Views: 780

Answers (1)

Antwan
Antwan

Reputation: 3876

The method displayInterstitial() is responsible of showing the Interstitial Ads

call this method in any place or event you want to show the Ads on

for example in onclick listener of any button and it will be shown

Edit if you want to show the Ads on the start of the App try using the adslistener like this

 interstitial.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {

            if (interstitial.isLoaded()) {
                interstitial.show();
            }

    }

    @Override
    public void onAdOpened() {


    }

    @Override
    public void onAdFailedToLoad(int errorCode) {

    }
});

Upvotes: 2

Related Questions