How to Implement Admob Ads in Android Studio | Banner and interstitial ads | Google Admob Ads 2023

Devendra Chavan
2 min readJul 31, 2023

--

Hello, and Welcome to the #CodingWithDev​ channel! In this tutorial, We will learn how to integrate AdMob ads into your Android app step by step using a Kotlin.

Here’s the official website for Admob detailed instructions:
https://developers.google.com/admob/android/quick-start

  1. Create an AdMob Account:

If you don’t have an AdMob account, sign up at https://apps.admob.com.

2. Create an Ad Unit ID:

After logging in to your AdMob account, create a new Ad Unit ID for each type of ad you want to display (Banner and Interstitial).

3. Integrate Google Play Services:

Ensure that you have Google Play Services integrated into your Android Studio project. You can add it to your app’s build.gradle file:

dependencies {
implementation 'com.google.android.gms:play-services-ads:20.4.0' // Use the latest version available
}

4. Add Permissions to the AndroidManifest.xml:

Add the required permissions to display ads in your AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

5. Implement Banner Ads:

To display Banner ads in your activity or fragment, you’ll need to add a com.google.android.gms.ads.AdView to your layout XML file:

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />

Then, in your activity or fragment, load the ad:

AdView adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

Replace @string/banner_ad_unit_id with the actual Ad Unit ID for your Banner ad.

6. Implement Interstitial Ads:

For Interstitial ads, you’ll need to create an com.google.android.gms.ads.InterstitialAd object:

InterstitialAd interstitialAd;

// In onCreate or wherever you initialize your InterstitialAd
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.interstitial_ad_unit_id));
interstitialAd.loadAd(new AdRequest.Builder().build());

To show the Interstitial ad, you’ll typically do this when it’s appropriate, such as after a user completes an action:

if (interstitialAd.isLoaded()) {
interstitialAd.show();
}

Replace @string/interstitial_ad_unit_id with the actual Ad Unit ID for your Interstitial ad.

7. Test Your Ads:

While testing your app, use test ads to avoid invalid clicks. Add the following code in your AdRequest setup:

AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) // For emulator
.addTestDevice("YOUR_DEVICE_TEST_ID") // For your physical device
.build();

Replace "YOUR_DEVICE_TEST_ID" with your device's test ID. You can find the test ID in the logcat when you run the app with test devices enabled.

Show More Tutorials And Feel free to SUBSCRIBE to my YOUTUBE channel Thank You :-)

--

--

Devendra Chavan
Devendra Chavan

Written by Devendra Chavan

Android Mobile Application Developer

No responses yet