6

我是 BlackBerry 应用程序开发的新手,并试图制作一个简单的应用程序来打开我的手电筒作为手电筒。我知道已经有几个应用程序可以做到这一点,但我想尝试自己做。

我已经安装了 eclipse 和所有必要的插件来让我的开发环境运行。我还成功地创建了股票标准 hello world 应用程序。

然而,我正在努力找出如何做到这一点。我一直在阅读 API 文档并开始使用FlashControl,VideoControlSnapshotControl.
然而,这些似乎并没有公开执行此操作的方法。

我知道通过摄像机我可以选择选项并打开闪光灯,这正是我想要模仿的。

到目前为止我使用的似乎只是将相机闪光灯设置为强制打开的代码是:

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);
4

3 回答 3

3

我已经解决了与闪光控制相关的问题

根据我在我最近的应用程序上使用闪存控制

相机。

这是我使用的代码:

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);
    }
}

这个逻辑与我的同事 Pinkesh 同时实现

在公司

于 2011-08-04T08:54:30.197 回答
1

OS 5.0 中提供的FlashControl类允许您打开闪存。只需使用 FORCE 标志在播放器上设置闪光控制:

FlashControl flash = (FlashControl)player.getControl("javax.microedition.amms.control.camera.FlashControl");
if(flash!=null) {
    try {
        flash.setMode(FlashControl.FORCE);
    } catch(IllegalArgumentException iae){}         
}

为此,您可能需要打开播放器来录制视频或拍照。为简洁起见,我没有在我的代码中显示这一点,但在这里你可以阅读教程。如果您的应用程序只是关于打开闪光灯,您可能希望隐藏视频字段。

于 2013-02-25T10:38:44.607 回答
0

尝试这样的事情

LED.setState(LED.STATE_ON);     // for LED
Backlight.enable(true);         // for Screen
this.setMode(FlashControl.ON);  // for flash light.

或者导入这个包

package lsphone.flash.microfireps;
于 2010-11-30T12:44:03.430 回答