I see that there are two problems in your code based on what you posted:
The <metadata> section should contain ADMOB_APP_ID instead of your publisher ID. This should be declared in <application> in ApplicationManifest.xml.
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="[ADMOB_APP_ID]"/>
You can find ADMOB_APP_ID in the ADMOB toolbar, click on the application
and check the "Application Settings". You can see the APP_ID that starts
usually with ca-app-pub-0123456789012345.
The second problem is where you declared AdView in your layout. Remember that you must provide the ad unit, not the publisher ID, which you can create in the ADMOB control panel by clicking on the ad unit tab.
according to your statement. Place the correct “ad unit” in the AdView as shown below.
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
After resolving the above issues, follow these steps:
MobileAds.initialize(this, "YOUR_ADMOB_APP_ID"); to create your first activity. This needs to be done only once, and thus the right place is either your first action or the onCreate application callback.
Find the AdView in the onCreate action, where you included the AdView in the layout.
mAdView = findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest);
Test ads work by providing test Adunit published by Google.
mAdView.setAdSize(AdSize.BANNER); mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
In addition, if you want to handle promotional events, do the following: -
mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() {
source share