2

Is there any way to check once you have tried to turn the flashlight on if it has worked or not?

I'm using:

p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();

To turn the camera on. This works with most phones, but not with all phones so I need to know if it's worked or not.

Edit: Just to be clear, I need to know if turning the flash on has actually worked or not. Sometimes you need to use FLASH_MODE_ON instead of FLASH_MODE_TRUE, and sometimes you need to use FLASH_MODE_ON even when

List<String> flashModes = p.getSupportedFlashModes();
flashModes.contains(Parameters.FLASH_MODE_TORCH)

returns true.

Thanks for any help.

Dirk
  • 10,668
  • 2
  • 35
  • 49
BlueJam
  • 43
  • 1
  • 7
  • check out this, http://stackoverflow.com/questions/6068803/how-turn-on-camera-flash-light-programmatically-in-android – InnocentKiller Feb 24 '14 at 11:13
  • hi the answer is given please have a look and visit http://www.androidhive.info/2013/04/android-developing-flashlight-application/ for more – Jitesh Upadhyay Feb 24 '14 at 11:19
  • @InnocentKiller Thanks, I have looked at that link before, but I can't see a way there that lets you know if turning the light on has worked or not. – BlueJam Feb 24 '14 at 11:21
  • @Jitesh Upadhyay Thanks for the reply but please read my question, I asked if there is any way to check if turning the light on actually worked or not. – BlueJam Feb 24 '14 at 11:24
  • yeah !! i deleted the previous answer, will try to get and willl be back to you – Jitesh Upadhyay Feb 24 '14 at 11:26
  • Thanks, I've been looking for a solution for a while and just can't find anything. Just to make it clear to anyone else I need a way to check if the torch has actually turned on or not as FLASH_MODE_TORCH doesn't work with all phones. When it doesn't work the torch just doesn't turn on. This is sometimes the case even when flashModes.contains(Parameters.FLASH_MODE_TORCH) comes back as true. – BlueJam Feb 24 '14 at 11:32

2 Answers2

1

First you need to check if the device supports flashlight:

context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);

Then you can safely assume that it will be turned on when you start preview.

Niko
  • 8,093
  • 5
  • 49
  • 85
0

Works for me:

camera.getParameters().getFlashMode().equals(Parameters.FLASH_MODE_TORCH)

Returns true flashlight is on

Note: Camera class has been deprecated in API level 21. so this solution won't work for recent versions

Khaled AbuShqear
  • 1,230
  • 14
  • 24