我正在实施谷歌提供的原生广告代码。这对google
广告单元ID ADMOB_AD_UNIT_ID =" ca-app-pub-3940256099942544/2247696110"
但是当我用我的ID替换它没有显示广告并执行onAdFailedToLoad
方法并且无法加载原生广告:0错误。
I tried two different ad unit id but it didn't load ad.
so what should I do??please help me
我试过下面的代码
final LayoutInflater li = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
AdLoader.Builder builder = new AdLoader.Builder(appContext, Global.ADMOB_AD_UNIT_ID);
builder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
@Override
public void onContentAdLoaded(NativeContentAd ad) {
//viewHolder.rlnativead.setVisibility(View.VISIBLE);
NativeContentAdView adView = (NativeContentAdView)li
.inflate(R.layout.ad_content, null);
populateContentAdView(ad, adView);
viewHolder.fl_adplaceholder.removeAllViews();
viewHolder.fl_adplaceholder.addView(adView);
}
});
AdLoader adLoader = builder.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int errorCode) {
// Toast.makeText(appContext, "Failed to load native ad: "
// + errorCode, Toast.LENGTH_SHORT).show();
Log.e("Call List adapter","Failed to load native ad: "+errorCode);
}
}).build();
adLoader.loadAd(new AdRequest.Builder().build());
答案 0 :(得分:0)
请添加至少一个测试设备并尝试,可能会对您有所帮助,
AdRequest adRequest = new AdRequest.Builder() .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID") .build();
答案 1 :(得分:0)
这可能是最近的答案,但期望帮助其他有类似问题的人。其中一个主要原因是尺寸不正确
在我的案例之前
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.NativeExpressAdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="@string/native_ad_id"
ads:adSize="320x250"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto">
</com.google.android.gms.ads.NativeExpressAdView>
我在给出adSize时犯了错误,所以我只是用下面的尺寸更改了添加尺寸并得到修复。感谢。
ads:adSize="320x250"