I’m new to Android App Development, and I have read the documentation and watched a few videos about how to implement banner ads. However, I couldn’t get it figured out. I’m not too sure where I’m messing up on the AdMob implementation code. I can see the “Ads By Google” banner ad in my activity_main.xml, but I cannot see any ad previews when launching the app.
build.gardle.kts (in dependencies):
implementation(libs.play.services.ads)
MainActivity.kt (in onCreate):
MobileAds.initialize(this@MainActivity) {}
adView = findViewById<View>(R.id.adView) as AdView
val adRequest = AdRequest.Builder().build()
adView.loadAd(adRequest)
AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
...
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="(Insert App ID Here)"/>
activity_main.xml:
<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="(Insert Unit Id Here)"/>