0

For some reason when i try to mute the native ad, it returns an empty dialog with no reasons for muting the native ad.

I got the code from here https://github.com/googlesamples/android-ads/blob/master/advanced/APIDemo/app/src/main/java/com/google/android/gms/example/apidemo/AdMobCustomMuteThisAdFragment.java

My code for muting native ad

private void showMuteReasonsDialog() {
        class MuteThisAdReasonWrapper {
            MuteThisAdReason reason;

            MuteThisAdReasonWrapper(MuteThisAdReason reason) {
                this.reason = reason;
            }

            @Override
            public String toString() {
                return reason.getDescription();
            }
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("Select a reason");
        final List<MuteThisAdReason> reasons = nativeAd.getMuteThisAdReasons();
        final List<MuteThisAdReasonWrapper> wrappedReasons = new ArrayList<>();
        for (MuteThisAdReason reason : reasons) {
            wrappedReasons.add(new MuteThisAdReasonWrapper(reason));
        }

        builder.setAdapter(
                new ArrayAdapter<>(MainActivity.this,
                        android.R.layout.simple_list_item_1, wrappedReasons),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        muteAdDialogDidSelectReason(wrappedReasons.get(which).reason);
                    }
                });

        builder.show();
    }



private void muteAdDialogDidSelectReason(MuteThisAdReason reason) {
        // Report the mute action and reason to the ad.
        // The ad is actually muted (removed from UI) in the MuteThisAdListener callback.
        nativeAd.muteThisAd(reason);
    }

private void muteAd() {
        // Disable mute button, remove ad.
        mCloseAd.setEnabled(false);
        mNativeAdContainer.removeAllViews();
    }

Requesting mute

 NativeAdOptions adOptions = new NativeAdOptions.Builder()
                .setVideoOptions(videoOptions)
                .setRequestCustomMuteThisAd(true)
                .build();

EDIT

unifiedNativeAd.isCustomMuteThisAdEnabled() returns false even though i enabled it in NativeAdOptions?

Is this because im using test ads ?

Vince VD
  • 1,506
  • 17
  • 38

1 Answers1

0

Check once, If you are building the adloader after you set it to True . For example something like this.

adLoader = new AdLoader.Builder(context, "ad unit ID").withNativeAdOptions(new NativeAdOptions.Builder()
                         .setRequestCustomMuteThisAd(true)
                         .build()).build();
    adLoader.loadAd(new AdRequest.Builder().build());
redhatvicky
  • 1,912
  • 9
  • 8