简体   繁体   English

如何获取最新安装的android版本的日期?

[英]How to get the date of latest installed android version?

I want to get the date and time (isn't that important) when the user installed his latest android version on the smartphone. 当用户在智能手机上安装了最新的android版本时,我想获取日期和时间(不是那么重要)。 I searched in google and looked after in the Android Reference, but didn'f find anything like that. 我在google中搜索并在Android参考中找到了内容,但没有找到类似的东西。

My first thought was the class android.os.BUILD but there is nothing. 我首先想到的是android.os.BUILD类,但没有任何东西。

android.od.BUILD.Time is just the date when the Build was compiled. android.od.BUILD.Time只是编译Build的日期。

Thanks for your help! 谢谢你的帮助!

private void getAppInstallTime(){
PackageManager pm = getApplicationContext().getPackageManager();
        try {
           PackageInfo info = pm.getPackageInfo("com.example.sample", 0);
            Field field = PackageInfo.class.getField("firstInstallTime");
            long timestamp = field.getLong(info);
            Date date = new Date(timestamp);
            Log.e("DATE", date + "InMillies "+timestamp);
            ApplicationInfo appInfo = pm.getApplicationInfo("com.example.sample", 0);
   String appFile = appInfo.sourceDir;
   long installed = new File(appFile).lastModified();
   Date dateMod = new Date(installed);
   Log.e("Updates","Updated Time"+dateMod+"  time in millies"+installed);
       } catch (NameNotFoundException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
       } catch (SecurityException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
       } catch (IllegalArgumentException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
       } catch (NoSuchFieldException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
       } catch (IllegalAccessException e1) {
           // TODO Auto-generated catch block
           e1.printStackTrace();
       }
 }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM