【发布时间】:2019-09-16 12:18:26
【问题描述】:
由于某种原因,当我尝试将原生广告静音时,它会返回一个空对话框,并且没有理由将原生广告静音。
我的原生广告静音代码
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 中启用了它?
这是因为我在使用测试广告吗?
【问题讨论】:
标签: java android admob ads native-ads