当用户在智能手机上安装他最新的 android 版本时,我想获取日期和时间(不是那么重要)。我在 google 中搜索并在 Android Reference 中进行了查找,但没有找到类似的内容。
我的第一个想法是上课android.os.BUILD
,但什么都没有。
android.od.BUILD.Time
只是编译构建的日期。
谢谢你的帮助!
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();
}
}
}