Ads

Google Admob - Banner & Interstitial

Config Adsense

You must set 5 value to configure your admob, all of these value you can change from file res/values/strings.xml

  • admob_app_id

  • banner_ad_unit_id

  • interstitial_ad_unit_id

  • publisher_id

  • privacy_policy_url

here how to get admob app id and unit id https://support.google.com/admob/answer/7356431?hl=en

res/values/strings.xml
<!--ADMOB property -->
<string name="admob_app_id">ca-app-pub-XXXXXXXXX</string>
<string name="banner_ad_unit_id">ca-app-pub-XXXXXXXXX</string>
<string name="interstitial_ad_unit_id">ca-app-pub-XXXXXXXXX</string>

<!--GDPR property -->
<string name="publisher_id">pub-XXXXXXXXX</string>
<string name="privacy_policy_url">http://dream-space.web.id/</string>

Why admob not showing?

From our experience admob sometimes not showing when you run and test app from android studio, admob will showing after app published to google play. But if you want to test how admob in this app working you can use testing unit id https://developers.google.com/admob/android/test-ads

Very Important you change ad unit id with your own unit id before publish to google play.

Disable Ads

new we make easy way to disable or enable adsense in the app, you only need to set boolean value with TRUE or FALSE

AppConfig.java
public class AppConfig {

    // flag for enable/disable all ads
    private static final boolean ADS_ENABLE = true;

    // flag for display ads (change true & false ant the end only )

    public static final boolean ADS_MAIN_ALL = ADS_ENABLE && true;
    public static final boolean ADS_MAIN_BANNER = ADS_ENABLE && ADS_MAIN_ALL && true;
    public static final boolean ADS_MAIN_INTERS = ADS_ENABLE && ADS_MAIN_ALL && true;
    public static final int ADS_INTERS_MAIN_INTERVAL = 60; // in second

    public static final boolean ADS_DETAILS_ALL = ADS_ENABLE && true;
    public static final boolean ADS_DETAILS_BANNER = ADS_ENABLE && ADS_DETAILS_ALL && true;
    public static final boolean ADS_DETAILS_INTERS = ADS_ENABLE && ADS_DETAILS_ALL && true;
    public static final int ADS_INTERS_DETAILS_FIRST_INTERVAL = 5; // in second
    public static final int ADS_INTERS_DETAILS_NEXT_INTERVAL = 60; // in second

    public static final boolean ADS_NOTIFICATION_PAGE = ADS_ENABLE && true;
    public static final boolean ADS_SEARCH_PAGE = ADS_ENABLE && true;
	
	. . .
}

Last updated

Was this helpful?