Tag: cod

Programmatically Reboot a BlackBerry Device

if you curious about how to programmatically reboot a BlackBerry Device,
there’s no specific API to do it.
but, you should start your curiosity from how you reinstall an application,
sometime you need to reboot your device.

here’s how to programmatically reinstall a module, so the BlackBerry will ask to reboot..

  1. Create a dummy.cod module
  2. public class Dummy extends Application{
    
    	public static void main( String[] args )
    	{
    	    new Dummy().enterEventDispatcher();
    	}
    }
  3. Create new BlackBerry project (reboot project) and include the dummy.cod in the project
  4. In the reboot project, install the dummy.cod
  5. Run the dummy application in the background
  6. Uninstall the dummy application, after removing dummy.cod the BlackBerry will ask to reboot
  7. 	public  void reset() throws IOException, ApplicationManagerException {
    
    		// load the dummy cod file
    		byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy.cod"));
    		//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)
    				System.out
    				.println("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 reuired
    		if (CodeModuleManager.isResetRequired())
    			CodeModuleManager.promptForResetIfRequired();
    
    		//if you want to automate the reboot.
    		EventInjector.TrackwheelEvent moveEvent =  new EventInjector.TrackwheelEvent( EventInjector.TrackwheelEvent.THUMB_ROLL_UP, 1, 1 );
    		EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent(
    				KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_ENTER , 0, 100);
    		EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent(
    				KeyCodeEvent.KEY_UP, (char) Keypad.KEY_ENTER, 0, 100);
    
    		try {
    			Thread.sleep(1000);
    		} catch (InterruptedException e) {
    			// TODO Auto-generated catch block
    		e.printStackTrace();
    		}
    		EventInjector.invokeEvent(moveEvent);
    		EventInjector.invokeEvent(pressEndKey);
    		EventInjector.invokeEvent(releaseEndKey);
    		Status.show("device is restarting");
    	}

[1] http://blog.vimviv.com/blackberry/programmatically-reboot-blackberry-device/
[2] http://supportforums.blackberry.com/t5/Java-Development/How-can-I-programmatically-reset-a-blackberry/td-p/116854


Obfuscate code in a BlackBerry application

How To – Obfuscate code in a BlackBerry application [1]

Unlike traditional compilers, the compiler for the BlackBerry platform is highly optimized for a constrained mobile environment where the goal is to minimize the size of the application. The resulting COD file provides a significant amount of obfuscation-like services similar to other true obfuscation packages in an effort to reduce the size of the COD file. For example, the following information is removed from a COD file:

  • All debug information
  • Local variable names
  • Source Line Numbers
  • Private Method and Members names

Support for obfuscation via third-party tools is not integrated into the JDE. As such, a command line procedure is required to obfuscate COD files for use on BlackBerry wireless devices. This article provides the steps and techniques required to obfuscate a COD file and have it execute properly on the BlackBerry device.

  1. Create an application in the JDE. You should place the project file in a separate directory for ease of use during this process.
  2. Create a temporary directory.
  3. Copy the associated JAR file created by the BlackBerry JDE to the temporary directory.
  4. Extract the contents of the JAR file into the temporary directory using the following command: jar xvf SampleApplication.jar
  5. Delete the COD file (that was extracted as part of the JAR file) and the JAR file. You will replace these files in the following steps.
  6. Obfuscate the class files that are contained in the temporary directory.
  7. Run the pre-verify tool on the contents of the temporary directory using the following command: preverify.exe -verbose -d . -classpath..\lib\net_rim_api.jar;
  8. Run rapc on the obfuscated (and pre-verified) class files to create a COD file. Use the following command:
  9. rapc.exe -verbose import=..\lib\net_rim_api.jar codename=SampleApplication SampleApplication.rapc C:\yourTempDir\SampleApplication.class

This produces a COD file that will work on a device that has its contents obfuscated.

[1] http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_To_-_Obfuscate_code_for_a_BlackBerry_application.html?nodeid=1033550&vernum=0


Load Text File From Library Project

There is a non-documented way, but it works [1].

If your library cod file name is: mylibrary.cod

and your text file included into mylibrary.cod is mytext.txt

then you can use the following url to open the stream for the text file from another cod file:

cod://mylibrary/mytext.txt
Message Edited by tbilisoft on 14-06-2009 05:50 PM

Tbilisoft Team
BlackBerry Utilities For Everyday Life
main site: http://www.tbilisoft.com
site for mobile users: http://www.tbilisoft.mobi

[1] http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=43341


  • Copyright © 1996-2010 vaks.in. All rights reserved.
    iDream theme by Templates Next | Powered by WordPress