在Android上获取应用程序安装date
有没有办法findAndroid设备上的“安装应用程序的date”。
已经广泛search,但无法find相关的答案。
在通过PackageManager文档/代码安装应用程序时,无法find关于date的任何信息。
非常感谢。 马希姆。
或者这个( API级别9以上!):
long installed = context .getPackageManager() .getPackageInfo(context.getPackageName(), 0) .firstInstallTime ;
使用此代码:
PackageManager pm = context.getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0); String appFile = appInfo.sourceDir; long installed = new File(appFile).lastModified();
尝试其中之一
/** * 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; } }
此方法返回string格式的安装date如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; }
- 如何从adb中删除一个应用程序而不知道它的包名
- Android-错误:任务执行失败':app:transformClassesWithDexForRelease'
- Android / Java – 简单的文本发布到Facebook墙?
- managedQuery()vs context.getContentResolver.query()vs android.provider.something.query()
- Firebase onTokenRefresh()未被调用
- 在Android中调用另一个Activity
- 如何在Android中绘制时设置线的宽度?
- 在Android Studio中导入Facebook库:无法find属性“ANDROID_BUILD_SDK_VERSION”
- 为首选项创build自定义布局