For this problem you should:
-
Check whether the flashlight is available or not.
-
If so then Turn Off/On
-
If not then you can do whatever, according to your app needs.
To determine whether the device has flash:
You can use the following:
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
This will return true in the presence of a flash and false otherwise.