【问题标题】:app installation time not being detected correctly upon reinstallation from android studio从 android studio 重新安装后,无法正确检测到应用程序安装时间
【发布时间】:2018-05-09 08:54:59
【问题描述】:

我正在使用下面的代码来获取我的应用程序的安装时间

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

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

如果我在更改一些源代码后重新安装 apk - 通过 android studio - installTime 不会更新。但是,如果我从我的设备中手动卸载应用程序。新的 installTime 下次会正确显示。

如何编写代码来检测android studio重新安装的apk文件的安装时间?

【问题讨论】:

    标签: android android-studio installation


    【解决方案1】:

    问题不在您的代码中。您需要了解,当您从 android studio 重新运行或停止/启动 android 应用程序时,它不会将应用程序卸载/重新安装到手机。相反,它将更改的类/资源复制到手机上的安装目录。所以apk文件的修改时间不会更新。

    您可以先尝试卸载应用程序,然后从 android studio 重新运行应用程序。或者,如果您不想每次都在手机上卸载应用程序时遇到麻烦,您可以将 IDE 配置为在重新运行之前卸载应用程序。这里有描述:Android Studio : How to uninstall APK (or execute adb command) automatically before Run or Debug?

    【讨论】:

    • Rather it copies changed classes/resources to installation directory on phone - 如何从 java 代码中检测到这一点?
    猜你喜欢
    • 2016-06-07
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    相关资源
    最近更新 更多