广告加载失败:0 使用测试广告时

Ad failed to load : 0 WHEN USING TEST AD

我正在努力在我的应用程序中实施 adMob 我正在使用测试广告本机 ID 以查看一切正常我一直遇到此错误:

Ad failed to load : 0

。我在这里看到一些帖子,这可能是因为 GoogleAdMob 尚未接受帐户,但我使用的是 TEST ID,而且我在 12 小时前创建了该帐户,我不明白。

inner class AdItemViewHolder(val view: View) : RecyclerView.ViewHolder(view) {

    fun bind() {
        val adLoader:AdLoader = AdLoader.Builder(context, Constants.ADMOB_TEST_AD_UNIT_ID)
            .forNativeAd { nativeAd ->
                Log.i("TESt", "Ad downloaded succesfully ${nativeAd.body} , ${nativeAd.headline}")
                val styles: NativeTemplateStyle =
                    NativeTemplateStyle.Builder().withMainBackgroundColor(
                        ColorDrawable(
                            ContextCompat.getColor(
                                context,
                                R.color.gray_500
                            )
                        )
                    ).build();

                val template: TemplateView = view.findViewById(R.id.my_template);
                template.setStyles(styles);
                template.setNativeAd(nativeAd);
            }
            .build();

        adLoader.loadAd(AdRequest.Builder().build());
    }

}

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main" >

<!--  This is your template view -->
<com.erdees.foodcostcalc.ads.TemplateView
    android:id="@+id/my_template"
    app:gnt_template_type="@layout/gnt_small_template_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

我在应用中看到空的广告布局。

您添加设备为测试设备了吗?

广告加载失败 0 表示 -> 可能是您最近才创建新的广告单元 ID 并请求实时广告。如果是这种情况,可能需要几个小时才能开始投放广告。如果您收到测试广告,那么您的实施没有问题。请等待几个小时,然后看看您是否能够收到实时广告。

Reference