How to Implement Admob Interstitial Ads in Android Studio|| Interstitial ads 2020

 How to Implement Admob Interstitial Ads in Android Studio|| Interstitial ads 2020

How to Implement Admob Ads in Android Studio




Google Test ID :

1. Sample AdMob App test ID:   ca-app-pub-3940256099942544~3347511713 
2. Interstitial test ID :     ca-app-pub-3940256099942544/1033173712


How To Get Device ID for testing ads

1. open LOGCAT in Android Studio

2. in search box search addtestdevice

3. you will get your device id


4. to add test device

AdRequest request = new AdRequest.Builder()

.addTestDevice("your device id")  

.build(); 


1: In Mainactivity.java

in package : 

import com.google.android.gms.ads.InterstitialAd; 

in public class : 

private InterstitialAd mInterstitialAd; 

in protected void :  mInterstitialAd = new InterstitialAd(this);

mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder()
.build());


in  public void onBackPressed: replace all this 

{
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
if (mywebView.canGoBack()) {
mywebView.goBack();
} else {
super.onBackPressed();
}

mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {

if (mywebView.canGoBack()) {
mywebView.goBack();
} else {


mInterstitialAd.loadAd(new AdRequest.Builder().build());
}

            }}); 


 

Post a comment

1 Comments

WARNING:
Don't do spam comments!