繁体   English   中英

观看奖励视频后,如何在 1 天内停止显示 android 应用中的所有广告?

[英]After Watching Rewarded Video, how to stop showing all ads in the android app for 1 day?

当用户观看奖励视频时,我试图在 1 天内停止在我的 android 应用中显示所有广告。 有可能吗? 我应该在本地使用带有存储变量的计数器还是可以通过 Play 控制台上的订阅来实现?

我认为最简单和最直接的方法是在 SharedPreferences 中保留过期日期:

// use this code on onRewarded function to store the datetime when user completed his AD.
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putLong("ExpiredDate", new Date().getTime());
editor.apply();

然后检查过期日期是否为 24 小时,然后继续否则显示错误通知。

// use this code to check before showing AD
SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
long startDateValue = sharedpreferences.getLong("ExpiredDate");
long endDateValue = new Date().getTime();
long diff = startDateValue - endDateValue;
long seconds = diff / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
if(hours < 24){
//show error that you have completed only "+ hours +" till now, wait more to see next ad.
} else {
    SharedPreferences.Editor editor = sharedpreferences.edit();
    editor.remove("ExpiredDate");
    editor.apply();
// show ads now...
}

我还没有测试过这段代码,但它应该可以工作..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM