Blackberry Developer Hints & Snippets

by Jessica Brown

Touch Screen Development

Retrieve the current orientation of the touch screen

Import net.rim.device.api.system.Display
Call Display.getOrientation()

Note that Display does not exist in JDEs prior to 4.7

Using Ifdefs to support one code base for multiple JDEs

Files that use the preprocessor must have //#preprocess as their first line to enable pre-processing on the file.

 

Then, where you want to use preprocessed code, use ifdef or ifndef blocks. Eg:

//#ifndef jde_4_7
/*
//#endif
Your code here; // code that will run if jde_4_7 is defined
//#ifndef jde_4_7
*/
//#endif

Command Line Builds

USB Cable Loading an App

When you plug in the (powered-on) device via USB a removable drive should appear in my computer. If you are prompted by windows to install drivers for the Blackberry, do so before proceeding. Blackberry USB Drivers can be obtained from Blackberry's website

Installed programs will be under the "Downloads" icon on the device. If a different version of the same application was loaded over the air, it may result in a message on attempted app startup about duplicate class definitions. If this is the case javaloader can be used to list the applications on the phone (javaloader -u dir), to identify the duplicated version, which can then be removed with javaloader.

Eclipse Blackberry Plugin/Simulators

Blackberry Simulator Reset

When debugging in Eclipse, sometimes you may come across a situation where you want to reset the blackberry device settings to undo any accidental customization (such as rearranging menus on the device) and remove all persisted files on the device (such as removing any cached app settings).

To do this, run the clean.bat file in the eclipse plugin's simulator's directory. (eg: for the 4.7.0 simulator, this will likely be "C:\Program Files\eclipse\plugins\net.rim.ejde.componentpack4.7.0_4.7.0.53\components\simulator\clean.bat")

Misc.

Compatibility Mode on Touch Screen Devices

Touch-screen support is a new feature in the 4.7 OS/JDE. If you build an app to run on a touch-screen device like the storm using JDE prior to 4.7, unless you set a special JAD setting, the app will run in "compatibility mode". Differences in compatibility mode include things like the app does not run at the native resolution of the device but will run centered on the screen in portrait mode (at the resolution of older blackberries), flipping being disabled, and other UI differences.

RTSP support in Simulator

The 4.6.0 JDE & simulator supports both HTTP and RTSP based playback well. The 4.7.0 simulator does not support RTSP, as blackberry "does not support all of the multimedia codecs on the simulator itself [and is] relying on the device to be the proper testing ground", so testing RTSP in version 4.7.0 requires testing on a physical device.