I'm trying to use admob to serve ads at the bottom of the screen.
I added the following line in the build.gradle file to get AdMob sdk:
compile 'com.google.android.gms:play-services-ads:8.4.0'
After that, I added AdView to XML to display ads:
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
app:adSize="BANNER"
android:layout_gravity="bottom"
app:adUnitId="@string/banner_ad_unit_id" />
Now I create an AdView link using id_view_view and create an AdRequest to request ads using the following lines of code:
AdView mAdView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
.build();
if (mAdView != null)
mAdView.loadAd(adRequest);
Everything works fine if I uncomment the function addTestDevice, but when I try to display real ads, I get the following error in logcat:
12-23 17:18:02.234 13226-13226/com.abc.xyz I/Ads: Starting ad request.
12-23 17:18:02.234 13226-13226/com.abc.xyz I/Ads: Use AdRequest.Builder.addTestDevice("38C0F116926519A0CBAF1094898921FB") to get test ads on this device.
12-23 17:18:02.554 13226-13226/com.abc.xyz I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@42dd86b8 time:83516183
12-23 17:18:05.694 13226-13226/com.abc.xyz D/EgretLoader: EgretLoader(Context context)
12-23 17:18:05.694 13226-13226/com.abc.xyz D/EgretLoader: The context is not activity
12-23 17:18:05.764 13226-13226/com.abc.xyz I/Ads: Ad finished loading.
12-23 17:18:05.824 13226-13226/com.abc.xyz E/Ads: JS: Uncaught ReferenceError: AFMA_ReceiveMessage is not defined (:1)
12-23 17:18:05.824 13226-13226/com.abc.xyz I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: AFMA_ReceiveMessage is not defined", source: (1)
After finding the problem, I tried the solutions from the links below, but none of them worked for me.
Uncaught ReferenceError: AFMA_getSdkConstants not defined
Interstitial admob not working: AFMA_ReceiveMessage not defined
, , . .