The following code will help to call a mobile number programatically.
PhoneArguments callArgs = new PhoneArguments(PhoneArguments.ARG_CALL,"mobile number to make call");
Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, callArgs);
Tuesday, August 21, 2012
Phone Call in Blackberry
Automatically Taking Picture in Blackberry
The following code will automatically take pictures without any user interactions. It also displays the taken picture in the screen.
private Field _videoField;
private Player _player;
private VideoControl _videoControl;
byte[] image;
try{
_player = Manager.createPlayer( "capture://video??encoding=jpeg&width=240&height=240" );
_player.realize();
_player.prefetch();
_videoControl = (VideoControl)_player.getControl("VideoControl");
_player.start();
if (_videoControl != null){
_videoField = (Field) _videoControl.initDisplayMode (GUIControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
add(_videoField);
}
}
catch(Exception e)
{
//show error
}
try {
image = _videoControl.getSnapshot(null);
_player.close();
EncodedImage bitmap = EncodedImage.createEncodedImage(image, 0, image.length);
BitmapField field1 = new BitmapField();
field1.setImage(bitmap);
add(field1);
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
private Field _videoField;
private Player _player;
private VideoControl _videoControl;
byte[] image;
try{
_player = Manager.createPlayer( "capture://video??encoding=jpeg&width=240&height=240" );
_player.realize();
_player.prefetch();
_videoControl = (VideoControl)_player.getControl("VideoControl");
_player.start();
if (_videoControl != null){
_videoField = (Field) _videoControl.initDisplayMode (GUIControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
_videoControl.setDisplayFullScreen(true);
add(_videoField);
}
}
catch(Exception e)
{
//show error
}
try {
image = _videoControl.getSnapshot(null);
_player.close();
EncodedImage bitmap = EncodedImage.createEncodedImage(image, 0, image.length);
BitmapField field1 = new BitmapField();
field1.setImage(bitmap);
add(field1);
} catch (MediaException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Play Audio From URL in Blackberry
The following code will help you to playing an audio from url.
try {
String httpURL="http://www.yourwebsite.com/audio.mp3";
if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
&& RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
httpURL += ";interface=wifi";
}
Player player;
player =Manager.createPlayer(httpURL);
player.realize();
player.prefetch();
player.start();
} catch (Exception me) {
Dialog.alert(me.toString());
}
try {
String httpURL="http://www.yourwebsite.com/audio.mp3";
if ((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
&& RadioInfo.areWAFsSupported(RadioInfo.WAF_WLAN)) {
httpURL += ";interface=wifi";
}
Player player;
player =Manager.createPlayer(httpURL);
player.realize();
player.prefetch();
player.start();
} catch (Exception me) {
Dialog.alert(me.toString());
}
Thursday, July 26, 2012
Gauge Field in Blackberry(Like download status bar)
The following code will display a Download status Bar like Gauge field in Blackberry.

GaugeField gField;
gField = new CustomGaugeField();
add(gField);
startProgressTimer();
private void startProgressTimer() {
ttask = new TimerTask() {
public void run() {
Field f;
for (int i = 0; i < getFieldCount(); i++) {
f = getField(i);
if (f instanceof CustomGaugeField) {
final CustomGaugeField gField = (CustomGaugeField) f;
final int increment = (i + 1) * 2;
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
if(gField.getValue()>=100)
{
ttask.cancel();
//Implement your action here
}
else{
gField.setValue((gField.getValue() + increment) % 101);
}
}
}
);
}
}
}
};
Timer ttimer = new Timer();
ttimer.schedule(ttask, 1000, 300);
}
//custom Gauge Field Class
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.GaugeField;
class CustomGaugeField extends GaugeField {
// Default constructor, need improvement
public CustomGaugeField() {
super("", 0, 100, 0, GaugeField.PERCENT);
}
// Colors
private static final int BG_COLOR = 0xd6d7d6;
private static final int BAR_COLOR = 0x63cb52;
private static final int FONT_COLOR = 0x5a55c6;
protected void paint(Graphics graphics) {
int xProgress = (int) ((getWidth() / 100.0) * getValue());
int xProgressInv = getWidth() - xProgress;
// draw background
graphics.setBackgroundColor(BG_COLOR);
graphics.clear();
// draw progress bar
graphics.setColor(BAR_COLOR);
graphics.fillRect(0, 0, xProgress, getHeight());//left to right
//graphics.fillRect(xProgressInv, 0, xProgress, getHeight());//right to left
// draw progress indicator text
String text = getValue() + "%";
Font font = graphics.getFont();
int xText = (getWidth() - font.getAdvance(text)) / 2;
int yText = (getHeight() - font.getHeight()) / 2;
graphics.setColor(FONT_COLOR);
graphics.drawText(text, xText, yText);
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent (width, 15);
}
}
GaugeField gField;
gField = new CustomGaugeField();
add(gField);
startProgressTimer();
private void startProgressTimer() {
ttask = new TimerTask() {
public void run() {
Field f;
for (int i = 0; i < getFieldCount(); i++) {
f = getField(i);
if (f instanceof CustomGaugeField) {
final CustomGaugeField gField = (CustomGaugeField) f;
final int increment = (i + 1) * 2;
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
if(gField.getValue()>=100)
{
ttask.cancel();
//Implement your action here
}
else{
gField.setValue((gField.getValue() + increment) % 101);
}
}
}
);
}
}
}
};
Timer ttimer = new Timer();
ttimer.schedule(ttask, 1000, 300);
}
//custom Gauge Field Class
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.GaugeField;
class CustomGaugeField extends GaugeField {
// Default constructor, need improvement
public CustomGaugeField() {
super("", 0, 100, 0, GaugeField.PERCENT);
}
// Colors
private static final int BG_COLOR = 0xd6d7d6;
private static final int BAR_COLOR = 0x63cb52;
private static final int FONT_COLOR = 0x5a55c6;
protected void paint(Graphics graphics) {
int xProgress = (int) ((getWidth() / 100.0) * getValue());
int xProgressInv = getWidth() - xProgress;
// draw background
graphics.setBackgroundColor(BG_COLOR);
graphics.clear();
// draw progress bar
graphics.setColor(BAR_COLOR);
graphics.fillRect(0, 0, xProgress, getHeight());//left to right
//graphics.fillRect(xProgressInv, 0, xProgress, getHeight());//right to left
// draw progress indicator text
String text = getValue() + "%";
Font font = graphics.getFont();
int xText = (getWidth() - font.getAdvance(text)) / 2;
int yText = (getHeight() - font.getHeight()) / 2;
graphics.setColor(FONT_COLOR);
graphics.drawText(text, xText, yText);
}
protected void layout(int width, int height) {
super.layout(width, height);
setExtent (width, 15);
}
}
Subscribe to:
Posts (Atom)