There is a way to check if the Bluetooth is turned on and if not, then alert the user? Thank you!
There is a way to check if the Bluetooth is turned on and if not, then alert the user? Thank you!
Try this:
Installation: npm install react-native-bluetooth-status --save
Link this plugin: react-native link react-native-bluetooth-status
import: import { BluetoothStatus } from 'react-native-bluetooth-status';
Check Bluetooth turn on or turn off code :
BluetoothStatus.state() is return boolean . if return true the bluetooth is ON if return false the bluetooth is OFF
componentDidMount()
{
this.checkInitialBluetoothState();
}
async checkInitialBluetoothState()
{
const isEnabled = await BluetoothStatus.state();
console.log("check bluetooth on or off", isEnabled);
if(isEnabled == true){
Alert.alert(
'Bluethooth',
'Bluetooth is turn on'
);
} else{
Alert.alert(
'Bluethooth',
'Bluetooth is turn off'
);
}
}