When Trying Turn Off Camera Led, App Crash
i have a code @TargetApi(23) private void setTorchMode( CameraManager cameraManager, String id, boolean switchOn) throws CameraAccessException { try { final M
Solution 1:
On some devices, if a flashlight is disabled and you try to disable it again, an app is crashed. So the solution is only to switch the state of the flashlight.
Solution 2:
public void turnOnFlashLight() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mCameraManager.setTorchMode(mCameraId, true);
mTorchOnOffButton.setImageResource(R.drawable.on);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void turnOffFlashLight() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mCameraManager.setTorchMode(mCameraId, false);
mTorchOnOffButton.setImageResource(R.drawable.off);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Post a Comment for "When Trying Turn Off Camera Led, App Crash"