Sonntag, 6. Dezember 2009

Hard reset your BlackBerry

Ever find yourself in the position where you want to hard reset your Blackberry without pulling out the battery? There are some apps in AppWorld that can do exactly this. Every wondered how they do this? There is no API for it.

I just found a great post in the BlackBerry Support forums which explains how to do the magic:
The only situation where the BlackBerry wants to restart is after installation/deinstallation of running modules. And that's exaclty the solution: just do it. :-)

(from http://supportforums.blackberry.com/t5/Java-Development/How-can-I-programmatically-reset-a-blackberry/td-p/116854)

1. Create a stub app who's main function simply creates the app instance and calls enterEventDispatcher on it. Include the stub cod as a resource in your app and remove the .cod extension.

2. Load the stub module into a byte array. The byte array can be obtained by calling getResourceAsStream with the cod file as your resource and then reading the bytes.

3. Create a new module with createNewModule( int, byte[], int ).

4. Call CodeModuleManager.saveNewModule( int, boolean ) where the int argument is the handle obtained from createNewModule and the boolean is true for forceOverwrite.

5. Obtain the application descriptors for your new module by calling CodeModuleManager.getApplicationDescriptors( int ). There should only be 1 descriptor in the resulting ApplicationDescriptor array at index 0.

6. Call ApplicationManager.getApplicationManager().runApplication( descriptor, false ), where descriptor is the application descriptor obtained in 5 and false means do not grab foreground. This will launch the module you just loaded.

7. Call CodeModuleManager.deleteModuleEx( int, boolean ) where the int is your module handle and the boolean is set to true for force delete even if the application is running. This is the real trick to this, because if you delete an application while it is running, a restart will be required.

8. Call CodeModuleManager.promptForResetIfRequired()

9. Presto

Donnerstag, 3. Dezember 2009

Midlet Installation Problems

Do you know the depressing moments when your JME application doesn't start? Or can not be installed although everything was fine on simulator or even on the different device?

The system is normally not much help at all so you spent hours guessing and trying: software development at it's worst.

Often it's simple a system check of properties in some of the files (often much too strict if you ask me). This could be a version number that contains a wrong formated build-number (Midlets need major.minor.build instead of major.minor.build.revision) or signature hashes written by your build tools into the manifest file.

Next time when you don't have a clue this document could help as a checklist (thanks to my colleague Yousuf who found this document):
Why Doesn't My MIDlet Run?