BlackBerry:如何读取 JAD 并提取版本号

发布于 2024-12-18 12:34:11 字数 192 浏览 3 评论 0原文

我知道该方法

ApplicationDescriptor.currentApplicationDescriptor();

,但我的目标是下载另一个 JAD 并将其版本号与当前应用程序版本进行比较。最好/最简单的方法是什么?有没有办法从一个简单的字符串构造一个ApplicationDescriptor?

I know the method

ApplicationDescriptor.currentApplicationDescriptor();

But I aim to download another JAD and compare it's version number to the current applications version. What is the best/easiest way to do this? Is there a way to construct an ApplicationDescriptor from a simple String?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

無處可尋 2024-12-25 12:34:11

从当前应用程序 JAD 获取版本:

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;
}

感谢任何更正和改进。请随意编辑并与我分享您的经验。

Get the version from the current Apps JAD:

String currentVersion = ApplicationDescriptor.currentApplicationDescriptor().getVersion();

Get the version from a downloaded JAD as String:

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();
}

Compare the version strings:

/**
 * 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;
}

Any corrections and improvements are appreciated. Feel free to edit and share your experiences with me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文