Get the set date of the application on Android

Is there a way to find out the “Date the application was installed” on an Android device.

I searched a lot, but could not find the appropriate answer.

Could not find anything regarding the date the application was installed using the PackageManager documentation / code.

+58
android date install
Mar 15 '11 at 12:22
source share
5 answers

or this ( API level 9 up!):

 long installed = context .getPackageManager() .getPackageInfo(context.getPackag‌​eName(), 0) .firstInstallTime ; 
+114
Mar 15 2018-11-11T00:
source share
— -

Use this code:

 PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0); String appFile = appInfo.sourceDir; long installed = new File(appFile).lastModified(); 
+22
Mar 15 '11 at 12:41
source share

Try one of these

 /** * 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
Sep 18 '13 at
source share

First time it was installed

 activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0 ).firstInstallTime; 

Last time it was updated.

 activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0 ).lastUpdateTime; 
+3
Nov 03 '18 at 0:55
source share

This method returns the installation date in String format, for example, 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; } 

Miscutilities

 /** * Return date in specified format. * * @param milliSeconds Date in milliseconds * @param dateFormat Date format * @return String representing date in specified format * <p> * Date myDate = MiscUtilities.getDate(82233213123L, "dd/MM/yyyy hh:mm:ss.SSS"); */ public static String getDate(long milliSeconds, String dateFormat) { // Create a DateFormatter object for displaying date in specified format. SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); // Create a calendar object that will convert the date and time value in milliseconds to date. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); return formatter.format(calendar.getTime()); } 
0
Dec 19 '16 at 20:58
source share



All Articles