January 26, 2020 /   admob   interstitial ad   android   java

Many developers face problems while implementing AdMob's Interstitial Ads in android apps. Developer come to know problems after rejection or removal of apps from Google Play Store.

The messages developers get from AdMob

  1. We don’t allow apps whose primary purpose is to serve ads, or apps where interstitial ads are placed after every user action.
  2. Interstitial ads that appear after the user has exited the app
  3. LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS
  4. Interstitial ads that load unexpectedly while a user is viewing the app’s content.

AND many more...

Things to remember while implementing Interstitial

  1. Most of the time developers want to earn money by putting interstitial ads after every click. However this leads to a violation of policy. It is recommended that you should at show interstitial ad after every 3 or more clicks.
  2. Never put Interstitial ad after app has been closed.
  3. Showing ad while user is navigating is a policy violation. User should be aware of the actions where he can get interstitial ad. You should not call show() unexpectedly.

The correct Implementation

Defile a method showAd() that returns true when certain number of clicks has been happened.

public class App extends Application {
    public static int clicks;
    public static boolean showAd(Context context) {
        int threshold = Integer.parseInt(context.getString(R.string.interstitial_threshold));
        clicks += 1;
        return clicks % threshold == 0;
    }
}


Calling interstitial from activity

public class MyActivity extends AppCompatActivity {
    private InterstitialAd interstitialAd;
    final Button nextButton = findViewById(R.id.next_button);
    nextButton.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                boolean show = Utils.showAd(MyActivity.this);
                if (show && interstitialAd.isLoaded()) {
                    interstitialAd.show();
                } else {
                    Log.d("TAG", "The interstitial wasn't loaded yet.");
                    openNextActivity();
                }
             }
    });
}

private void initializeInterstitial() {
        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(getString(R.string.click_interstitial));
        interstitialAd.loadAd(new AdRequest.Builder().build());
    interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                // Load the next interstitial.
                interstitialAd.loadAd(new AdRequest.Builder().build());
                openNextActivity();
            }

            @Override
            public void onAdFailedToLoad(int i) {
                interstitialAd.loadAd(new AdRequest.Builder().build());
            }

            @Override
            public void onAdLeftApplication() {
                interstitialAd.loadAd(new AdRequest.Builder().build());
            }
        });
}

private void openNextActivity() {
    Intent myIntent = new Intent(this, NextActivity.class);
        this.startActivity(myIntent);
}

Related Posts

Android: Integrating Facebook Audience Network (FAN)

Android: Using together AdMob and Facebook Audience Network