I am trying to ad using AdMob to display ads at the bottom of screen.
I added following line in my build.gradle file to get AdMob sdk:
compile 'com.google.android.gms:play-services-ads:8.4.0'
After then, I added AdView in XML to show 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 make a referecne of AdView using ad_view id and build AdRequest to request for ads using following lines of code:
AdView mAdView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
// .addTestDevice("38C0F116926519A0CBAF1094898921FB")
.build();
if (mAdView != null)
mAdView.loadAd(adRequest);
Everything works perfect if I uncomment addTestDevice
function but when I try to display real ads, I am getting 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 searching the issue, I tried the solutions from the below links but none of them worked for me.
Uncaught ReferenceError: AFMA_getSdkConstants is not defined
Interstitial Admob doesn't work : AFMA_ReceiveMessage is not defined
Please suggest me what I am doing wrong or what I am missing. Thanks.
I check your code and is correct, some times you have to do 2 things:
1- Wait for check, remember you just add the ad a few minutes ago. 2- Try in a real device, remember you dont have the same stuff like play store servies in a emulator.