Wednesday, April 11, 2012

Blackberry recipes

Today my planning to Blackberry simple task but most of time it's use on our application.

1. Get IMEI No:
private String getIMEINumber() {
  byte[] imeiByteArray = net.rim.device.api.system.GPRSInfo.getIMEI();
  String imei = net.rim.device.api.system.GPRSInfo.imeiToString(imeiByteArray);
  imeiByteArray = null;
  return imei;
}

2. Set Font on LabelField:
 LabelField lblTemp = new LabelField("Temp");
 FontFamily fontFamily[] = FontFamily.getFontFamilies();
 Font font = fontFamily[1].getFont(FontFamily.CBTF_FONT, 12);
 lblTemp.setFont(font);

3. get List of Install Application:
net.rim.device.api.system.CodeModuleManager.getModuleHandles()
get an array of handles into all modules now.
net.rim.device.api.system.CodeModuleManager.getApplicationDescriptors(int moduleHandle)
To get ApplicationDescriptors associated with the module. You will have to sort out which modules are libraries and which are applications.

4.Sent Mail:
private void invokeMail(String emailID){
  try{
   Message m = new Message();
   Address a = new Address(""+emailID, "Mail Title");
   Address[] addresses = {a};
   m.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses);
   m.setContent("");
   m.setSubject("Mail Subject");
   Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(m));
  }catch(Exception e){
    System.out.println("Error on Open Mail");
  }
}
5. Invoke Call
private void invokeCall(String callNo){
        PhoneArguments call = new PhoneArguments(PhoneArguments.ARG_CALL, callNo);
 Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, call);
}
Read Image from SD Card
public Bitmap getImage(){
    Bitmap bitmapImage=null;
    try{
        InputStream input;
        FileConnection fconn = (FileConnection) Connector.open("file:///store/home/user/dirname/imgname.png", Connector.READ_WRITE);
        input = fconn.openInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int j = 0;
        while((j=input.read()) != -1) {
             baos.write(j);
        }
        byte[] byteArray = baos.toByteArray();

        bitmapImage = Bitmap.createBitmapFromBytes(byteArray,0,byteArray.length,1);


    }catch(Exception ioe){
        System.out.println(ioe);
    }
    return bitmapImage;
}

Thanks,,..

Wednesday, April 4, 2012

Convert WebApplication to Blackberry Playbook Application

Today I have study regarding to convert web application on blackberry playbook application using Blackberry webworks. In this point we study convert web application to zip and zip to .bar and install that bar file into blackberry playbook.

In First step create hello world web application using html as following code.

1. Create Folder helloworld, and create index.html file on it and save with following code.



My First Heading

My first paragraph.


2. Now Create config.xml file this file is configuration on you playbook application like application name, application icon, splash screen etc. paste following code on config.xml file.



  Helloworld
  Sample Hello world web application convert to blackberry playbook
  Research In Motion
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  


3. Now Create images folder on project for icon images. Add you application icon.
4. Create zip file you helloworld application, Note: please select all helloworld file then zip otherwise chance to convert error.

5. Convert zip file to .bar file and sign .bar file using following command.

bbwp "C:\helloworld.zip" -gcsk mycskpassword -gp12 myp12password -buildId 10 -o "C:\myoutputdir"




A successful signing should produce results like the following.

[INFO] Parsing command line options
[INFO] Parsing bbwp.properties
[INFO] Validating WebWorks archive
[INFO] Parsing config.xml
[INFO] Populating application source
[INFO] Compiling WebWorks application
[INFO] Packaging the bar file
[INFO] Bar packaging complete
[INFO] Starting signing tool
[INFO] Signing complete
[INFO] WebWorks application packaging complete

if you have not install signature key please you can find help following link:
http://www.devguy.org/2011/05/signing-blackberry-playbook.html

Request new signature key:
https://www.blackberry.com/SignedKeys/


Now you .bar file is ready to install Blackberry playbook device you can install at following command.

A. Turn on Development Mode on your BlackBerry PlayBook tablet.
B. Obtain the IP address of your BlackBerry PlayBook tablet.
C. At the command prompt, navigate to the bin folder of the BlackBerry® WebWorks™ SDK for BlackBerry® Tablet OS installation folder. For example:

cd WebWorks SDK Install Dir\bbwp\blackberry-tablet-sdk\bin

D. At the command prompt, run the blackberry-deploy command.

blackberry-deploy -installApp -password playbook -device 192.100.1.2 -package helloworld.bar

Now you application install successfully on playbook device.

Output Look like this: