Blackberry
Local
External
Load a Program on to a Device
Use JavaLoader.exe, it is installed with a JDE, and lives in the bin directory.
Run it with no parameters to see the usage.
To load a program onto a BlackBerry that is connected via USB, I typed:
JavaLoader -usb load MyProgram.cod
Simple Dialogs
Dialog.inform("Parse Succeeded");
int val = Dialog.ask(Dialog.D_YES_NO, "Exit?");
if (-1 == val) {
return false;
}
Address, how to display it the map app
void showMap() {
Contact contact = MapShow.getContactFor();
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(contact, 0));
}
static Contact getContactFor()
{
try {
ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.WRITE_ONLY);
Contact contact = contactList.createContact();
String[] name = new String[5];
try {
name[Contact.NAME_OTHER] = "Disney World";
name[Contact.NAME_PREFIX] = "Mr.";
name[Contact.NAME_FAMILY] = "Shepard";
name[Contact.NAME_GIVEN] = "Solx";
} catch(IllegalArgumentException e) {
return null;
}
if (contactList.isSupportedField(Contact.NAME)) {
contact.addStringArray(Contact.NAME, Contact.ATTR_NONE, name);
}
String[] address = new String[7];
try {
address[Contact.ADDR_COUNTRY] = "United States";
address[Contact.ADDR_LOCALITY] = "Lake Buena Vista";
address[Contact.ADDR_POSTALCODE] = "32830";
address[Contact.ADDR_REGION] = "Florida";
address[Contact.ADDR_STREET] = "1675 N Buena Vista Dr";
} catch(IllegalArgumentException e) {
return null;
}
if (contactList.isSupportedField(Contact.ADDR)) {
contact.addStringArray(Contact.ADDR, Contact.ATTR_NONE, address);
}
return contact;
} catch(PIMException e) {
return null;
}
}
Code signing in Eclipse
1) Make sure to have your signing keys in the Eclipse plugin dir with the codesigning jar. For me this is:
C:\Program Files\EclipseBlackBerry\plugins\net.rim.eide.componentpack4.3.0_4.3.0.8\components\bin
2) Make sure Eclipse is exitted.
3) Start Eclipse and open a workspace with a Blackberry project that needs signing.
4) Do "Project -> Clean" making "Start a build immediately" be unchecked.
5) Do "Project -> Build All"
6) Do "Project -> Build Active Blackberry Configuration" (this seems to already have occured by step 5, but just to make my steps repeatable I am list it here)
7) Do "Blackberry -> Request Signatures..." and a signature dialog box will pop up, if you didn't exit eclipse as I said in step 2, you may instead get some file open dialog for a .cod file, to match my instructions go back to step 2 and exit Eclipse and continue with all the steps until you get back to here.
8) Request signatures (it will do so for 3 of the 6 items listed).
9) You are ready to debug, so run your project in the debugger and it should work (I have password locking set, so when I start debugging, Eclipse pops up a dialog where I have to put in my BB password, and if I get it wrong or dismiss the dialog, then I am hosed and I have to exit eclipse and start over, and then when the BB simulator starts I have to enter the password again).
10) after you debug, if you do NOT exit Eclipse, you can change the code and then do steps 5, 6, and then 9 to debug (you don't need to get the signing done again - but if you try to sign again it will give you a dialog asking for a .cod file which you don't need to do, so don't do it. One more thing, on successive debugs I only need to give the password to the BB, I don't get a dialog from Eclipse asking for it).
11) If you ever do exit eclipse, I think you have to go back to the steps after #2 (you may be able to skip the signing again, but I haven't tried it yet - I don't want to mess up something that is working good enough at the moment).
1) Eclipse will put a squiggley red underline and mark as errors all of the imports and usages of code that needs signing, but it will work anyway.
2) There is documentation in a few places that says you can turn off the error markers by going to
"Window -> Preferences... -> BlackBerry JDE -> Code Signing"
and then checking all the options there, but for me Eclipse shows no options there. I even reinstalled Eclipse in a clean virtual machine and still no options there. If you really want to get rid of the error markers there is a .class file you can edit to do so, but I don't think we are supposed to mess with that file so I have left it alone (other than I messed with it to to work out my steps), but it is left in its original form now.
File System
The top directory (on an SD Card) that you can write to is "file:///SDCard/BlackBerry/"
When working with files the names are file with or without a trailing "/"
Removing an Application
- Options | Advanced Options | Applications
- Menu | Modules
- Goto program (it will be at the very end, use CONTROL-DOWN ARROW to get there quickly) Menu | Delete
If that doesn't work (sometimes there is not a 'Delete' option), tether your device via usb cable and use JavaLoader.exe to delete it
(note that the name of the item to be removed is the same name as you see in the Modules list from the instuctions above):
JavaLoader.exe -usb erase MyProgram
# or if the program is running you can do the following (which restarts the BB as part of the uninstall):
JavaLoader.exe -usb erase -f MyProgram
Icon, how to set one for the Application
Note: Application icon pixel size is 32x32
Java IDE
- Add icon file to the project (I prefer .png)
- Package Explorer | Properties | BlackBerry File Properties | Use as application icon
Raw setting
In the .jad file use the MIDlet-1 attribute
#format:
MIDlet-1: Application Name,images/default_icon.png,MainClassName
#example, icon only:
MIDlet-1: ,icon.jpg
Encrypt data on micro sd card
See "userguide_bb8330_cdma.pdf - page 151"
- You must have a password set for password locking
- There are 3 types of locking
- Device - this encrypts data with a device specific key. The data can only be decrypted on the same device
- Security Password - this encrypts data with your password
- Security Password & Device - this encypts the data using the device specific key and your password
To turn on locking goto Options | Media Card | Encryption Mode
Apparently there is no way to tell if encryption is turned on or off.
Apparently a user could copy the data through their USB cable and get an unencrypted version
Code Guidelines
- Use local variables instead of class varibles
- Make classes final (but the Blackberry JDE compiler makes any classes not extended final automatically)
- Use int instead of long
- For constant strings use private static String str = "value" - do not use final, because it will force a copy of the data to happen [BADGV1-p21]
- Avoid Object.getClass() [BADGV1-p21]
- Avoid String(String) constructor [BADGV1-p22]
- Avoid: String str = new String("str");
- Avoid: String str = new String("1" + "2");
- Prefer: String str = "str";
- Prefer: String str = "1" + "2";
- Loops
- Avoid: for(int i = 0; i < vector.size(); i++)
- Prefer: int size = vector.size(); for (int i = 0; i < size; i++)
- Prefer: for (int i = vector.size() - 1; i >= 0; i--)
- Use shift >> instead of division whenever possible.
- Avoid java.util.Enumeration [BADGV1-p23]
- Use instanceof immediately followed by a cast, instead of catch cast exceptions [BADGV1-p23]
- Avoid checking for null
- Avoid: (e != null && e instaceof Fred)
- Prefer: (e instanceof Fred) - which says null is not an instanceof Fred.
- Use private whenever possible
- Use default package access over public or protected whenever possible [BADGV1-p24].
- Avoid creating interfaces unless for sure there will be multiple implementations [BADGV1-p24]
- Use static inner classes[BADGV1-p25]
- Avoid unnecessary initialization
- Import individual classes
- Use multithreading
- Use primitive types
- Avoid creating many objects quickly
- Set object refs to null when finished with them
- Reuse objects whenever possible
- Use a long identifier instead of a String [BADGV1-p27]
- Catching Exceptions eliminates the stack trace, catch Throwable for debugging, since it doesn't elimate the stack trace
GUI, simple example
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.SeparatorField;
/**
*
*/
class Widgets extends UiApplication {
public static void main(String[] args)
{
Widgets theApp = new Widgets();
theApp.enterEventDispatcher();
}
Widgets()
{
pushScreen(new WidgetScreen());
}
}
final class WidgetScreen extends MainScreen
{
public WidgetScreen()
{
LabelField title = new LabelField("LabelField");
setTitle(title);
LabelField label2 = new LabelField("LabelField2");
add(label2);
VerticalFieldManager vfm1 = new VerticalFieldManager();
add(vfm1);
LabelField label3 = new LabelField("LabelField3");
vfm1.add(label3);
LabelField label4 = new LabelField("LabelField4");
vfm1.add(label4);
LabelField label5 = new LabelField("LabelField5");
add(label5);
SeparatorField sep1 = new SeparatorField();
add(sep1);
LabelField label6 = new LabelField("LabelField6");
add(label6);
}
}
Signing keys, restoring them
They go in a directory like this C:\Program Files\Research In Motion\BlackBerry JDE 4.5.0\bin and they are the .csk and .db files
GUI thread, invoking
Use net.rim.device.api.system.Application.invokeLater and net.rim.device.api.system.Application.invokeAndWait
Base64 Encoding a String
HttpConnection httpConn = (HttpConnection)Connector.open("https://secure.com");
String auth = _username + ":" + _password;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Base64OutputStream b64 = new Base64OutputStream(bout);
b64.write(auth.getBytes());
b64.flush();
b64.close();
String encoded = bout.toString();
String httpAuth = "Basic " + encoded;
httpConn.setRequestProperty("Authorization", httpAuth);
int status = httpConn.getResponseCode();
Internet Access in the simulator
- Start the Simulator
- Start the program called MDS
- Verify you can see webpages in the blackberry
Code signing keys, where to get them
http://www.blackberry.com/developers/downloads/jde/api.shtml
Blackberry Development Environment Setup
- Install JDK 1.5 or higher (get it from sun, I use http://javasoft.com
- Install Blackberry JDE, I installed
BlackBerry_JDE_4.3.0.0.exe
- Add the JDK's bin directory to your path (for me it was:
C:\Program Files\Java\jdk1.6.0_06\bin)
- Add emulators for more devices than those that come with the JDK.
- Curve Simulator, I got it from the simulator file
BlackBerry_Simulators_4.3.0.124_8330.exe