1

I'd like to publish a free Android app which is monetized by ads. I do not want to show ads within the first 24 hours, because if the user doesn't like the app, why should he/she be bothered by ads. If he likes the app and keeps it, there will be ads or a pro-version.

How could I find out if "now" is within those first 24 hours of app usage (could start from the time the app was installed or the time the app was first opened, that doesn't matter). I don't want the user to be able to just uninstall the app, then reinstall it and suddenly there are no ads anymore.

Is there some kind of a unique ID that does not change and that can be used to be looked up in a user database (Device-ID, Firebase-ID, ...)? Is there any better way to achieve this behavior?

Thank you!

  • Please check the duplicate to see how you can check if a user is new. And to check if "now" is within those first 24 hours, add a Timestamp property. Here is for [Firebase Realtime Database](https://stackoverflow.com/questions/43584244/how-to-save-the-current-date-time-when-i-add-new-value-to-firebase-realtime-data) and here is for [Cloud Firestore](https://stackoverflow.com/questions/48474957/servertimestamp-is-allways-null-on-firebase-firestore/48475027). – Alex Mamo Jul 27 '20 at 11:02
  • 1
    @AlexMamo While your links may be a good approach to detect new users, it is not a duplicate. I'd in cases like this recommend posting an answer explaining how you'd apply the information in the links to this problem. – Frank van Puffelen Jul 27 '20 at 14:40

2 Answers2

0

There is unique id for every Android device.

Please check this post

Unique ID of Android device

Ragesh
  • 205
  • 3
  • 11
0

I'm trying to implement the same feature for my own app right now, and I am going to try this approach first, where I save the timestamp of the first app opened to sharadpreferences. I'm going to do it this way because I don't want to use cloud databases and device ID:s right now. The only drawback would be, information of first app opened would disappear when app is uninstalled. However, I think that would not be very big issue for me at least.

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean userLoginTime = sharedPreferences.contains(getString(R.string.userLoginTime));
if (!userLoginTime){
   //save the current time to SharedPreferences if the field userLoginTime is missing
   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
   Date currentTime = Calendar.getInstance().getTime();
   String stringCurrentTime = dateFormat.format(currentTime);//parser need try and catch. These are only for getting the idea
   sharedPreferences.edit().putString(getString(R.string.userLoginTime),stringCurrentTime).apply();

}

and after this I would check within the showAd function that the user has used the app long enough. You can use the SimpleDateFormat for easier use of the date objects and calculate the time between current time and userLoginTime when you want to show the ad.

//time between two Date objects. Unit mils
Long diff = userLoginTime.getTime() - currentTime.getTime()

to make this more "efficient" you can save adsEnabled boolean to SharedPreferences after the time you choose. Then you only need to check if adsEnabled is true.

I know that this will disappear when user deletes and reinstalls the app, but I think that few user will actually do that. As you mentioned, if they like the app, they would not mind the ads (if the ads are cleverly placed). Moreover, in my opinion, this approach is much easier to implement and it almost do everything you want, so it would be worth of a try.

-Jussi