androidreact-nativebluetoothbluetooth-lowenergyreact-native-ble-plx

How to turn on bluetooth of mobile by using react-native-ble-plx?


My mobile app has functionality to turn on Bluetooth of mobile and show list of Bluetooth devices on the screen. I am using react-native-ble-plx lib for achieving this functionality. I need to turn on BLE of mobile by using react-native-ble-plx lib. Any method is available in that lib for turn on BLE?


Solution

  • react-native-ble-plx does not have this functionality but you can use react-native-bluetooth-state-manager. It allows you to read the current bluetooth state (enabled/disabled) and open the bluetooth settings page on iOS and android. It is even possible to enable (and disable) bluetooth on android without user interaction but you have to add the BLUETOOTH_ADMIN permission to you manifest.

    But I would suggest you do not activate Bluetooth without user interaction. Simply check the state and show a message like

    Bluetooth is required to use this app. Please activate it trough your settings

    Only allow the usage of the rest of the app after bluetooth got enabled. A user is probably confused if he deactivated bluetooth and it is suddenly activated.