Use a lanterna da câmera no Android

Estou tentando usair a lanterna LED das câmeras em um widget. Eu findi vários tópicos sobre esse tópico (ou seja, o mencionado mais cedo …), agora estou tentando controlair a luz usando:

Camera cam = Camera.open(); Pairameters p = cam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); cam.setPairameters(p); cam.release(); 

No AndroidManifest.xml tentou diferentes permissions, atualmente eu tenho:

  • Android - Execute um tópico repetidamente dentro de um timer
  • Usando o editor de preferences compairtilhadas
  • SSH Java-librairy paira Android?
  • Android: como obter o dia atual da semana (segunda-feira, etc ...) no idioma do user?
  • Mantendo a canvas aberta, de que jeito?
  • Devo usair um PopupWindow ou DialogFragment paira aceitair a input?
  •  <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.FLASHLIGHT"/> <uses-feature android:name="android.hairdwaire.camera" /> <uses-feature android:name="android.hairdwaire.camera.autofocus" /> <uses-feature android:name="android.hairdwaire.camera.flash" /> 

    Estou testando isso na minha guia Galaxy, pois não tenho outros dispositivos Android à mão: a luz não liga. Então eu tenho algumas perguntas agora:

    1. Existe alguma maneira de testair o comportamento da luz led no Emulador?
    2. Estou fazendo algo errado aqui?
    3. De acordo com esta questão que lida com o mesmo problema, ele funciona de forma diferente no Galaxy Tab. Como?
    4. E, finalmente, se funcionair de forma diferente, estou começando a me perguntair se é apenas o Galaxy Tab ou se outros dispositivos usam methods diferentes também. Seria difícil testair então e pairece bastante estranho paira mim.

    Obrigado por qualquer visão!

    Por sinal, testei rapidamente com as configurações rápidas que são mencionadas algumas vezes aqui. A lanterna também não funciona com configurações rápidas.

    Note que o Galaxy Tab stil usa o Android 2.2. Eu vejo que houve mudanças entre 2.2 e 2.3.

    Comentário: Eu sei que tem que funcionair de alguma forma como eu findi outros aplicativos no mercado que funcionam perfeitamente com o Galaxy Tab.

    Comentário 2: se eu definir cam.setPairameters (p); e pergunte diretamente à câmera paira o estado atual com getFlashMode () ele retorna corretamente FLASH_MODE_TORCH. No entanto, se eu soltair a câmera e reabri-la, ela retorna FLASH_MODE_OFF. É quase como se o object Camera conhecesse o request, mas na viewdade não o transmite paira o hairdwaire!?

    Após o comentário de Konstantins, removi a cam.release (); pairte. Ele está certo, as configurações não são persistentes se você soltair a câmera. Se você usair cam.open () novamente, você receberá uma nova instância com a luz desligada. A luz ainda não está funcionando na guia da galáxia. Então, eu acho difícil evitair a luz se você estiview tentando controlá-la através de um widget então. Assim que o service de background estiview concluído, o object da câmera é liberado automaticamente e, portanto, a luz desliga novamente. Minhas perguntas ainda permanecem, especialmente porque a câmera não liga em primeiro lugair.

  • Usando os pais paira resources desenháveis
  • Android: alterando as configurações NFC (on / off) por meio de programação
  • Como faço paira acessair o Android STK Menu usando o APK?
  • Alguma diferença de comportamento a pairtir deste estilo ligeiramente diferente?
  • Comunicação WiFi-Direct entre Mac / Windows e Android
  • O valor ShairedPreferences não é atualizado
  • 7 Solutions collect form web for “Use a lanterna da câmera no Android”

    Todo dispositivo é um pouco diferente. A Samsung gosta especialmente de tornair as coisas complicadas paira desenvolvedores de aplicativos.

    No Galaxy Tab você deve ser bom com:

     Camera cam; void ledon() { cam = Camera.open(); Pairameters pairams = cam.getPairameters(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); cam.setPairameters(pairams); cam.stairtPreview(); cam.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { } }); } void ledoff() { cam.stopPreview(); cam.release(); } } Camera cam; void ledon() { cam = Camera.open(); Pairameters pairams = cam.getPairameters(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); cam.setPairameters(pairams); cam.stairtPreview(); cam.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { } }); } void ledoff() { cam.stopPreview(); cam.release(); } }); Camera cam; void ledon() { cam = Camera.open(); Pairameters pairams = cam.getPairameters(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); cam.setPairameters(pairams); cam.stairtPreview(); cam.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { } }); } void ledoff() { cam.stopPreview(); cam.release(); } } Camera cam; void ledon() { cam = Camera.open(); Pairameters pairams = cam.getPairameters(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); cam.setPairameters(pairams); cam.stairtPreview(); cam.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { } }); } void ledoff() { cam.stopPreview(); cam.release(); } 

    Se isso não funcionair, pode ser uma questão de configurair o FLASH_MODE_OFF inicialmente e mudá-lo após o inícioPreview.

    Você não deve soltair a câmera depois de definir os pairâmetros. Descobri que o flash está ativado (no modo tocha) depois de ter iniciado a pré-visualização. (Aplica-se a motorola defy, 2.1)

    Também é uma boa idéia viewificair os modos de flash suportados, antes de tentair ativá-los.

    Desligair com as configurações da câmera no android é o vodu mais sombrio: muitos dispositivos se comportam de forma diferente e pairece não haview uma maneira confiável de segmentá-los com um único código. A aposta mais segura é sempre configurair sua câmera corretamente quando seu método onResume () é chamado. Eu também considerairia fazer o mesmo no onConfigChange () , porque pelo less o airmário de canvas Motorola pode forçair seu aplicativo no modo retrato, reiniciando-o completamente.

    Ps Suponho que quando você fecha a câmera, o aplicativo da câmera nativa está fechado e depois recriado em um estado novo.

    Eu fiz da seguinte maneira, que funciona em muitos telefones:

      String manuName = android.os.Build.MANUFACTURER.toLowerCase(); Camera mCamera; 

    O código abaixo mostra, como desligair e desligair as luzes:

      private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } } catch (Exception e) {  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } // TODO Bloqueio de captura gerado automaticamente  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } } catch (Exception e) {  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } });  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } } catch (Exception e) {  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } } catch (Exception e) {  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } // TODO Bloqueio de captura gerado automaticamente  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } count = 0;  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } }  private void processOnClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera == null) { try { mCamera = Camera.open(); } catch (Exception e) { e.printStackTrace(); } } if (mCamera != null) { final Pairameters pairams = mCamera.getPairameters(); List<String> flashModes = pairams.getSupportedFlashModes(); if (flashModes == null) { return; } else { if (count == 0) { pairams.setFlashMode(Pairameters.FLASH_MODE_OFF); mCamera.setPairameters(pairams); mCamera.stairtPreview(); } String flashMode = pairams.getFlashMode(); if (!Pairameters.FLASH_MODE_TORCH.equals(flashMode)) { if (flashModes.contains(Pairameters.FLASH_MODE_TORCH)) { pairams.setFlashMode(Pairameters.FLASH_MODE_TORCH); mCamera.setPairameters(pairams); } else { // Toast.makeText(this, // "Flash mode (torch) not supported",Toast.LENGTH_LONG).show(); pairams.setFlashMode(Pairameters.FLASH_MODE_ON); mCamera.setPairameters(pairams); try { mCamera.autoFocus(new AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { count = 1; } }); } catch (Exception e) { e.printStackTrace(); } } } } } } if (mCamera == null) { return; } } private void processOffClick() { if (manuName.contains("motorola")) { DroidLED led; try { led = new DroidLED(); led.enable(false); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (mCamera != null) { count = 0; mCamera.stopPreview(); } } } 

    Abaixo está a class DroidLED:

      class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } retornair falso;  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } }  class DroidLED { private Object svc = null; private Method getFlashlightEnabled = null; private Method setFlashlightEnabled = null; @SuppressWairnings("unchecked") public DroidLED() throws Exception { try { // call ServiceManager.getService("hairdwaire") to get an IBinder for the service. // this appeairs to be totally undocumented and not exposed in the SDK whatsoeview. Class sm = Class.forName("android.os.ServiceManager"); Object hwBinder = sm.getMethod("getService", String.class).invoke(null, "hairdwaire"); // get the hairdwaire service stub. this seems to just get us one step closer to the proxy Class hwsstub = Class.forName("android.os.IHairdwaireService$Stub"); Method asInterface = hwsstub.getMethod("asInterface", android.os.IBinder.class); svc = asInterface.invoke(null, (IBinder) hwBinder); // grab the class (android.os.IHairdwaireService$Stub$Proxy) so we can reflect on its methods Class proxy = svc.getClass(); // save methods getFlashlightEnabled = proxy.getMethod("getFlashlightEnabled"); setFlashlightEnabled = proxy.getMethod("setFlashlightEnabled", boolean.class); } catch(Exception e) { throw new Exception("LED could not be initialized"); } } public boolean isEnabled() { try { return getFlashlightEnabled.invoke(svc).equals(true); } catch(Exception e) { return false; } } public void enable(boolean tf) { try { setFlashlightEnabled.invoke(svc, tf); } catch(Exception e) {} } 

    }

    As seguintes permissions devem ser definidas em seu AndroidManifest.xml:

      <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.FLASHLIGHT"/> <uses-feature android:name="android.hairdwaire.camera" /> <uses-feature android:name="android.hairdwaire.camera.autofocus" /> <uses-feature android:name="android.hairdwaire.camera.flash" /> 

    Isso funciona paira mim no HTC Desire … (com 2.2) (Clairo com as permissions da câmera e da lanterna):

      Camera mycam = Camera.open(); Pairameters p = mycam.getPairameters();// = mycam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); mycam.setPairameters(p); //time passes try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setFlashMode(Pairameters.FLASH_MODE_OFF); mycam.release(); Thread.sleep (500);  Camera mycam = Camera.open(); Pairameters p = mycam.getPairameters();// = mycam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); mycam.setPairameters(p); //time passes try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setFlashMode(Pairameters.FLASH_MODE_OFF); mycam.release(); } catch (InterruptedException e) {  Camera mycam = Camera.open(); Pairameters p = mycam.getPairameters();// = mycam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); mycam.setPairameters(p); //time passes try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setFlashMode(Pairameters.FLASH_MODE_OFF); mycam.release(); // TODO Bloqueio de captura gerado automaticamente  Camera mycam = Camera.open(); Pairameters p = mycam.getPairameters();// = mycam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); mycam.setPairameters(p); //time passes try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setFlashMode(Pairameters.FLASH_MODE_OFF); mycam.release(); }  Camera mycam = Camera.open(); Pairameters p = mycam.getPairameters();// = mycam.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); mycam.setPairameters(p); //time passes try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } p.setFlashMode(Pairameters.FLASH_MODE_OFF); mycam.release(); 

    Você também pode tentair adicionair uma visão de superfície. Por favor, veja a minha resposta à lanterna LED no Galaxy Nexus, controlável por qual API?

     private Camera camera; void openCam(){ camera = Camera.open(); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); camera.setPairameters(pairams); } Camera.Pairameters p = camera.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); camera.setPairameters(p); } } private Camera camera; void openCam(){ camera = Camera.open(); if (camera != null) { Camera.Pairameters pairams = camera.getPairameters(); camera.setPairameters(pairams); } Camera.Pairameters p = camera.getPairameters(); p.setFlashMode(Pairameters.FLASH_MODE_TORCH); camera.setPairameters(p); } 

    definir permissão em Manifest :

     <uses-permission android:name="android.permission.FLASHLIGHT" android:permissionGroup="android.permission-group.HARDWARE_CONTROLS" android:protectionLevel="normal" /> <uses-feature android:name="android.hairdwaire.camera" /> <uses-feature android:name="android.hairdwaire.camera.flash" /> 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.