简体   繁体   English

有没有办法找出一个应用程序安装了多长时间?

[英]Is there a way to find out how long an app is installed?

I would like to find out how long an app is already installed on a device. 我想找出一个应用程序已经在设备上安装了多长时间。

The reason : I like to announce a new update for the app for users who have installed the app longtime ago and want to prevent to announce this for users, which have just installed the app. 原因:我想为很久以前安装了该应用程序的用户宣布该应用程序的新更新,并希望防止为刚刚安装该应用程序的用户宣布此更新。 I hate myself advertising in the apps :-) so I want to be discreet and show the announcement for only users which have installed the app longtime ago. 我讨厌自己在应用程序中投放广告:-),所以我想保持谨慎,只对很久以前安装了该应用程序的用户显示公告。 (Sorry for my bad english) (对不起,我的英语不好)

what i do not want to use is this the following, because this allow me to detect this only from a newer version, where I implemented it: - using google analytics. 我不想使用的是以下内容,因为这使我只能从实施该功能的较新版本中检测到它:-使用Google Analytics(分析)。 - a counter which counts the appstarts in a property -一个计数器,用于计算属性中的appstarts

I am looking for a solution that I implement now in 2014 and detects that an app is installed since 2013. 我正在寻找一种解决方案,该解决方案将于2014年实施,并检测到自2013年以来已安装了某个应用。

any hints ? 有什么提示吗?

The easiest way to do this moving forward would be with a pair of SharedPreferences : 进行此操作最简单的方法是使用一对SharedPreferences

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(new Context());
boolean firstRun = prefs.getBoolean("IS_FIRST_RUN", true);
long now = System.currentTimeMillis();
if (firstRun)
{
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("IS_FIRST_RUN", false);
    editor.putLong("FIRST_RUN_MILLIS", now);
    editor.apply();
}
else
{
    long dateFirstRun = prefs.getLong("FIRST_RUN_MILLIS", 0L);
    if (dateFirstRun == 0L)
    {
        // no value saved. decide how you want to handle
    }
    else if (now - dateFirstRun < SOME_AGE)
    {
        // offer extra functionality
    }
}

If you want to check past installs I think you will have to play with the PackageManager 如果您想检查以前的安装,我认为您必须使用PackageManager

Edit: As Richard suggests in the comments above: 编辑:正如理查德在上面的评论中建议的那样:

try
{
    long firstInstall = context.getPackageManager().getPackageInfo("package.name", 0).firstInstallTime;
}
catch (PackageManager.NameNotFoundException e)
{
    e.printStackTrace();
}

In my experience, if the app is on Google Play, I would use some service like UrbanAirship, Parse, or raw GCM implementation with personal server to register devices and be able to send push messages to every handset. 以我的经验,如果该应用程序在Google Play上运行,我会在个人服务器上使用UrbanAirship,Parse或原始GCM实施等服务来注册设备,并能够向每部手机发送推送消息。 I wouldn't mind about the already installed apps 'cause the Play Store app on the device will announce the user about the update when available. 我不介意已经安装的应用程序,因为设备上的Play商店应用程序会在可用时向用户发布有关更新的信息。

Now, if the app is not on Google Play, but still consumes an api, you can take advantage of it and send a one-time promotional message to download the new version with the new features: 现在,如果该应用程序不在Google Play上,但仍在使用api,则可以利用它并发送一次促销信息,以下载具有新功能的新版本:

    //TODO Receive message here

    //check preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if(!prefs.getBoolean("alreadyAdvertised", false)){
        prefs.edit().putBoolean("alreadyAdvertised", true).commit();
        //TODO display message here

    }

Hope it helps. 希望能帮助到你。

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

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