Monetize your Android app using AdMob Banner Ads.

Suraj Shende
Road to Code
Published in
Nov 16, 2020
credit:https://www.nitecodes.com/

In this article, I will walk you through how to monetize any android app by showing ads(Banner Ads) using AdMob.

SDK Setup

This step is common for all types of advertisements.

Add the following dependency to your app-level Gradle file to pull the Mobile Ads SDK.

implementation 'com.google.android.gms:play-services-ads:19.5.0'

In AndroidManifest.xml add the following tag inside the application tag.

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>

Initialize Mobile Ads SDK by calling MobileAds.initialize() inside OnCreate() method.

MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});

Banner Ads Layout

Add AdView to the layout

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
</com.google.android.gms.ads.AdView>

Now Load an Ad in Java file

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

For detailed information watch this YouTube Video:

--

--