当用户在智能手机上安装了他最新的Android版本时,我希望得到日期和时间(并不重要)。 我在谷歌搜索并在Android参考资料中照看,但没有找到类似的东西。
我的第一个想法是班级android.os.BUILD
,但没有任何内容。
android.od.BUILD.Time
只是Build编译的日期。
感谢您的帮助!
答案 0 :(得分:0)
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();
}
}
}