gpt4 book ai didi

java - 原生广告静音不显示的原因?

转载 作者:行者123 更新时间:2023-12-02 00:38:43 25 4
gpt4 key购买 nike

出于某种原因,当我尝试将原生广告静音时,它会返回一个空对话框,没有任何理由将原生广告静音。

我从这里得到了代码https://github.com/googlesamples/android-ads/blob/master/advanced/APIDemo/app/src/main/java/com/google/android/gms/example/apidemo/AdMobCustomMuteThisAdFragment.java

我的用于静音原生广告的代码

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

请求静音

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

编辑

unifiedNativeAd.isCustomMuteThisAdEnabled() 返回 false,即使我在 NativeAdOptions 中启用它?

这是因为我正在使用测试广告吗?

最佳答案

检查一次,如果您在将其设置为 True 后正在构建广告加载器。例如这样的事情。

adLoader = new AdLoader.Builder(context, "ad unit ID").withNativeAdOptions(new NativeAdOptions.Builder()
.setRequestCustomMuteThisAd(true)
.build()).build();
adLoader.loadAd(new AdRequest.Builder().build());

关于java - 原生广告静音不显示的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57956777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com