6

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);
Nate
  • 30,589
  • 12
  • 76
  • 201
WebDude
  • 5,985
  • 5
  • 31
  • 42

3 Answers3

3

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

CAMOBAP
  • 5,011
  • 8
  • 53
  • 84
Anurag Somani
  • 39
  • 1
  • 4
1

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.

Mister Smith
  • 24,695
  • 17
  • 97
  • 181
  • Can I call `flash.setMode(FlashControl.FORCE)` when player already started (I mean `Player.start()` already called)? – CAMOBAP Feb 27 '13 at 13:29
  • 1
    Yes (just checked a test project I did some time ago). – Mister Smith Feb 27 '13 at 14:06
  • `you'd probably like to have the video field hidden` how can I do this? – CAMOBAP Feb 28 '13 at 21:09
  • Either placing a field on top of it, at an absolute position (like it is described [here](http://docs.blackberry.com/es-es/developers/deliverables/29251/Displaying_field_at_absolute_position_on_screen_1603057_11.jsp)) or pushing it offscreen, or drawing directly on top of it. – Mister Smith Mar 04 '13 at 08:19
  • @CAMOBAP, I don't think either of those solutions will work (placing field on top, or using `AbsoluteFieldManager`), unfortunately. I think the `VideoControl` is smart enough to know when it's instantiated, but not actually visible, and will turn off the flash (even if `FlashControl.FORCE` is set). – Nate Mar 06 '13 at 06:58
  • @Nate If nothing does the trick, I think in OS 7.0 it should be possible to paint a full-screen-size overlay on top with [´AdvancedVideoControl´](http://www.blackberry.com/developers/docs/7.0.0api/net/rim/device/api/media/control/AdvancedVideoControl.html#USE_GUI_ADVANCED) – Mister Smith Mar 06 '13 at 09:14
  • I have tried it. But flash is coming for a while only. Like in Android, it will come for long time. – Arindam Mukherjee May 08 '13 at 14:37
0

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;
Nate
  • 30,589
  • 12
  • 76
  • 201
Tariq
  • 9,514
  • 11
  • 55
  • 97