0

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

4

1 回答 1

1

我认为最简单和最直接的方法是在 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...
}

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

于 2020-02-06T08:19:43.327 回答