Just add this link
http://www.blackberry.com/go/eclipseUpdate/3.5/java
to add site to install all packs of blackberry operating system.
For more information on this visit
Aman's Blackberry Blog
You can get code fully tested and implemented for BlackBerry development. Enjoy Coding...........
Saturday, June 26, 2010
Thursday, May 20, 2010
Retrieve the phone number of the device in blackberry
Just write two lines
String phnumber;
phnumber = Phone.getDevicePhoneNumber(true);
String phnumber;
phnumber = Phone.getDevicePhoneNumber(true);
Wednesday, May 19, 2010
show images in listfield
myList = new ListField()
{
protected boolean navigationClick(int status , int time)
{
int selectedindex = myList.getSelectedIndex();
bsid = businessid[selectedindex];
pid = personid[selectedindex];
did = driverid[selectedindex];
bkid = bookingid[selectedindex];
if(pid!=null&&bkid!=null&&did!=null&&bsid!=null)
{
UiApplication.getUiApplication().pushScreen(new HistoryRoute(obj));
}
return true;
}
};
myList.setRowHeight(70);
ListCallback myCallback = new ListCallback();
myList.setCallback(myCallback);
for(int i = 0;i
{
String fieldOne = requireddate[i]+"#"+requiredtime[i]+"$"+endaddress[i]+"@"+images[i];
myList.insert(i);
myCallback.insert(fieldOne, i);
}
ListfieldCallback method :--
private static class ListCallback implements ListFieldCallback {
private Vector listElements = new Vector();
public void drawListRow(
ListField list, Graphics g, int index, int y, int w) {
String text = (String)listElements.elementAt(index);
Bitmap bmp =null;
int part1= text.indexOf("#");
int part2 =text.indexOf("$");
int part3 = text.indexOf("@");
g.setColor(Color.BLACK);
int len = text.length();
String str1 = new String();
String str2 = new String();
String str3 = new String();
String str4 = new String();
String str12 = text.substring(0,part1);
str1 = str12.substring(0,10);
String remstraftrfirst =text.substring(part1);
str2 = text.substring(part1+1,part2);
str3 = text.substring(part2+1,part3);
byte[] dataArray = null;
str4 = text.substring(part3+1, len);
try
{
byte [] Decoded = Base64InputStream.decode(str4, 0, str4.length());
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
int multH;
int multW;
int currHeight = bitmap.getHeight();
int currWidth = bitmap.getWidth();
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP(50));
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(60));
bitmap = bitmap.scaleImage32(multW,multH);
bmp = bitmap.getBitmap();
}
catch(Exception e)
{
}
int xpos = 0;
int ypos = 5 + y;
int wt = 80;
int h = 200;
g.drawBitmap( xpos, ypos, wt, h, bmp, 0, 0 );
xpos = 90;
ypos = 10+y ;
g.drawText(str1+" "+str2, xpos, ypos);
xpos = 90;
ypos = 30+y;
g.drawText("To:"+" "+str3, xpos, ypos);
g.setColor(Color.GRAY);
g.drawLine(0,ypos+37, 360,ypos+37);
g.drawLine(0,ypos+39, 360,ypos+39);
}
public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s) {
return listElements.indexOf(p, s);
}
public int getPreferredWidth(ListField list) {
int width = 300;
return width;
}
public void insert(String toInsert, int index) {
listElements.addElement(toInsert);
}
}
{
protected boolean navigationClick(int status , int time)
{
int selectedindex = myList.getSelectedIndex();
bsid = businessid[selectedindex];
pid = personid[selectedindex];
did = driverid[selectedindex];
bkid = bookingid[selectedindex];
if(pid!=null&&bkid!=null&&did!=null&&bsid!=null)
{
UiApplication.getUiApplication().pushScreen(new HistoryRoute(obj));
}
return true;
}
};
myList.setRowHeight(70);
ListCallback myCallback = new ListCallback();
myList.setCallback(myCallback);
for(int i = 0;i
String fieldOne = requireddate[i]+"#"+requiredtime[i]+"$"+endaddress[i]+"@"+images[i];
myList.insert(i);
myCallback.insert(fieldOne, i);
}
ListfieldCallback method :--
private static class ListCallback implements ListFieldCallback {
private Vector listElements = new Vector();
public void drawListRow(
ListField list, Graphics g, int index, int y, int w) {
String text = (String)listElements.elementAt(index);
Bitmap bmp =null;
int part1= text.indexOf("#");
int part2 =text.indexOf("$");
int part3 = text.indexOf("@");
g.setColor(Color.BLACK);
int len = text.length();
String str1 = new String();
String str2 = new String();
String str3 = new String();
String str4 = new String();
String str12 = text.substring(0,part1);
str1 = str12.substring(0,10);
String remstraftrfirst =text.substring(part1);
str2 = text.substring(part1+1,part2);
str3 = text.substring(part2+1,part3);
byte[] dataArray = null;
str4 = text.substring(part3+1, len);
try
{
byte [] Decoded = Base64InputStream.decode(str4, 0, str4.length());
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
int multH;
int multW;
int currHeight = bitmap.getHeight();
int currWidth = bitmap.getWidth();
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP(50));
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(60));
bitmap = bitmap.scaleImage32(multW,multH);
bmp = bitmap.getBitmap();
}
catch(Exception e)
{
}
int xpos = 0;
int ypos = 5 + y;
int wt = 80;
int h = 200;
g.drawBitmap( xpos, ypos, wt, h, bmp, 0, 0 );
xpos = 90;
ypos = 10+y ;
g.drawText(str1+" "+str2, xpos, ypos);
xpos = 90;
ypos = 30+y;
g.drawText("To:"+" "+str3, xpos, ypos);
g.setColor(Color.GRAY);
g.drawLine(0,ypos+37, 360,ypos+37);
g.drawLine(0,ypos+39, 360,ypos+39);
}
public Object get(ListField list, int index) {
return listElements.elementAt(index);
}
public int indexOfList(ListField list, String p, int s) {
return listElements.indexOf(p, s);
}
public int getPreferredWidth(ListField list) {
int width = 300;
return width;
}
public void insert(String toInsert, int index) {
listElements.addElement(toInsert);
}
}
Wednesday, April 28, 2010
performing click event in blackberry
protected boolean touchEvent(TouchEvent message)
{
boolean isConsumed = false;
int eventCode = message.getEvent();
if(eventCode == TouchEvent.CLICK) {
UiApplication.getUiApplication().pushScreen(new selctcategory());
}
return isConsumed;
}
{
boolean isConsumed = false;
int eventCode = message.getEvent();
if(eventCode == TouchEvent.CLICK) {
UiApplication.getUiApplication().pushScreen(new selctcategory());
}
return isConsumed;
}
Use of Touch events in Blackberry
protected boolean touchEvent(TouchEvent message)
{
boolean isConsumed = false;
TouchGesture touchGesture = message.getGesture();
if (touchGesture != null)
{
if (touchGesture.getEvent() == TouchGesture.SWIPE)
{
switch(touchGesture.getSwipeDirection())
{
case TouchGesture.SWIPE_NORTH:
Dialog.alert("Swipe to up side ");
break;
case TouchGesture.SWIPE_SOUTH:
Dialog.alert("Swipe to down side ");
break;
case TouchGesture.SWIPE_EAST:
Dialog.alert("Swipe to right side ");
break;
case TouchGesture.SWIPE_WEST:
Dialog.alert("Swipe to left side ");
break;
}
isConsumed = true;
}
}
return isConsumed;
}
{
boolean isConsumed = false;
TouchGesture touchGesture = message.getGesture();
if (touchGesture != null)
{
if (touchGesture.getEvent() == TouchGesture.SWIPE)
{
switch(touchGesture.getSwipeDirection())
{
case TouchGesture.SWIPE_NORTH:
Dialog.alert("Swipe to up side ");
break;
case TouchGesture.SWIPE_SOUTH:
Dialog.alert("Swipe to down side ");
break;
case TouchGesture.SWIPE_EAST:
Dialog.alert("Swipe to right side ");
break;
case TouchGesture.SWIPE_WEST:
Dialog.alert("Swipe to left side ");
break;
}
isConsumed = true;
}
}
return isConsumed;
}
How to convert an image coming in base64 from webservice into bitmap
byte [] Decoded = Base64InputStream.decode(getNodeValue(detailNode), 0, getNodeValue(detailNode).length());
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
Bitmap bmp = bitmap.getBitmap();
add( new BitmapField(bmp));
Note:- here getNodeValue(detailNode) is a method which reads nodes of Web Service
String dd = new String(Decoded);
dataArray = dd.getBytes();
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
Bitmap bmp = bitmap.getBitmap();
add( new BitmapField(bmp));
Note:- here getNodeValue(detailNode) is a method which reads nodes of Web Service
Thursday, April 22, 2010
Fetch image from url in blackberry
First make a class and paste the code as it is.
package reports;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
public class UrlToImage
{
public static Bitmap _bmap;
UrlToImage(String url)
{
HttpConnection connection = null;
InputStream inputStream = null;
EncodedImage bitmap;
byte[] dataArray = null;
try
{
connection = (HttpConnection) Connector.open(url, Connector.READ, true);
inputStream = connection.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
StringBuffer rawResponse = new StringBuffer();
while (-1 != (length = inputStream.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length));
}
int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK)
{
throw new IOException("HTTP response code: "
+ responseCode);
}
final String result = rawResponse.toString();
dataArray = result.getBytes();
}
catch (final Exception ex)
{ }
finally
{
try
{
inputStream.close();
inputStream = null;
connection.close();
connection = null;
}
catch(Exception e){}
}
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
// this will scale your image acc. to your height and width of bitmapfield
int multH;
int multW;
int currHeight = bitmap.getHeight();
int currWidth = bitmap.getWidth();
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP(480));//height
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(360));//width
bitmap = bitmap.scaleImage32(multW,multH);
_bmap=bitmap.getBitmap();
}
public Bitmap getbitmap()
{
return _bmap;
}
}
Now in ur main class where you want to display picture write the code
package reports;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
public class First extends UiApplication{
public static void main(String[] args)
{
First theapp = new First();
theapp.enterEventDispatcher();
}
public First()
{
pushScreen(new scr());
}
}
class scr extends MainScreen
{
Bitmap bit ;
BitmapField pic;
public scr()
{
String url ="http://www.somesite.image.jpg";
UrlToImage img = new UrlToImage( url);
bit =img.getbitmap();
pic = new BitmapField(bit);
add(pic);
}
}
package reports;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
public class UrlToImage
{
public static Bitmap _bmap;
UrlToImage(String url)
{
HttpConnection connection = null;
InputStream inputStream = null;
EncodedImage bitmap;
byte[] dataArray = null;
try
{
connection = (HttpConnection) Connector.open(url, Connector.READ, true);
inputStream = connection.openInputStream();
byte[] responseData = new byte[10000];
int length = 0;
StringBuffer rawResponse = new StringBuffer();
while (-1 != (length = inputStream.read(responseData)))
{
rawResponse.append(new String(responseData, 0, length));
}
int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK)
{
throw new IOException("HTTP response code: "
+ responseCode);
}
final String result = rawResponse.toString();
dataArray = result.getBytes();
}
catch (final Exception ex)
{ }
finally
{
try
{
inputStream.close();
inputStream = null;
connection.close();
connection = null;
}
catch(Exception e){}
}
bitmap = EncodedImage.createEncodedImage(dataArray, 0,dataArray.length);
// this will scale your image acc. to your height and width of bitmapfield
int multH;
int multW;
int currHeight = bitmap.getHeight();
int currWidth = bitmap.getWidth();
multH= Fixed32.div(Fixed32.toFP(currHeight),Fixed32.toFP(480));//height
multW = Fixed32.div(Fixed32.toFP(currWidth),Fixed32.toFP(360));//width
bitmap = bitmap.scaleImage32(multW,multH);
_bmap=bitmap.getBitmap();
}
public Bitmap getbitmap()
{
return _bmap;
}
}
Now in ur main class where you want to display picture write the code
package reports;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
public class First extends UiApplication{
public static void main(String[] args)
{
First theapp = new First();
theapp.enterEventDispatcher();
}
public First()
{
pushScreen(new scr());
}
}
class scr extends MainScreen
{
Bitmap bit ;
BitmapField pic;
public scr()
{
String url ="http://www.somesite.image.jpg";
UrlToImage img = new UrlToImage( url);
bit =img.getbitmap();
pic = new BitmapField(bit);
add(pic);
}
}
Subscribe to:
Posts (Atom)