我正在努力在我的应用程序中实施 adMob 我正在使用测试广告原生 ID 以查看工作是否正常我一直遇到此错误:
<块引用>广告加载失败: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 :(得分:1)
您是否已将该设备添加为测试设备?
广告加载失败 0 表示 -> 可能是您最近才创建了一个新的广告单元 ID 并请求实时广告。如果是这种情况,广告可能需要几个小时才能开始投放。如果您收到的是测试广告,那么您的实施就没有问题。只需等待几个小时,然后看看您是否能够收到实时广告。