4

My app turn on camera LED using FLASH_MODE_TORCH, but now some people say that FLASH_MODE_TORCH will not work on some Samsung devices correctly.

So should I use FLASH_MODE_ON for all devices to work?(especially for Samsung devices)

Mehrdad Salimi
  • 1,400
  • 4
  • 16
  • 31

3 Answers3

5

may be this will help you

    Parameters params = null;


if(mCamera != null) {
params = mCamera.getParameters();

if(params != null) {
List<String> supportedFlashModes = params.getSupportedFlashModes();

if(supportedFlashModes != null) {

if(supportedFlashModes.contains(Parameters.FLASH_MODE_TORCH)) {
params.setFlashMode( Parameters.FLASH_MODE_TORCH );
} else if(supportedFlashModes.contains(Parameters.FLASH_MODE_ON)) {
params.setFlashMode( Parameters.FLASH_MODE_ON );
} else mCamera = null;



} else Log.d(TAG, "Camera is null.");


if(mCamera != null) {
Log.d(TAG, "Flash disponibile (" + params.getFlashMode() + ")");
 mCamera.setParameters( params );
mCamera.startPreview();
mCamera.autoFocus(null);

} else Log.d(TAG, "Camera is null.");
Dhwanik Gandhi
  • 685
  • 6
  • 12
  • 1
    I am using this code now, it works for most of devices well, but it doesn't work for some Samsung devices like Galaxy Ace. I want to know that will 'Flash_mode_on' work on all devices? – Mehrdad Salimi Apr 28 '14 at 09:23
  • You helped me a lot. I will mark it as an accepted answer when I test it on some more devices. Thanks, – Mehrdad Salimi Apr 28 '14 at 10:36
1

There is no single way to make sure the flash works on every device. You have to add a lot of code that is specific of the manufacturer and the device.

Dwhanik's answer is how I would handle the specific problem you are talking about. Check for FLASH_MODE_TORCH first and then try FLASH_MODE_ON. But this does not mean that you will get a flash on every device.

jbutewicz
  • 26
  • 3
0
public void Initialize(){
    if (this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
        camManager = (CameraManager) getSystemService(this.CAMERA_SERVICE);
        try {
            if (camManager.getCameraIdList().length > 0) {
                strCameraID=camManager.getCameraIdList()[0];
            }
        } catch (Exception EX_CAMLIST) {
        }
    }
}
public void switchLED(String strCemeraID,boolean status){
    if(camManager==null || strCemeraID==null)return;
    try {
        if (strCemeraID.length() > 0) {
            camManager.setTorchMode(strCemeraID, status);
        }
    } catch (Exception EX_CAMERA_TORCH) {
    }
}