Tuesday, February 16, 2010

How to create library jar file and use that jar in another project

Sometimes we use some codes/classes redundantly in many application without any changes in the code.
In such type of cases its better to create a jar file with those classes and use only the jar file on other projects.
For exmaple, if we have some classes with custom UI , then we can create a jar file with the classes rather adding all the classes in other projects repeatdely also in those case we have to change the packge name based on the directory.

First , How to Create the Jar file
1. Create a new workspace (for example lib.jdw)
2. Create a new project(for example lib.jdp) under lib.jdw
3. Add the classes you want to create jar.
4. Note that no main is reqired.
5. From project properties make the project as library.
    Right Click on the Project -> Properties.. -> Application Tab -> Select Project type as Library
6. Build the project
7. Now you should have a jar file named lib.jar in the project file directory.
8. Preverify the jar file
    a. Go to your JDE installation folder (C:\Program Files\Research In Motion\BlackBerry JDE 
    b. Copy lib.jar file to bin folder.
    c. Now open your command prompt and change your current directory to your JDE installation 

    d. Now execute the following command:

        preverify -classpath "C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\lib 
        \net_rim_api.jar"  "lib.jar"
    e. In your bin directory(C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\bin) a folder  
        named output will create.
    f. Preverified jar file resides here.

9. Now rename lib.jar as lib.zip and delete cod , csl , cso file from there
10. Rename it back to lib.jar (make sure cod,csl,cso has been deleted)
11. Now you have got the jar file that you can reuse.

Second, How to add this jar to other project
1. For example, yow want to add this jar from another project (different workspace) app.jdp.

2. Import the jar file from the project app.jdp 
    Right Click on the Project -> Properties.. -> Build Tab -> Add lib.jar as Imported Jar    files:
3. Now you will be able to import the classed of lib into the new project app.


Saturday, January 9, 2010

How to Deploy any Application on Real Blackberry Devices

First of all the following files are required to install an application into real device.
  a. appName.cod (appName1.cod, appName2.cod, ...)
  b. appName.jad
  c. appName.alx
  d. .htaccess (required for OTA)

An application can be intalled in the real device in two ways.
  a. OTA (Over The Air)
  b. Connecting your device with the PC
      b1. Using Javaloader
      b2. Using Desktop Manager

OTA Installation Process
Check this link.
Connecting your device with the PC
1. First Connect your device through USB.
2. Sign the cod file if required
3. Then you can install your application in the following ways:
    a. Using javaloader:
        i. Goto the JDE bin directory(ex: C:\Program Files\Research In Motion\BlackBerry JDE 4.6.0\bin\).
        ii. copy your cod and jad file there.
        iii. execute the following command from there (you can create a batch file (*.bat) and just click will do )
                javaloader -usb load applicationName.jad           
                javaloader -usb load applicationName.cod
    b. Using Desktop Manager:
        i.  Install destop manager
        ii. place *.alx and *.cod  file in the same directory
        iii.select your *.alx file from desktop manager.
        iv.Then it should start installing the application in the device.

Also check out these videos from Developer Video Library.

Sunday, August 30, 2009

Code Signing

Quote from Knowbedge Article about code Signing:
"Research In Motion (RIM) must track the use of sensitive application programming interfaces (APIs) in the
BlackBerry JDE for security and export control reasons. In the API reference documentation, sensitive classes or
methods are indicated by a lock icon or are noted as signed. If you use these controlled classes or methods in your
applications, your application must be signed with a key or a signature provided by RIM before you can load the
application .cod files onto the BlackBerry smartphone."
For Buying Code signing keys Go Here. You have to spend 20 USD to buy the key.

Some Other Reference link from KB Article.
What Is - Code signing and obtaining signature keys
Register Signing Keys
How To - sign a .cod file 
Also Have a look at this Article. Here signing steps explained clearly. 
Once you have the key you can sign as many application as you want.
And just in case if you lost the keys RIM resend you the keys to your mail address by disabling your previous keys. For that you have to send a mail to devsupport@rim.com requesting the keys and regarding your issue about key lost. The normally respond within 2-3 business days.

Legally you cannot use the keys more than one PC.
But Practically you can use the keys in any PC. For this:
a. Preserve the following files:
i.   sigtool.db
ii.  sigtool.csk
iii. sigtool.set
b. Copy these files in the JDE bin directory. (ex: C:\Program Files\Research In Motion\BlackBerry JDE 4.3.0\bin)

Clickable BitmapField

For making BitmapField clickable

Bitmap image = Bitmap.createBitmapFromResource("button.png");
BitmapField imageButton = new BitmapField(image, BitmapField.FOCUSABLE)
private XYRect xyrect=new XYRect();
protected boolean navigationClick(int status, int time)
// This is method will invoke after clicking the image
// System.out.println("Image Clicked");
return true;

Align Field in Center

For aligning ButtonField in a HorizontalFieldManager

HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
ButtonField button = new ButtonField("Button",DrawStyle.HCENTER);

For aligning LabelFIeld Center

LabelField labelField = new LabelField("Center Label", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER);

Drawing a Circle

There is no direct api in the graphics class to draw circle.
So for creating circle have to use eclipse or arc.

Circle Property
1. Center point of the circle (x, y)
2. Radius r

Now circle can be drawn in the following ways

Graphics.drawEclipse(x, y, x + r, y, x, y + r, 0, 360);

Graphics.fillArc(x, y, r, r, 0, 360);
Graphics.drawArc(x, y, r, r, 0, 360);

Clickable LabelField act like Link (Href Field )

The example of a LabelField which act like html link.

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.system.Characters;

public class HrefField extends Field {

private String content;
private Font fieldFont;
private int fieldWidth;
private int fieldHeight;
private boolean active = false;
private int backgroundColour = 0xffffff;
//private int textColour = 0x333333;
private int textColour = 0x0000ff;
private int maskColour = 0xBBBBBB;

private int buttonId;
private String buttonName;

public HrefField(String content)
this.content = content;
fieldFont = defaultFont();
fieldWidth = fieldFont.getAdvance(content)+2;
fieldHeight = fieldFont.getHeight() + 3;

public void setColours(int backgroundColour, int textColour, int maskColour)
this.backgroundColour = backgroundColour;
this.textColour = textColour;
this.maskColour = maskColour;

public void setBackgroundColour(int backgroundColour)
this.backgroundColour = backgroundColour;

public void setTextColour(int textColour)
this.textColour = textColour;

public void setMaskColour(int maskColour)
this.maskColour = maskColour;

public void setFont(Font fieldFont)
this.fieldFont = fieldFont;

public int getPreferredWidth()
return fieldWidth;

public int getPreferredHeight()
return fieldHeight;

protected void layout(int arg0, int arg1)
setExtent(getPreferredWidth(), getPreferredHeight());

protected void paint(Graphics graphics)

if (active)
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
graphics.fillRect(0, 0, fieldWidth, fieldHeight);

graphics.drawText(content, 1, 1);
graphics.drawLine(1, fieldHeight-2, fieldWidth-2, fieldHeight-2);

protected boolean navigationClick(int status, int time)
return true;

public void setButtonId(int buttonId)
this.buttonId = buttonId;

public void setButtonName(String buttonName)
this.buttonName = buttonName;

public int getButtonId()
return buttonId;
public String getButtonName()
return buttonName;
public boolean keyChar(char key, int status, int time)
if (key == Characters.ENTER)
return true;

return false;

protected void onFocus(int direction)
active = true;

protected void onUnfocus()
active = false;

public static Font defaultFont()
return Font.getDefault();