2

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 :)

sashimi87
  • 31
  • 1
  • possible duplicate of [How to programatically reboot a BLACKBERRY device?](http://stackoverflow.com/questions/4345752/how-to-programatically-reboot-a-blackberry-device) – Mathias Bynens Feb 20 '12 at 13:05

1 Answers1

0

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.

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114