1

我有一个黑莓应用程序。它是从提供动态 JAD 文件内容的网页下载的。JSP 打印那些:

out.println("Appid: " + appid);
out.println("Ip: " + user.getIp());
out.println("Servicename: " + service);
out.println("MIDlet-Version: 1.0.0");
out.println("MIDlet-Jar-URL: MyApp.jar");
out.println("MIDlet-Jar-Size: 91633");
out.println("MicroEdition-Profile: MIDP-2.0");
     (and other attributes goes on like that..)

我需要获取我的自定义属性,例如“Appid”,但它有时会获取空值。用户可以下载并运行该应用程序,但其中一些无法获取我的自定义属性。我不知道这与手机型号或操作系统的当前状态有关,但根据我的日志,这个问题主要出现在这些设备上:

9800 操作系统 6.0.0.546

9300 操作系统 6.0.0.570

9300 操作系统 6.0.0.668

9320 操作系统 7.1.0.398

我获取属性的代码:

    CodeModuleGroup cmg = null;
    CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll();
    String moduleName = ApplicationDescriptor
            .currentApplicationDescriptor().getModuleName();

    for (int i = 0; i < allGroups.length; i++) {
        if (allGroups[i].containsModule(moduleName)) {
            cmg = allGroups[i];
            break;
        }
    }

    if (cmg != null) {

        AppData.firstPageURL = cmg.getProperty("Firstpage");

        AppData.appId = cmg.getProperty("Appid");
        AppData.firstIp = cmg.getProperty("Ip");
        AppData.firstSubServiceName = cmg.getProperty("Servicename");

        for (Enumeration e = cmg.getPropertyNames(); e.hasMoreElements();) {

            String name = (String) e.nextElement();
            String value = cmg.getProperty(name);
            AppData.errorStep += "-" + name + ":" + value + "-";
        }
    }

顺便说一句,我确定上面 for 循环中的代码在这些情况下永远不会运行。

任何想法 ?

4

1 回答 1

0

有时,ApplicationDescriptor.currentApplicationDescriptor().getModuleName()给出同级 cod 文件的名称而不是主 cod 文件的名称。因此,如果您的模块名称是MyApp,该函数可能会返回MyApp-1

要解决此问题,您必须去掉连字符后的数字。

String moduleName = ApplicationDescriptor.currentApplicationDescriptor()
         .getModuleName();
if(moduleName.indexOf('-') > 0) {
    moduleName = moduleName.substring(0, moduleName.indexOf('-');
}
于 2013-06-09T06:58:35.307 回答