android admob sdk,android – 无法显示AdMob横幅
我正在嘗試使用AdMob廣告在屏幕底部顯示廣告.
我在build.gradle文件中添加了以下行以獲取AdMob sdk:
compile 'com.google.android.gms:play-services-ads:8.4.0'
之后,我在XML中添加了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)
在搜索問題之后,我嘗試了以下鏈接中的解決方案,但它們都沒有為我工作.
請告訴我我做錯了什么或我錯過了什么.謝謝.
解決方法:
我檢查你的代碼是正確的,有時你必須做兩件事:
1-等待檢查,記住您只需在幾分鐘前添加廣告.
2-嘗試一個真實的設備,記住你沒有像模擬器中的Play商店服務那樣的東西.
標簽:android,admob,banner,uncaught-exception,referenceerror
來源: https://codeday.me/bug/20190528/1168191.html
總結
以上是生活随笔為你收集整理的android admob sdk,android – 无法显示AdMob横幅的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 神奇的奇偶性原理
- 下一篇: 使用selenium爬取艺恩网年度票房(