Implement Google Ads with AdsManager

Rufan Khokhar
2 min readFeb 20, 2022
Photo by Nathana Rebouças on Unsplash

Implement Google ads with the easiest way on Android Apps

Google Ads SDK is very famous and is mostly used by Android developers. It’s very easy to use and manage but after using this library, I realized that I can make it more easiest for Android Developers. So, let's start.

Add it settings.gradle file.

Step-2

Add AdsManager dependency on your app-level build.gradle file

Step-3

Add your Ad Manager/Admob app ID (identified in the Ad Manager UI) to your app’s AndroidManifest.xml file. To do so, add a <meta-data> tag with android:name="com.google.android.gms.ads.APPLICATION_ID". You can find your app ID in the Ad Manager/Admob UI. For android:value, insert your own Ad Manager/Admob app ID, surrounded by quotation marks.

Step-4

Initialize the Google Mobile Ads SDK in oncreate() method in MainActivity.kt file

Load Banner Ads

XML Code

Kotlin Code for banner ad

Load Interstitial Ad

load interstitial ad and show anywhere within the app

Load Naive ads

Before loading the native ads, Keep in mind this library uses pre-defined native ad view ids for populating the native ad to NativeAdView. So, I recommended you used these ids to use the build-in native ad population.

Here is the predefined ids list and example view:

// Set the media view. Media content will be automatically populated in the media view once
// Set other ad assets
adView.headlineView = adView.findViewById(R.id.ad_headline)
val mediaView: MediaView? = adView.findViewById(R.id.ad_media)
adView.mediaView = mediaView
adView.bodyView = adView.findViewById(R.id.ad_body)
adView.callToActionView = adView.findViewById(R.id.ad_call_to_action)
adView.iconView = adView.findViewById(R.id.ad_app_icon)
adView.priceView = adView.findViewById(R.id.ad_price)
adView.starRatingView = adView.findViewById(R.id.ad_stars)
adView.storeView = adView.findViewById(R.id.ad_store)
adView.advertiserView = adView.findViewById(R.id.ad_advertiser)

Example View

kotlin code

Load App-Open Ads

--

--

Rufan Khokhar

Experienced Android Developer with a demonstrated history of working in the information technology and services industry.