3

I'm trying to load interstitial ad on the tablet, with the test ad id. On output ad is not showing, but I'm getting the callback on "onAdLoaded".

This is my code:-

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 setContentView(R.layout.ad_activity);

 mPublisherInterstitialAd = new PublisherInterstitialAd(this);
 mPublisherInterstitialAd.setAdUnitId("/6499/example/interstitial");
 mPublisherInterstitialAd.loadAd(newPublisherAdRequest.Builder().build());

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

            Log.d("AD ","LOADED");
        }

        @Override
        public void onAdFailedToLoad(int i) {

            Log.d("AD ","FAILED");
        }
    });
}
Lucifer
  • 29,392
  • 25
  • 90
  • 143
ALEX JOY
  • 111
  • 1
  • 7
  • did you just created advertise ?, any error on logcat ? – Lucifer Mar 23 '18 at 10:29
  • This is my log.. – ALEX JOY Mar 23 '18 at 10:32
  • what kind of ad id is `/6499/example/interstitial` ?,Use this ad id `ca-app-pub-3940256099942544/1033173712` – Manohar Mar 23 '18 at 10:32
  • interstiatial ads take time to be ready. after what you did you need to call mPublisherInterstitialAd.show(). see https://developers.google.com/admob/android/interstitial – Angel Koh Mar 23 '18 at 10:37
  • These are my logs Starting ad request. Could not find method android.webkit.WebSettings.setMixedContentMode, referenced from method com.google.android.gms.ads.internal.webview.m. – ALEX JOY Mar 23 '18 at 10:40

2 Answers2

3

Try this

public void inrequestadd() {
    mInterstitial = new InterstitialAd(MainActivity.this);
    mInterstitial.setAdUnitId("Your ID");
    mInterstitial.loadAd(new AdRequest.Builder().build());
    mInterstitial.setAdListener(new AdListener() {

        @Override
        public void onAdClosed() {
            super.onAdClosed();

        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            super.onAdFailedToLoad(errorCode);

        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            if (mInterstitial.isLoaded()) {
                mInterstitial.show();
            }
        }

    });
}
Siddharth Patel
  • 205
  • 1
  • 13
0

Here is how I handle this kind of code

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initAds();
}

private void initAds() {
      MobileAds.initialize(this, "your app id");
      mInterstitialAd = new InterstitialAd(this);                         
      mInterstitialAd.setAdUnitId("your ad unit ID"); 
      mInterstitialAd.loadAd(new AdRequest.Builder().build());

      mInterstitialAd.setAdListener(new AdListener() {
        @Override
        public void onAdClosed() {
            // Load the next interstitial.
            mInterstitialAd.loadAd(new AdRequest.Builder().build());
        }

      });
}

Also in the manifest file:

    <meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="your app id"/>

Next, depending on the logic of your app, you would have something like:

if (mInterstitialAd.isLoaded()) {
   mInterstitialAd.show();
} else {
   System.out.println("The interstitial wasn't loaded yet. Do some other action");
}
Teshte
  • 624
  • 1
  • 7
  • 26