Turn on Flash as Light on Blackberry
Asked Answered
G

3

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);
Garretson answered 23/11, 2010 at 8:9 Comment(0)
P
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

Prurient answered 4/8, 2011 at 8:54 Comment(2)
and I get you +50 for answer improvementYearning
Why are you initializing flashControl whith a dummy object?Skit
S
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.

Skit answered 25/2, 2013 at 10:38 Comment(7)
Can I call flash.setMode(FlashControl.FORCE) when player already started (I mean Player.start() already called)?Yearning
Yes (just checked a test project I did some time ago).Skit
you'd probably like to have the video field hidden how can I do this?Yearning
Either placing a field on top of it, at an absolute position (like it is described here) or pushing it offscreen, or drawing directly on top of it.Skit
@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).Ballarat
@Ballarat 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´Skit
I have tried it. But flash is coming for a while only. Like in Android, it will come for long time.Indignity
T
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;
Topsyturvydom answered 30/11, 2010 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.