Skip to main content

Posts

Showing posts from July, 2009

get the System Date Time Blackberry

Date d = new Date( System.currentTimeMillis() ); lblDate = new LabelField(d.toString()); this will return Long Date Including timizone and all the things. but if you want a format the date time to shor, long or medium you can use following method. Medium Date SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_MEDIUM);     String Mydate = df.format(new Date(System.currentTimeMillis())); Ex:- Mar 08, 2006. Short Date SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_SHORT);  String Mydate = df.format(new Date(System.currentTimeMillis())); Ex:- 03.08.06. Long Date SimpleDateFormat df = new SimpleDateFormat(SimpleDateFormat.DATE_LONG);  String Mydate = df.format(new Date(System.currentTimeMillis())); Ex:- Wednesday, March 08, 2006. Custom Date SimpleDateFormat df = new SimpleDateFormat( "MMMM, dd yyyy" );  String Mydate = df.format(new Date(System.currentTimeMillis())); Ex:- March 08, 2006. Some Formating Examples "yyyy.MM.dd G 'at

Blackberry POST Request To the Server with Header information

public static String ProcessPOSTRequest(String serviceUrl, String authToken, String requestData) { HttpConnection hc = null ;         OutputStream os = null;          try { hc = (HttpConnection) Connector.open(serviceUrl,Connector.READ_WRITE); hc.setRequestMethod(HttpConnection.POST); hc.setRequestProperty("Content-Type", "text/xml"); //hc.setRequestProperty("Content-Language", "en-US"); //hc.setRequestProperty("Accept", "application/octet-stream"); if (authToken.length()>0) { byte[] ByteArray=authToken.getBytes("UTF-8"); String Encoded = Base64OutputStream.encodeAsString(ByteArray, 0, ByteArray.length, false, false); hc.setRequestProperty("Authorization",Encoded); } os = hc.openOutputStream(); os.write(requestData.getBytes(),0,requestData.getBytes().length); os.flush(); os.close(); int responseCode = hc.getResponseCode(); System.out.print

BackBerry GET Request to the Server

public static String getHttpResponce (String URL) { try { HttpConnection httpConnection = (HttpConnection) Connector.open(URL); httpConnection.setRequestMethod(HttpConnection.GET); InputStream inputStream = httpConnection.openInputStream(); StringBuffer sb = new StringBuffer(); int C; while( -1 != (C = inputStream.read()))  { sb.append((char)C); } return sb.toString(); } catch (Exception e) { return "-1"; } }

Deploy / Install Application to BlackBerry

Install Black Berry Desktop Manager   Connect Blackberry to the PC using the cable Run the Desktop Manager Select the Alx File and Click next to finish.

Change Main Screen Background in Blackberry

In here i tried several methods to do that. All methods give me some out put but not perfect. most of examples gives the out put but also gives ugly scoll bar. I used folloeing coding to set main screen backgroung color with out the scoll bar in component pack 4.5. public class frmLogin extends MainScreen { VerticalFieldManager vmain; public frmLogin()  {        super( NO_VERTICAL_SCROLL );       vmain = new VerticalFieldManager( USE_ALL_HEIGHT |USE_ALL_WIDTH )      {  protected void paint(net.rim.device.api.ui.Graphics graphics)          {      graphics.setBackgroundColor(0xe6e7e8);  // 0xRRGGBB or Color.Blue          graphics.clear();  super.paint(graphics);         }       };            // Add other controlers to vmain            add(vmain); }

Connect to web service Blackberry

Assume this as a sample SOAP 1.1 Message SOAP 1.1 The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values. POST /Service.asmx HTTP/1.1 Host: 64.49.254.143 Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/isValidUser" ><?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> < isValidUser xmlns="http://tempuri.org/"> < Username >string</Username> < Password >string</Password> </isValidUser> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope

Bitmap Field events, Listeners in Blackberry

bmfDeposit = new BitmapField(Bitmap.getBitmapResource("Deposit.png"),FOCUSABLE) {      protected void onFocus(int direction) { setBitmap(Bitmap.getBitmapResource("View.png")); } protected void onUnfocus() { setBitmap(Bitmap.getBitmapResource("Deposit.png")); } protected boolean trackwheelClick(int status, int time) { UiApplication.getUiApplication().pushScreen(new frmDepositMain()); return true; } protected boolean keyChar(char character, int status, int time) { if (Characters.ENTER==character) { UiApplication.getUiApplication().pushScreen(new frmDepositMain()); } return true; } };

Progress Bar in Black Berry

Editable Progress Bar GaugeField gaugeField; gaugeField = new GaugeField ("PROGRESS ", 0, 30, 15, Field.FOCUSABLE);     Precentage Progress Bar GaugeField gaugeField2; gaugeField2 = new GaugeField ("PERCENT ", 0, 30, 15, GaugeField.PERCENT);   Normal Progress Bar GaugeField gaugeField3; gaugeField3  = new GaugeField ("NO_TEXT ", 0, 30, 15, GaugeField.NO_TEXT);  Syntax GaugeField (lable,min,max,start,style);

Detect when an image is added or removed in the BlackBerry device file system

import net.rim.device.api.io.file.FileSystemJournal; import net.rim.device.api.io.file.FileSystemJournalEntry; import net.rim.device.api.io.file.FileSystemJournalListener; import net.rim.device.api.ui.component.Dialog; public class FileExplorerDemoJournalListener implements FileSystemJournalListener  { private long _lastUSN; private String path; public void fileJournalChanged() { long nextUSN = FileSystemJournal.getNextUSN(); for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN; --lookUSN) { FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN); if (entry == null) {    break;  } path = entry.getPath(); switch (entry.getEvent()) {    case FileSystemJournalEntry.FILE_ADDED:         Dialog.alert(path);        break;    case FileSystemJournalEntry.FILE_DELETED:          Dialog.alert(path);        break;        } } } } ---------------------- Main----------------------------------- import net.rim.device.api.ui.UiAppli

How to Convert Byte[] to File in C#

public void getFile(Byte[] Files)  { String LPath ="sample.jpg"; if (File.Exists(LPath )) {  File.Delete(LPath );    } FileStream fs = new FileStream(LPath , FileMode.Create, FileAccess.ReadWrite, FileShare.Write); fs.Write(Files, 0, Files.Length); fs.Flush(); fs.Close(); }