简体   繁体   English

如何在 Android 中显示 AdMob 非个性化原生高级广告?

[英]How to show AdMob Non-Personalized Native Advanced ads in Android?

I tried various different methods but none of them seem to work.我尝试了各种不同的方法,但似乎都没有奏效。 This is given by AdMob:这是由 AdMob 给出的:

Bundle extras = new Bundle();
extras.putString("npa", "1");

AdRequest request = new AdRequest.Builder()
    .addNetworkExtrasBundle(AdMobAdapter.class, extras)
    .build();

The code I use:我使用的代码:

AdLoader.Builder builder = new AdLoader.Builder(this, "ca-app-pub-XXXXX").forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
            @Override
            public void onNativeAdLoaded(@NonNull NativeAd nativeAds) {
                if (nativeAds!=null) nativeAd = nativeAds;
                CardView cardView = findViewById(R.id.adCard);
                NativeAdView adView = (NativeAdView)getLayoutInflater().inflate(R.layout.native_ad_view, null);
                populateNativeAd(nativeAd, adView);
                cardView.removeAllViews();
                cardView.addView(adView);
            }
        });

The ads are loaded and shown without the usage of AdRequest and I can't find a way forward consent using AdLoader广告在没有使用AdRequest的情况下加载和显示,我找不到使用 AdLoader 的方法来获得同意

If anyone else is facing the same confusion: AdRequest is used in this line:如果其他人也面临同样的困惑: AdRequest在这一行中使用:

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

My bad.我的错。 The code was too long and I was not able to find this line.代码太长,我找不到这一行。 Change it to:将其更改为:

Bundle extras = new Bundle();
extras.putString("npa", "1");
adLoader.loadAd(new AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter.class, extras).build());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM