如何解决Admob错误,无法加载广告0

时间:2019-06-13 19:24:01

标签: android admob

我已经在自己的app中实施了Admob,并且可以很好地与测试广告一起使用。 我正在将广告加载到供稿列表中,并出现错误“加载广告失败:0” 。根据Stack Overflow的答案,此错误主要与新创建的广告单元有关,但已经超过15天,但出现了相同的错误。奖励视频广告单元运行正常时。 Admob帐户也具有批准状态。在Google Admob Community中问了同样的问题,但没有答案。

请勿将其复制为this question,因为接受的答案表示要等待,但就我而言,我正在等待最后15天。

这是代码段。

private void showNativeGoogleAd(UnifiedNativeAdViewHolder holder)
{
    AdLoader adLoader = new AdLoader.Builder(mContext, mContext.getString(R.string.admob_social_wall_ad_unit_id))
    //AdLoader adLoader = new AdLoader.Builder(mContext, "ca-app-pub-3940256099942544/1044960115")
            .forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
                @Override
                public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
                    // Show the ad.
                    populateNativeAdView(unifiedNativeAd, holder.adView);
                    //holder.fl_adplaceholder.removeAllViews();
                    //holder.fl_adplaceholder.addView(holder.adView);
                }
            })
            .withAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int errorCode) {
                    // Handle the failure by logging, altering the UI, and so on.
                    Log.d("TAG", "onAdFailedToLoad: Google => "+errorCode);
                }
            })
            .withNativeAdOptions(new NativeAdOptions.Builder()
                    // Methods in the NativeAdOptions.Builder class can be
                    // used here to specify individual options settings.
                    .build())
            .build();

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

private void populateNativeAdView(UnifiedNativeAd nativeAd,
                                  UnifiedNativeAdView adView) {
    // Some assets are guaranteed to be in every UnifiedNativeAd.
    ((TextView) adView.getHeadlineView()).setText(nativeAd.getHeadline());
    ((TextView) adView.getBodyView()).setText(nativeAd.getBody());
    ((Button) adView.getCallToActionView()).setText(nativeAd.getCallToAction());

    // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to
    // check before trying to display them.
    com.google.android.gms.ads.formats.NativeAd.Image icon = nativeAd.getIcon();

    if (icon == null) {
        adView.getIconView().setVisibility(View.INVISIBLE);
    } else {
        ((ImageView) adView.getIconView()).setImageDrawable(icon.getDrawable());
        adView.getIconView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getPrice() == null) {
        adView.getPriceView().setVisibility(View.INVISIBLE);
    } else {
        adView.getPriceView().setVisibility(View.VISIBLE);
        ((TextView) adView.getPriceView()).setText(nativeAd.getPrice());
    }

    if (nativeAd.getStore() == null) {
        adView.getStoreView().setVisibility(View.INVISIBLE);
    } else {
        adView.getStoreView().setVisibility(View.VISIBLE);
        ((TextView) adView.getStoreView()).setText(nativeAd.getStore());
    }

    if (nativeAd.getStarRating() == null) {
        adView.getStarRatingView().setVisibility(View.INVISIBLE);
    } else {
        ((RatingBar) adView.getStarRatingView())
                .setRating(nativeAd.getStarRating().floatValue());
        adView.getStarRatingView().setVisibility(View.VISIBLE);
    }

    if (nativeAd.getAdvertiser() == null) {
        adView.getAdvertiserView().setVisibility(View.INVISIBLE);
    } else {
        ((TextView) adView.getAdvertiserView()).setText(nativeAd.getAdvertiser());
        adView.getAdvertiserView().setVisibility(View.VISIBLE);
    }

    // Assign native ad object to the native view.
    adView.setNativeAd(nativeAd);
}

0 个答案:

没有答案