View
125
Download
0
Category
Preview:
Citation preview
<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" />
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;
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 }}
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();
Click the image above or this text toWatch video on Android Studio – How to put
Admob Interstitial at YouTubeYou can also download textfile on all the
methods by clicking here.
Recommended