LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:

1,732 views
Skip to first unread message

Raman R

unread,
Mar 29, 2017, 5:45:32 AM3/29/17
to Google Mobile Ads SDK Developers


Please any one help Now my app has on critical  by admob due to wrong interstitial code as

"Interstitial ads that load unexpectedly while a user is viewing the app’s content".

what to do? Please some one correct me...


 import android.view.Window;
    import android.view.WindowManager;
    import android.support.v7.app.AppCompatActivity;
    import android.webkit.WebSettings;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;

    import com.google.android.gms.ads.AdListener;
    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    import com.google.android.gms.ads.InterstitialAd;

    public class a2 extends AppCompatActivity {

        AdView mAdView;
        InterstitialAd mInterstitialAd;
        WebView WebViewWithCSS;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(R.layout.activity_a2);

            WebViewWithCSS = (WebView)findViewById(R.id.webView);

            WebSettings webSetting = WebViewWithCSS.getSettings();
            webSetting.setJavaScriptEnabled(true);

            WebViewWithCSS.setWebViewClient(new WebViewClient());
            WebViewWithCSS.loadUrl("file:///android_asset/2.html");

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

            mInterstitialAd = new InterstitialAd(this);

            // set the ad unit ID
            mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));

            adRequest = new AdRequest.Builder()
                    .build();

            // Load ads into Interstitial Ads
            mInterstitialAd.loadAd(adRequest);

            mInterstitialAd.setAdListener(new AdListener() {
                public void onAdLoaded() {
                    showInterstitial();
                }
            });
        }

        @Override
        public void onPause() {
            if (mAdView != null) {
                mAdView.pause();
            }
            super.onPause();
        }

        @Override
        public void onResume() {
            super.onResume();
            if (mAdView != null) {
                mAdView.resume();
            }
        }

        @Override
        public void onDestroy() {
            if (mAdView != null) {
                mAdView.destroy();
            }
            super.onDestroy();
        }


        private void showInterstitial() {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            }
        }
    }

Joshua Lagonera (Mobile Ads SDK Team)

unread,
Mar 29, 2017, 6:35:36 AM3/29/17
to Google Mobile Ads SDK Developers
Hi Raman,

From your code snippet, it looks like you are showing the Interstitial Ad right after it finishes loading, which can be described as "unexpected", as mentioned in the notification you received.

mInterstitialAd.setAdListener(new AdListener() {
  public void onAdLoaded() {
    showInterstitial();
  }
});

The app must explicitly call this method (.show()) at the appropriate time.
For reference, I would like to include the following links from our Help Center in guiding you to choose the proper implementation for your application:
Regards,
Joshua Lagonera
Mobile Ads SDK Team

Raman R

unread,
Mar 29, 2017, 6:45:58 AM3/29/17
to google-adm...@googlegroups.com
Sorry for the Inconvenience. i could not understand your reply could you please correct my source code.

for example-  i am having 10 buttons on Main activity for how to call the interstitial and other activities

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/A7xoI5TdHc8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua Lagonera (Mobile Ads SDK Team)

unread,
Mar 29, 2017, 10:08:27 PM3/29/17
to Google Mobile Ads SDK Developers
Hi Raman,

To correct your source code, you can remove the call to the showInterstitial() method on the onAdLoaded() listener.
However, I'm afraid I am not able to comment on when to display and show the Interstitial Ad as it is highly dependent on your application. 
You may use the previous resources I linked to guide you to choose the right implementation:
On Wednesday, March 29, 2017 at 6:45:58 PM UTC+8, Raman R wrote:
Sorry for the Inconvenience. i could not understand your reply could you please correct my source code.

for example-  i am having 10 buttons on Main activity for how to call the interstitial and other activities
Reply all
Reply to author
Forward
0 new messages