I have an icon of flashlight in my react-native
application. I want to hide it if mobile device does not support flashlight or not has flashlight.
In native android we have this solution:
I have an icon of flashlight in my react-native
application. I want to hide it if mobile device does not support flashlight or not has flashlight.
In native android we have this solution:
use this npm package.
if the device won't have torch than the below code will throw exception and catch block will be executed and thus you will get to know whether the device has torch or not
try {
await Torch.switchState(newTorchState);
this.setState({ isTorchOn: newTorchState });
}
catch (e) {
ToastAndroid.show(
'We seem to have an issue accessing your torch',
ToastAndroid.SHORT
);
}