2010-11-23 30 views
6

我是黑莓應用程序開發的新手,並試圖做一個簡單的應用程序來將我的手電筒作爲手電筒。我知道有幾個應用程序已經這樣做了,但我想嘗試自己做。打開閃光燈作爲黑莓上的光

我已經安裝了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); 

回答

0

嘗試是這樣的

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

否則導入這個包

package lsphone.flash.microfireps; 
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在the公司

+0

可否請您提供「Camera」類的完整代碼? – CAMOBAP 2013-02-21 12:41:42

+0

,我爲你解答+50問題 – CAMOBAP 2013-02-21 12:49:03

1

FlashControl類實現爲我的同事

,購自OS 5.0允許你打開閃光燈。只需設置您的播放器與FORCE標誌閃光燈控制:

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

對於這個工作,你可能需要打開一個播放器來錄製視頻或拍照。爲了簡潔起見,我沒有在代碼中顯示該代碼,但您可以閱讀教程here。如果您的應用只是關於開啓閃光燈,您可能希望隱藏視頻領域。