Я пытаюсь разработать приложение Android на Java, мне нужно получить метку времени для последней версии приложения из моей программы, вот мой код:
String getTimeStamp()
{
// Get the path to the apk container.
String apkPath = context.getApplicationInfo().sourceDir, timeStamp = "";
JarFile containerJar = null;
long lastModifiedDate = 0;
Date date;
try
{
PathClassLoader obj = (PathClassLoader) context.getClassLoader();
containerJar = new JarFile(apkPath); // Open the apk container as a jar..
ZipEntry ze = containerJar.getEntry("classes.dex"); // Look for the "classes.dex" entry inside the container.
if (ze != null) // If this entry is present in the jar container
{
FileTime fileTime = ze.getLastModifiedTime();
if (!fileTime.toString().startsWith("1981-01-01"))
{
long time = fileTime.toMillis();
if (time > lastModifiedDate)
{
lastModifiedDate = time;
date=new Date(lastModifiedDate);
timeStamp = date.toString();
}
}
}
}
catch (IOException e) { e.printStackTrace(); }
finally
{
if (containerJar != null)
try { containerJar.close(); }
catch (IOException e) { e.printStackTrace(); }
}
return timeStamp;
}
Когда приложение запускается из Android Studio, оно возвращает "", но когда оно запускается на моем телефоне, оно возвращает "1979-11-30", почему? Как получить последний раз, когда файл был изменен?