android - 无法显示 AdMob 横幅

标签 android admob banner uncaught-exception referenceerror

我正在尝试使用 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 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34435281/

相关文章:

Android LogCat 不适用于模拟器

java - 查找 EditText 可编辑的 getSpans 开始和结束索引

android - 我怎样才能看到缩小代码的效果

kotlin - 如何在 android studio 中实现 Admob Interstitial Ad - Kotlin

ios - 无法在方向更改时调整 AdMob View 的大小

css - 我的横幅在 Safari 5.1.7 中不可见

html - 对象在同一条线上而不丢失位置?

java - 从 CSV raw 插入 SQLite 的更快方法?

android - Android :configChanges Eclipse 中的 Admob 错误

android - admob 横幅未显示在弹出窗口中