In this article, we have to create an AdMob medium rectangle banner ad format that is used to implement the bottom of the layout or else the top of the layout. So, we have to implement the below code in your project and follow step by step.
STEP: 01
We can insert dependency in your build.gradle(Module: level) given below.
// Admob Ads Dependency
implementation 'com.google.android.gms:play-services-ads:21.1.0'
STEP: 02
Insert Meta-Deta in your “manifests” file given below.
<!-- 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"/>
STEP: 03
We have to insert INTERNET permission to run this banner ad given below.
<uses-permission android:name="android.permission.INTERNET" />
STEP: 04
we have to create an AdView layout space to show ads in your project given below.
<com.google.android.gms.ads.AdView android:id="@+id/mediumRectangleBannerAd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginTop="8dp" app:adSize="MEDIUM_RECTANGLE" app:adUnitId="ca-app-pub-3940256099942544/6300978111" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/relativeLayout" app:layout_constraintVertical_bias="0" />
STEP: 05
we have to create a variable which is help to initialize ads in your project.
// AdView Variable private AdView mediumRectangleBannerAdFormat;
STEP: 06
Now, we have to initialize the banner ad and request the ad and also load this ad in the layout of your project.
// Admob Ads Code Here MobileAds.initialize(this, initializationStatus -> { }); mediumRectangleBannerAdFormat = findViewById(R.id.mediumRectangleBannerAd); AdRequest adRequest = new AdRequest.Builder().build(); mediumRectangleBannerAdFormat.loadAd(adRequest);
STEP: 07
Finally, we can create the onPause, onResume, and onDestroy methods to protect you from invalid click activity of your ADMOB Account.
@Override protected void onPause() { if (mediumRectangleBannerAdFormat != null) { mediumRectangleBannerAdFormat.pause(); } super.onPause(); } @Override protected void onResume() { if (mediumRectangleBannerAdFormat != null) { mediumRectangleBannerAdFormat.pause(); } super.onResume(); } @Override protected void onDestroy() { if (mediumRectangleBannerAdFormat != null) { mediumRectangleBannerAdFormat.pause(); } super.onDestroy(); }
Finally, you can “RUN” this mobile application on your real Mobile Device. An image is given below to help you how to look at your application.

————— THANK YOU VERY MUCH —————