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)
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)
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.");
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.
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) {
}
}