以编程方式重新启动黑莓

发布于 2024-12-08 20:42:50 字数 1686 浏览 0 评论 0原文

我想制作可以自行重新启动黑莓的黑莓应用程序(在完成某些任务后),

例如,我使用虚拟

dummy : 制作这个小应用程序(在它变成 dummy.cod 后,我将其移动到 res 文件夹并将其重命名为 dummy,不再使用 .cod)

public class Dummy extends Application{  

    public static void main( String[] args ) {  
        new Dummy().enterEventDispatcher();  
    }

    public Dummy(){
    }
}    

应用程序示例代码: (我的应用程序的描述:只有 1 个按钮来调用重置方法)

public void reset() throws Exception {
    // load the dummy cod file
    byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));

            // create new module
    int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length); 

    // install the module
    if (newHandle != 0) {
        int savecode = CodeModuleManager.saveNewModule(newHandle, true);
        if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
            Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
        // now run the dummy application in background
        ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
        ApplicationManager.getApplicationManager().runApplication(appDesc, false);
        CodeModuleManager.deleteModuleEx(newHandle, true);
    }

    // restart the blackberry if required
    CodeModuleManager.promptForResetIfRequired(); 

}

当我将代码运行到模拟器(SimPackage 6.0.0.587 - 9780 和 SimPackage 5.0.0.977 - 9300)时,代码运行良好,它显示一条消息“立即重新启动/稍后重新启动”。

但是当我将代码加载到真实设备 9780 OS 6.0.0.570 和设备 9300 OS 5.0.0.846 时,代码仍然无法工作。

知道为什么会发生吗?或者我只是犯了一个简单但致命的错误?

谢谢 :)

I want to make Blackberry application that can restart the blackberry it self (after doing some task)

for example, i make this little application using the dummy

dummy : (after it becomes dummy.cod, i move it to the res folder and rename it to dummy, not using .cod anymore)

public class Dummy extends Application{  

    public static void main( String[] args ) {  
        new Dummy().enterEventDispatcher();  
    }

    public Dummy(){
    }
}    

application sample code :
(description of my application : just have 1 button to call the reset method)

public void reset() throws Exception {
    // load the dummy cod file
    byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));

            // create new module
    int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length); 

    // install the module
    if (newHandle != 0) {
        int savecode = CodeModuleManager.saveNewModule(newHandle, true);
        if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
            Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
        // now run the dummy application in background
        ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
        ApplicationManager.getApplicationManager().runApplication(appDesc, false);
        CodeModuleManager.deleteModuleEx(newHandle, true);
    }

    // restart the blackberry if required
    CodeModuleManager.promptForResetIfRequired(); 

}

When I run my code to Simulator (SimPackage 6.0.0.587 - 9780 & SimPackage 5.0.0.977 - 9300) the code was running well, it shows a message to "Restart Now / Restart Later".

But when I’ve load my code to real device 9780 OS 6.0.0.570 and device 9300 OS 5.0.0.846, the code is still won’t work.

Any idea why is it happen ? or I just make a simple but fatal mistake ?

Thanks :)

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

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

发布评论

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

评论(1

榆西 2024-12-15 20:42:50

您的代码是正确的,但您需要签署您的代码才能在真实设备上执行CodeModuleManager.deleteModuleEx

请参阅 CodeModuleManager 文档< /a> 了解更多信息。

Your code is correct, but you need to sign your code to be able to execute CodeModuleManager.deleteModuleEx on a real device.

Please refer to the CodeModuleManager documentation for more information.

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