简体   繁体   English

Android Java:确定用户是否是该应用程序的新用户,或者该应用程序是否以前安装过

[英]Android Java: Find out if user is new to the app or if the app was previously installed

I'd like to publish a free Android app which is monetized by ads.我想发布一个免费的 Android 应用程序,该应用程序通过广告获利。 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.我不想在前 24 小时内展示广告,因为如果用户不喜欢该应用程序,他/她为什么要被广告打扰。 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).我怎样才能知道“现在”是否在应用程序使用的前 24 小时内(可以从应用程序安装时间或应用程序首次打开时间开始,没关系)。 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, ...)?是否存在某种不会更改且可用于在用户数据库中查找的唯一 ID(Device-ID、Firebase-ID、...)? Is there any better way to achieve this behavior?有没有更好的方法来实现这种行为?

Thank you!谢谢!

There is unique id for every Android device.每个 Android 设备都有唯一的 ID。

Please check this post请检查这个帖子

Unique ID of Android device Android设备的唯一ID

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.我现在正在尝试为我自己的应用程序实现相同的功能,我将首先尝试这种方法,将第一个打开的应用程序的时间戳保存到 sharadpreferences。 I'm going to do it this way because I don't want to use cloud databases and device ID:s right now.我打算这样做是因为我现在不想使用云数据库和设备 ID:s。 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.在此之后,我会在 showAd function 中检查用户使用该应用程序的时间是否足够长。 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.您可以使用 SimpleDateFormat 来更轻松地使用日期对象,并在您想要展示广告时计算当前时间和 userLoginTime 之间的时间。

//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.为了使这更“高效”,您可以在您选择的时间后将 adsEnabled boolean 保存到 SharedPreferences 中。 Then you only need to check if adsEnabled is true.然后你只需要检查 adsEnabled 是否为真。

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 -尤西

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

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