Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In API level 9 (Gingerbread) and above, there's the <a href="http://developer.android.com/reference/android/content/pm/PackageInfo.html#firstInstallTime">PackageInfo.firstInstallTime</a> field, holding milliseconds since the epoch:</p> <pre><code>packageManager.getPackageInfo(packageName, 0).firstInstallTime; </code></pre> <p>I have the following code to use it if available, and fall back to the apk modification time:</p> <pre><code>// return install time from package manager, or apk file modification time, // or null if not found public Date getInstallTime( PackageManager packageManager, String packageName) { return firstNonNull( installTimeFromPackageManager(packageManager, packageName), apkUpdateTime(packageManager, packageName)); } private Date apkUpdateTime( PackageManager packageManager, String packageName) { try { ApplicationInfo info = packageManager.getApplicationInfo(packageName, 0); File apkFile = new File(info.sourceDir); return apkFile.exists() ? new Date(apkFile.lastModified()) : null; } catch (NameNotFoundException e) { return null; // package not found } } private Date installTimeFromPackageManager( PackageManager packageManager, String packageName) { // API level 9 and above have the "firstInstallTime" field. // Check for it with reflection and return if present. try { PackageInfo info = packageManager.getPackageInfo(packageName, 0); Field field = PackageInfo.class.getField("firstInstallTime"); long timestamp = field.getLong(info); return new Date(timestamp); } catch (NameNotFoundException e) { return null; // package not found } catch (IllegalAccessException e) { } catch (NoSuchFieldException e) { } catch (IllegalArgumentException e) { } catch (SecurityException e) { } // field wasn't found return null; } private Date firstNonNull(Date... dates) { for (Date date : dates) if (date != null) return date; return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload