我正在开发一个Android应用程序,我想显示.apk现在的版本和日期我能够显示应用程序的应用程序版本,PackageInfo现在我想显示创建应用程序的日期或.apk创建日期.
对于新读者:
public static String getAppTimeStamp(Context context) {
String timeStamp = "";
try {
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0);
String appFile = appInfo.sourceDir;
long time = new File(appFile).lastModified();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
timeStamp = formatter.format(time);
} catch (Exception e) {
}
return timeStamp;
}
Run Code Online (Sandbox Code Playgroud)
检查classes.dex的最后修改日期的方法,这意味着上次构建应用程序代码的时间:
try{
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0);
ZipFile zf = new ZipFile(ai.sourceDir);
ZipEntry ze = zf.getEntry("classes.dex");
long time = ze.getTime();
String s = SimpleDateFormat.getInstance().format(new java.util.Date(time));
}catch(Exception e){
}
Run Code Online (Sandbox Code Playgroud)