Pobierz datę instalacji aplikacji na Androida

Czy istnieje sposób, aby dowiedzieć się "data, kiedy aplikacja została zainstalowana" na urządzeniu z Androidem.

Szukali intensywnie, ale nie mogli znaleźć odpowiedniej odpowiedzi.

Nie udało się znaleźć niczego odnośnie daty instalacji aplikacji za pomocą dokumentacji/kodu Packagemanagera.

Wielkie dzięki. Mahim.

Author: mahim, 2011-03-15

4 answers

Lub ten (API poziom 9 w górę!):

long installed = context
    .getPackageManager()
    .getPackageInfo(context.getPackag‌​eName(), 0)
    .firstInstallTime
;
 106
Author: Martin Matysiak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-02 16:34:13

Użyj tego kodu:

PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();
 22
Author: Sunil Pandey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-20 14:09:24

Spróbuj jednego z tych

/**
 * The time at which the app was first installed. Units are as per currentTimeMillis().
 * @param context
 * @return
 */
public static long getAppFirstInstallTime(Context context){
    PackageInfo packageInfo;
    try {
    if(Build.VERSION.SDK_INT>8/*Build.VERSION_CODES.FROYO*/ ){
        packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
        return packageInfo.firstInstallTime;
    }else{
        //firstinstalltime unsupported return last update time not first install time
        ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
        String sAppFile = appInfo.sourceDir;
        return new File(sAppFile).lastModified();
    }
    } catch (NameNotFoundException e) {
    //should never happen
    return 0;
    }
}
 7
Author: guyland123,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-04-27 22:51:07

Ta metoda zwraca datę instalacji w formacie String jak 12/25/2016 10:38:02:

  private String getInstallDate() {
        // get app installation date

        PackageManager packageManager =  getActivity().getPackageManager();
        long installTimeInMilliseconds; // install time is conveniently provided in milliseconds

        Date installDate = null;
        String installDateString = null;

        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getActivity().getPackageName(), 0);
            installTimeInMilliseconds = packageInfo.firstInstallTime;
            installDateString  = MiscUtilities.getDate(installTimeInMilliseconds, "MM/dd/yyyy hh:mm:ss");
        }
        catch (PackageManager.NameNotFoundException e) {
            // an error occurred, so display the Unix epoch
            installDate = new Date(0);
            installDateString = installDate.toString();
        }

        return installDateString;
    }
 -1
Author: Al Lelopath,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-19 20:58:32