Obtenir la date d’installation de l’application sur Android

Est-il possible de connaître la “Date à laquelle une application a été installée” sur un périphérique Android.

Avoir effectué des recherches approfondies, mais incapable de trouver une réponse pertinente.

Impossible de trouver quelque chose concernant la date à laquelle l’application a été installée via la documentation / code de PackageManager.

Merci beaucoup. Mahim.

ou celui-ci ( API niveau 9 vers le haut!):

long installed = context .getPackageManager() .getPackageInfo(context.getPackag‌​eName(), 0) .firstInstallTime ; 

Utilisez ce code:

 PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0); Ssortingng appFile = appInfo.sourceDir; long installed = new File(appFile).lastModified(); 

Essayez l’un de ces

 /** * 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); Ssortingng sAppFile = appInfo.sourceDir; return new File(sAppFile).lastModified(); } } catch (NameNotFoundException e) { //should never happen return 0; } } 

Cette méthode renvoie la date de l’installation au format Ssortingng comme 12/25/2016 10:38:02 :

  private Ssortingng getInstallDate() { // get app installation date PackageManager packageManager = getActivity().getPackageManager(); long installTimeInMilliseconds; // install time is conveniently provided in milliseconds Date installDate = null; Ssortingng installDateSsortingng = null; try { PackageInfo packageInfo = packageManager.getPackageInfo(getActivity().getPackageName(), 0); installTimeInMilliseconds = packageInfo.firstInstallTime; installDateSsortingng = 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); installDateSsortingng = installDate.toSsortingng(); } return installDateSsortingng; }