【问题标题】:Android Java: Find out if user is new to the app or if the app was previously installedAndroid Java:了解用户是否是该应用程序的新用户,或者该应用程序之前是否已安装
【发布时间】:2020-11-16 16:43:12
【问题描述】:

我想发布一款通过广告获利的免费 Android 应用。我不想在前 24 小时内展示广告,因为如果用户不喜欢该应用程序,他/她为什么要被广告打扰。如果他喜欢该应用并保留它,就会有广告或专业版。

我如何知道“现在”是否在应用使用的前 24 小时内(可以从应用安装时间或应用首次打开时间开始,这无关紧要)。我不希望用户能够只是卸载应用程序,然后重新安装它,然后突然就没有广告了。

是否存在某种不会更改且可用于在用户数据库中查找的唯一 ID(Device-ID、Firebase-ID、...)?有没有更好的方法来实现这种行为?

谢谢!

【问题讨论】:

  • 请检查副本以了解如何检查用户是否为新用户。要检查“现在”是否在前 24 小时内,请添加 Timestamp 属性。这里是Firebase Realtime Database,这里是Cloud Firestore
  • @AlexMamo 虽然您的链接可能是检测新用户的好方法,但它不是重复的。在这种情况下,我建议发布一个答案,解释如何将链接中的信息应用于此问题。

标签: java android firebase google-play google-play-console


【解决方案1】:

每个 Android 设备都有唯一的 ID。

请看这篇文章

Unique ID of Android device

【讨论】:

    【解决方案2】:

    我现在正在尝试为我自己的应用程序实现相同的功能,我将首先尝试这种方法,将第一个打开的应用程序的时间戳保存到 sharadpreferences。我打算这样做是因为我现在不想使用云数据库和设备 ID:s。唯一的缺点是,卸载应用程序时,第一个打开的应用程序的信息会消失。不过,我认为这至少对我来说不是什么大问题。

    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();
    
    }
    

    之后,我会在 showAd 函数中检查用户使用该应用的时间是否足够长。您可以使用 SimpleDateFormat 来更轻松地使用日期对象,并在您想要展示广告时计算当前时间和 userLoginTime 之间的时间。

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

    为了使这更“高效”,您可以在您选择的时间后将 adsEnabled 布尔值保存到 SharedPreferences。那么你只需要检查 adsEnabled 是否为真。

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

    -朱西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 2013-12-21
      相关资源
      最近更新 更多