Interstitial ads are full-screen ads that cover the interface of their host app. Today we will tell you in this post how you can install Interstitial ads in your app through android-studio, we will tell you step by step how to install.
In very simple language, we told you how you can put Interstitial ads on your app, nothing we tell you.
Fast Step:
build.gradle:
1.
implementation 'com.google.android.gms:play-services-ads:21.0.0'
2.
Manifest.xml:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
3.
private InterstitialAd mInterstitialAd;
Full code interstitial ad for Android studio:
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(this,"ca-app-pub-3940256099942544/1033173712", adRequest,
new InterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
// The mInterstitialAd reference will be null until
// an ad is loaded.
mInterstitialAd = interstitialAd;
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
// Handle the error
mInterstitialAd = null;
}
});
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){
@Override
public void onAdDismissedFullScreenContent() {
// Called when fullscreen content is dismissed.
Log.d("TAG", "The ad was dismissed.");
}
@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
// Called when fullscreen content failed to show.
Log.d("TAG", "The ad failed to show.");
}
@Override
public void onAdShowedFullScreenContent() {
// Called when fullscreen content is shown.
// Make sure to set your reference to null so you don't
// show it a second time.
mInterstitialAd = null;
Log.d("TAG", "The ad was shown.");
}
});
3.
if (mInterstitialAd != null) {
mInterstitialAd.show(VideoActivity.this);
} else {
Log.d("TAG", "The interstitial ad wasn't ready yet.");
}