Step 1: First of all create new Project in Android Studio then open build.gradle (Module App) and add Admob SDK dependency
implementation 'com.google.android.gms:play-services-ads:19.6.0'
Now open your Manifest.xml and Add meta data and internet permission
inside manifest tag
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
inside application tag
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
Add a Button in your layout file to set onClick to interstitial ads in your app
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/showAds"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Show"
/>
finally in you Activity.java class first of all add create a variable inside the class { }
InterstitialAd interstitialAd;
Button button;
then write these code inside you onCreate() method
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
interstitialAd.loadAd(new AdRequest.Builder().build());
button = findViewById(R.id.showAds);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (interstitialAd.isLoaded()){
interstitialAd.show();
}
}
});
congratulations finally you have successfully added a interstitial ads in your app