android – 无法显示AdMob横幅
作者:互联网
我正在尝试使用AdMob广告在屏幕底部显示广告.
我在build.gradle文件中添加了以下行以获取AdMob sdk:
compile 'com.google.android.gms:play-services-ads:8.4.0'
之后,我在XML中添加了AdView来展示广告:
<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" />
现在,我使用ad_view id制作AdView的参考资料,并使用以下代码行构建AdRequest来请求广告:
AdView mAdView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
// .addTestDevice("38C0F116926519A0CBAF1094898921FB")
.build();
if (mAdView != null)
mAdView.loadAd(adRequest);
如果我取消注释addTestDevice函数但是当我尝试显示真实广告时,一切都很完美,我在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)
在搜索问题之后,我尝试了以下链接中的解决方案,但它们都没有为我工作.
Uncaught ReferenceError: AFMA_getSdkConstants is not defined
Interstitial Admob doesn’t work : AFMA_ReceiveMessage is not defined
请告诉我我做错了什么或我错过了什么.谢谢.
解决方法:
我检查你的代码是正确的,有时你必须做两件事:
1-等待检查,记住您只需在几分钟前添加广告.
2-尝试一个真实的设备,记住你没有像模拟器中的Play商店服务那样的东西.
标签:android,admob,banner,uncaught-exception,referenceerror 来源: https://codeday.me/bug/20190528/1168191.html