I am new to BlackBerry application development and trying to make a simple application to turn my flash light on as a torch. I know there are several applications that do this already, but I would like to try do it on my own.
I have installed eclipse and all the necesary add on to get my development environment running. I have also successfully create the stock standard hello world application.
I am however struggling to find out how to do this. I have been reading through the API documentation and started playing with FlashControl
, VideoControl
and SnapshotControl
.
These however don't seem to expose methods to do this.
I know through the video camera I am able to go to options and turn the flash light on and this is exactly what i'm trying to mimic.
The code i have used so far which seems to just set the camera flash to force on is:
Player p = javax.microedition.media.Manager.createPlayer("capture://video");
p.realize();
p.start();
FlashControl flashControl = (FlashControl) p.getControl("javax.microedition.amms.control.camera.FlashControl");
flashControl.setMode(FlashControl.FORCE);
the problem relevant to the flash control has been resolved by me
as per i am using the flash control on my recent application on
camera.
Here is the code which i used :
public Camera(int j)
{
k = j;
try
{
Player player = Manager.createPlayer("capture://video");
player.realize();
_videoControl = (VideoControl) player.getControl("VideoControl");
flashControl = new FlashControl()
{
public void setMode(int mode)
{
// TODO Auto-generated method stub
}
public boolean isFlashReady()
{
// TODO Auto-generated method stub
return false;
}
public int[] getSupportedModes()
{
// TODO Auto-generated method stub
return null;
}
public int getMode()
{
// TODO Auto-generated method stub
return 0;
}
};
flashControl = (FlashControl) player
.getControl("javax.microedition.amms.control.camera.FlashControl");
try {
if (k == 1)
{
flashControl.setMode(FlashControl.AUTO);
Dialog.alert("slect Auto");
}
else if (k == 2)
{
flashControl.setMode(FlashControl.OFF);
Dialog.alert("slect No");
}
}
catch (Exception e)
{
System.out.println(e);
}
if (_videoControl != null)
{
_videoField = (Field) _videoControl.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE,
"net.rim.device.api.ui.Field");
// _videoControl.setDisplaySize(330, 420);
// _videoControl.setDisplayLocation(getContentWidth(),
// getContentHeight());
_videoControl.setVisible(true);
add(_videoField);
capture = new ButtonField("Capture", Field.FIELD_HCENTER);
capture.setChangeListener(this);
add(capture);
player.start();
}
}
catch (Exception e)
{
System.out.println(e);
}
}
this logic has been implemented simultaneously with Pinkesh as my colleage
in the comapny
The FlashControl
class, available from OS 5.0 allows you to turn the flash on. Just set a flash control on your player with the FORCE flag:
FlashControl flash = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
if(flash!=null) {
try {
flash.setMode(FlashControl.FORCE);
} catch(IllegalArgumentException iae){}
}
For this to work, you'll probably need to open a player to record video or take a picture. I'm not showing that in my code for the sake of brevity, but here you can read a tutorial. If your app is only about turning on the flash, you'd probably like to have the video field hidden.
Try something like this
LED.setState(LED.STATE_ON); // for LED
Backlight.enable(true); // for Screen
this.setMode(FlashControl.ON); // for flash light.
or else import this package
package lsphone.flash.microfireps;