简体   繁体   中英

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. Is it possible and how? Should I use a counter with stored variables locally or something is possible through subscriptions on play console?

I think the easiest and most direct way to do this is keeping expired date in 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.

// 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..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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