简体   繁体   中英

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:

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

If anyone else is facing the same confusion: AdRequest is used in this line:

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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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