Android Java:查找用户是否是该应用的新用户,或者该应用以前是否已安装。

huangapple 未分类评论61阅读模式
英文:

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

问题

我想发布一个免费的Android应用,通过广告实现盈利。我不希望在头24小时内显示广告,因为如果用户不喜欢这个应用,为什么还要被广告打扰呢?如果他喜欢这个应用并继续使用,将会显示广告或者提供一个专业版。

我应该如何判断“现在”是否在这头24小时内的应用使用时间之内(可以从应用安装时或首次打开应用时开始计时,这没有关系)?我不希望用户能够卸载应用,然后重新安装,突然之间就没有广告了。

是否存在一种不变且可用于在用户数据库中查找的唯一标识(设备ID,Firebase ID等)?有没有更好的方法来实现这种行为?

谢谢!

英文:

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!

答案1

得分: 0

这里为每台Android设备都有唯一的标识符。

请查看此帖子:

https://stackoverflow.com/questions/4468248/unique-id-of-android-device

英文:

There is unique id for every Android device.

Please check this post

https://stackoverflow.com/questions/4468248/unique-id-of-android-device

答案2

得分: 0

我正在尝试为我的应用程序实现相同的功能,现在首先要尝试这种方法,其中我会将第一个打开的应用程序的时间戳保存到共享首选项中。我会这样做,因为我现在不想使用云数据库和设备ID。唯一的缺点是,当应用程序被卸载时,第一个打开的应用程序的信息将会消失。然而,我认为这对我来说可能不是很大的问题。

SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean userLoginTime = sharedPreferences.contains(getString(R.string.userLoginTime));
if (!userLoginTime){
   //如果字段userLoginTime缺失,则将当前时间保存到SharedPreferences中
   SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
   Date currentTime = Calendar.getInstance().getTime();
   String stringCurrentTime = sdf.format(currentTime);//解析需要try和catch。这些只是为了传达思想
   sharedPreferences.edit().putString(getString(R.string.userLoginTime), stringCurrentTime).apply();
}

在此之后,我会在showAd函数中检查用户是否已经使用应用程序足够长的时间。您可以使用SimpleDateFormat更轻松地处理日期对象,并在要显示广告时计算当前时间和userLoginTime之间的时间差。

//两个日期对象之间的时间差。单位为毫秒
Long diff = userLoginTime.getTime() - currentTime.getTime();

为了使这更加"高效",您可以在选择的时间后将adsEnabled布尔值保存到SharedPreferences中。然后,您只需检查adsEnabled是否为真。

我知道这在用户删除并重新安装应用程序时会消失,但我认为很少有用户会真正这样做。正如您提到的,如果他们喜欢这个应用程序,他们不会介意广告(如果广告摆放得巧妙的话)。此外,在我看来,这种方法更容易实现,并且几乎可以满足您的所有需求,所以值得一试。

-Jussi

英文:

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

huangapple
  • 本文由 发表于 2020年7月27日 18:55:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/63113840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定