2

I am using below code to obtain the installation time of my app

    PackageManager p = this.getPackageManager();
    ApplicationInfo apinf = null;

    apinf = p.getApplicationInfo(this.getPackageName(), 0);
    String apkFile = apinf.sourceDir;
    installTime = new File(apkFile).lastModified();

If I reinstall apk after making some source code changes - via android studio - the installTime is not updated. If however, I manually uninstall app from my device. the new installTime is correctly shown next time.

How do I write code to detect installation time of apk file that is reinstalled by android studio?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
xxx374562
  • 226
  • 1
  • 8

1 Answers1

1

The problem is not in your code. You need to understand that when you re-run or stop/start the android application from android studio, it does not uninstall/re-install the application to phone. Rather it copies changed classes/resources to installation directory on phone. So the modified time of apk file is not updated.

You can try to uninstall the application first, and then re-run the application from android studio. Or if you don't want to get into trouble of uninstalling the application from phone every-time, you can configure your IDE to uninstall the application before re-running. It is described here: Android Studio : How to uninstall APK (or execute adb command) automatically before Run or Debug?

Aqeel Ashiq
  • 1,988
  • 5
  • 24
  • 57
  • `Rather it copies changed classes/resources to installation directory on phone` - how to detect this from java code? – xxx374562 May 10 '18 at 02:30