Interstitial Ad only show after two calls to interstitialAd.show()

513 views
Skip to first unread message

Jonathan Fiszer

unread,
Jul 31, 2022, 11:27:31 PM7/31/22
to Google Mobile Ads SDK Developers
Hi!

This is my first time with Android Studio.

I´m making a webview app (a JS game) with a banner and Interstitials ads, but I´am having a strange problem with the Interstitials.

They only show up after making two calls to «interstitialAd.show()», even after «interstitialAd» is loaded and it´s not null.

So, «interstitialAd» have an ID but when I call interstitialAd.show() nothing happens. But when I call interstitialAd.show() some seconds again then the Ad show up.

And it´s allways the same. Not one or three. Two calls needed. No matters the way I call the function (from the webview or from a botton in Java).

Now I made a workaround and I call «interstitialAd.show()» two times with 10 ms difference, and it´s imperceptible for the user, but I´m afraid to break some AdMob policy.

Anyone have some idea what could be wrong?

Here´s my code now:

public class MainActivity extends Activity
{
     private WebView mWebView;
     private AdView mAdView;  
     public InterstitialAd interstitialAd;
   
     private static final long GAME_LENGTH_MILLISECONDS = 3000;
     private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712";
     private static final String TAG = "MainActivity";

     @Override
     @SuppressLint("SetJavaScriptEnabled")

     protected void onCreate(Bundle savedInstanceState)
     {
         setTheme(R.style.AppTheme);
         super.onCreate(savedInstanceState);

         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

         setContentView(R.layout.activity_main);

         // Con esto configuramos y cargamos el WebView
         mWebView = findViewById(R.id.activity_main_webview);
         WebSettings webSettings = mWebView.getSettings();
         webSettings.setJavaScriptEnabled(true);
         webSettings.setDomStorageEnabled(true);
         webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
         webSettings.setAppCacheEnabled(true);
         mWebView.setWebViewClient(new MyWebViewClient());
         mWebView.setWebContentsDebuggingEnabled(true);

         mWebView.addJavascriptInterface(new AndroidtoJS(), "test"); //Androidto js class object maps to js test object

         mWebView.loadUrl("file:///android_asset/index.html");

         MobileAds.initialize(this, new OnInitializationCompleteListener() {
             @Override
             public void onInitializationComplete(InitializationStatus initializationStatus) {
             }
         });

         mAdView = findViewById(R.id.adView);
         AdRequest adRequest = new AdRequest.Builder().build();
         mAdView.loadAd(adRequest);

         loadAd();

     }
   
     public void loadAd()
     {
         AdRequest adRequest = new AdRequest.Builder().build();
         InterstitialAd.load(
                 this,
                 AD_UNIT_ID,
                 adRequest,
                 new InterstitialAdLoadCallback()
                 {
                     @Override
                     public void onAdLoaded(@NonNull InterstitialAd interstitialAd)
                     {

                         MainActivity.this.interstitialAd = interstitialAd;

                         Log.i(TAG, "onAdLoaded");

                         interstitialAd.setFullScreenContentCallback(new FullScreenContentCallback()
                         {
                             @Override
                             public void onAdDismissedFullScreenContent()
                             {
                                MainActivity.this.interstitialAd = null;
                                Log.d("TAG", "The ad was dismissed.");
                                loadAd();
                             }

                             @Override
                             public void onAdFailedToShowFullScreenContent(AdError adError)
                             {
                                MainActivity.this.interstitialAd = null;
                                Log.d("TAG", "The ad failed to show.");
                             }

                             @Override
                             public void onAdShowedFullScreenContent()
                             {
                             }
                        });
                     }

                     @Override
                     public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                        Log.i(TAG, loadAdError.getMessage());
                        interstitialAd = null;

                        String error = String.format(
                                "domain: %s, code: %d, message: %s",
                                loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage()
                        );
                     }
                 }
         );
    }

    public void showInterstitial() {
        if (interstitialAd != null) {
            MainActivity.this.interstitialAd.show(MainActivity.this);
        } else {
        }
    }

    public class AndroidtoJS extends Object
    {
        @JavascriptInterface
        public void cargarAnuncio(String msg) {
            MainActivity.this.showInterstitial();
        }
    }
}

Mobile Ads SDK Forum Advisor

unread,
Aug 1, 2022, 9:04:11 AM8/1/22
to jony....@gmail.com, google-adm...@googlegroups.com
Hi Jonathan,

Thank you for reaching out to us. Let me do the best I can to assist you in this.

I've tested our sample app, and can confirm that the first ad request fails and requesting another one successfully load an ad. However, the onAdFailedToLoad() were called when the ad request fails on my end. If onAdFailedToLoad() triggers when you've requested an ad, then it safe to request another one. Requesting for multiple interstitial ad (on a short period of time) is against AdMob policy. However, based on your use case, your ad request has been filled (interstitialAd is loaded and not null), and you're just calling the show() method two times. I could confirm that there's no violated AdMob policy for this use case.

Regards,
Google Logo
Teejay Wennie
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2d3TtP:ref

Jonathan Fiszer

unread,
Aug 3, 2022, 5:15:42 PM8/3/22
to Google Mobile Ads SDK Developers
Thank you very much for the answer and the test!

I'm keep calm with my workaround then

Mobile Ads SDK Forum Advisor

unread,
Aug 4, 2022, 2:18:43 AM8/4/22
to jony....@gmail.com, google-adm...@googlegroups.com

Hi Jonathan,

If you have any other concerns related to the implementation of Google Mobile Ads SDK, kindly provide us the details. We'll be happy to assist you.

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2d3TtP:ref
Reply all
Reply to author
Forward
0 new messages