72

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.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
mahim
  • 723
  • 1
  • 5
  • 4
  • 2
    Please tell, Why do you need this? Isn't it sufficient to know the first launch date? – Vladimir Ivanov Mar 15 '11 at 12:23
  • 1
    This is as per client requirements for one of the projects we are working on. – mahim Mar 17 '11 at 07:43
  • @VladimirIvanov "Please tell why you need this?" http://stackoverflow.com/questions/19764667/determine-date-or-version-that-app-was-purchased-from-google-play-store-equi – Seshu Vinay Jul 28 '15 at 10:14

6 Answers6

148

or this one (API Level 9 upwards!):

long installed = context
    .getPackageManager()
    .getPackageInfo(context.getPackag‌​eName(), 0)
    .firstInstallTime
;
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
Martin Matysiak
  • 3,356
  • 2
  • 17
  • 19
  • Thanks a lot for your help on the subject. – mahim Mar 17 '11 at 07:42
  • 1
    You would be able to get all the other "package info" as well via this link, http://developer.android.com/reference/android/content/pm/PackageInfo.html – fedmich Jan 09 '14 at 22:59
  • 2
    Unfortunately this date is reset when the app is uninstalled and reinstalled. – Patrick Aug 01 '14 at 17:16
  • 9
    for all the copy&paste people out there: ```javalong installDate;try { installDate = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime;} catch (PackageManager.NameNotFoundException e) { installDate = Calendar.getInstance().getTimeInMillis();}``` – Tobias Jul 26 '16 at 22:03
  • 1
    How about updating app from store? Is this update(change) the date? – helloWorld Jan 30 '17 at 12:25
  • 3
    @BogdanShulga updating will not change this date, look also to lastUpdateTime. – anber Feb 23 '17 at 14:41
  • In case of a factory reset what happens to the app. Consider its a system app or google play store. Will the install date change on factory reset? – ANAND PURUSHOTTAM Aug 17 '20 at 12:40
26

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();
Rob Hruska
  • 118,520
  • 32
  • 167
  • 192
Sunil Pandey
  • 7,042
  • 7
  • 35
  • 48
11

First Time It Was Installed

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

Last Time It Was Updated

activity.getPackageManager().getPackageInfo( activity.getPackageName(), 0 ).lastUpdateTime;
Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
8

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;
    }
}
Mojtaba Yeganeh
  • 2,788
  • 1
  • 30
  • 49
guyland123
  • 841
  • 9
  • 4
3

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());
}
Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
3
public long getInstallDateInMilliseconds() {
    long installDate;
    try {
        installDate = context.getPackageManager()
                      .getPackageInfo(context.getPackageName(),0)
                      .firstInstallTime;
    } catch (PackageManager.NameNotFoundException e) {
        installDate = Calendar.getInstance().getTimeInMillis();
    }
    return installDate;
}
Mr N
  • 25
  • 1
  • 3
  • Can you offer some explanation of your approach to help people understand your thinking? Also, why might someone take this approach over the accepted answer from a decade ago? – Jeremy Caney Jun 05 '20 at 04:21