Android Studio - How to put AdMob Interstitial

7

Transcript of Android Studio - How to put AdMob Interstitial

Page 1: Android Studio - How to put AdMob Interstitial
Page 2: Android Studio - How to put AdMob Interstitial

<string name=“interstitial_ad_unit_id">Your AdMob Interstitial ID here</string>

Include required permissions for Google Mobile Ads to run.

<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Page 3: Android Studio - How to put AdMob Interstitial

compile 'com.google.android.gms:play-services-ads:9.6.1'

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;

private InterstitialAd mInterstitialAd;

Page 4: Android Studio - How to put AdMob Interstitial

public void loadInterstitial() {

AdRequest adRequest = new AdRequest.Builder() .setRequestAgent("android_studio:ad_template").build(); mInterstitialAd.loadAd(adRequest);}

private void showInterstitial() {

// Show the ad if it's ready. Otherwise toast and reload the ad. if (mInterstitialAd != null && mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { //put code here to execute if ad did not show, example go to next level of a game }}

Page 5: Android Studio - How to put AdMob Interstitial

private InterstitialAd newInterstitialAd() { InterstitialAd interstitialAd = new InterstitialAd(this); interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id)); interstitialAd.setAdListener(new AdListener() {

@Override public void onAdClosed() { // put code to execute on ad closure, example, go to next level

in a game } }); return interstitialAd;}

mInterstitialAd = newInterstitialAd();loadInterstitial();

Page 6: Android Studio - How to put AdMob Interstitial