Reputation: 733
Is there are way to find out the "Date when an application was installed" on an Android Device.
Have searched extensively, but unable to find relevant answer.
Was unable to find anything regarding Date when Application was Installed through PackageManager
documentation/Code.
Upvotes: 73
Views: 49130
Reputation: 1
Go to file manager, then open folder named "Android" and search for apps name is "data" or "obb" folder. The date and time folder was created is the installation date. Tip - some folders have the name of apps creator instead the name of app.
Upvotes: 0
Reputation: 25
public long getInstallDateInMilliseconds() {
long installDate;
try {
installDate = context.getPackageManager()
.getPackageInfo(context.getPackageName(),0)
.firstInstallTime;
} catch (PackageManager.NameNotFoundException e) {
installDate = Calendar.getInstance().getTimeInMillis();
}
return installDate;
}
Upvotes: 3
Reputation: 6778
This method returns the date of the install in String format like 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());
}
Upvotes: 3
Reputation: 47581
activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0 ).firstInstallTime;
activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0 ).lastUpdateTime;
Upvotes: 12
Reputation: 3396
or this one (API Level 9 upwards!):
long installed = context
.getPackageManager()
.getPackageInfo(context.getPackageName(), 0)
.firstInstallTime
;
Upvotes: 151
Reputation: 841
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;
}
}
Upvotes: 8
Reputation: 7102
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();
Upvotes: 26