我开始对Google移动广告感兴趣。现在我正在测试给定测试广告的RewardedVideoAd
功能。一切正常,但我找不到如何在广告未完成时停用广告关闭的方式。
下面是我的抽象代码,显示了我如何使用RewardedVideoAd
方法:
public class TestPage extends AppCompatActivity implements RewardedVideoAdListener {
private Button button;
private final static String APP_ADMOB_ID = "[my_app_admob_id]";
private RewardedVideoAd mRewardedVideoAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_page);
MobileAds.initialize(this, APP_ADMOB_ID);
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
}
});
}
private void loadRewardedVideoAd() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
new AdRequest.Builder().build());
}
@Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "Video ad loaded",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "Video ad opened",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "Video ad started",
Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdClosed() {
loadRewardedVideoAd();
}
@Override
public void onRewarded(RewardItem rewardItem) {
Toast.makeText(this, "onRewarded! currency: " + rewardItem.getType() + " amount: " +
rewardItem.getAmount(), Toast.LENGTH_LONG).show();
}
@Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "Left app during video ad",
Toast.LENGTH_LONG).show();
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
Toast.makeText(this, "Failed to load video ad", Toast.LENGTH_LONG).show();
}
}
现在,当显示广告视频时,用户可以按后退按钮,然后出现对话框,其中包含消息: Close video?
。我想禁用此功能。
但我不知道怎么做。我尝试@Override
onBackPressed()
方法并插入if语句,如果能够执行某些操作,则使用检查布尔值。但它不起作用。
所以我的主要问题是:
在视频运行时是否有办法停止关闭广告?
感谢您提供任何帮助。
P.S。:我已阅读所有“AdMob for Android”说明,我不需要链接。