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

Issue

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

Solution

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

Answered By – neel3sh

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published