Получить версию из текущего JAD Apps:
String currentVersion = ApplicationDescriptor.currentApplicationDescriptor().getVersion();
Получить версию из загруженного JAD в виде строки:
public static String getJADProperty(String jadString, String propKey) {
int indexFrom = jadString.indexOf(propKey) + propKey.length();
// Value reaches until line break (Unix vs. Win)
int indexTo = jadString.indexOf("\r", indexFrom);
if (indexTo == -1) { indexTo = jadString.indexOf("\n", indexFrom); }
return jadString.substring(indexFrom, indexTo).trim();
}
Сравнить строки версии:
/**
* Compares two version strings that are in the format 1.1.1
*
* @param current Version String in the format 1.1.1 (current version of the app)
* @param remote Version String in the format 1.1.1 (remote version of the app)
*
* @return true if the remote version is newer
*/
public static boolean compareVersionStrings(String current, String remote) {
int lastIndexCurrent = 0;
int indexCurrent = 0;
int lastIndexRemote = 0;
int indexRemote = 0;
String currentVersionSubstring = "";
String remoteVersionSubstring = "";
do {
lastIndexCurrent = indexCurrent + currentVersionSubstring.length();
indexCurrent = current.indexOf(".", lastIndexCurrent);
lastIndexRemote = indexRemote + remoteVersionSubstring.length();
indexRemote = remote.indexOf(".", lastIndexRemote);
// Needed because there is no "." at the last number of the version string
if (indexCurrent != -1) {
currentVersionSubstring = current.substring(lastIndexCurrent, indexCurrent);
} else {
currentVersionSubstring = current.substring(lastIndexCurrent);
}
if (indexRemote != -1) {
remoteVersionSubstring = remote.substring(lastIndexRemote, indexRemote);
} else {
remoteVersionSubstring = remote.substring(lastIndexRemote);
}
if (Integer.parseInt(currentVersionSubstring) < Integer.parseInt(remoteVersionSubstring)) {
return true;
}
} while (indexCurrent != -1);
// 1.0 < 1.0.1
if (indexRemote != -1) {
return true;
}
return false;
}
Любые исправления и улучшения приветствуются.Не стесняйтесь редактировать и делиться своим опытом со мной.