[英]After Watching Rewarded Video, how to stop showing all ads in the android app for 1 day?
I am trying to implement stop showing all ads in my android app for 1 day when a user watches rewarded video.当用户观看奖励视频时,我试图在 1 天内停止在我的 android 应用中显示所有广告。 Is it possible and how?
有可能吗? Should I use a counter with stored variables locally or something is possible through subscriptions on play console?
我应该在本地使用带有存储变量的计数器还是可以通过 Play 控制台上的订阅来实现?
I think the easiest and most direct way to do this is keeping expired date in SharedPreferences :我认为最简单和最直接的方法是在 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();
then check that if expire date is 24 hours old then continue else show the error notification.然后检查过期日期是否为 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...
}
i have not tested this code but it should work..我还没有测试过这段代码,但它应该可以工作..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.