androidreact-nativebluetoothnavigationsettings

Navigate to bluetooth toggle settings screen on android directly with react native


I have an application with bluetooth and sometimes need to help users turn on their bluetooth. The user must go to settings on their android > Connected devices > Connection preferences > Bluetooth... and then they can finally toggle their bluetooth on.

I've added an alert into the app which the user can press to take them to the "BLUETOOTH_SETTINGS" menu.

Linking.sendIntent("android.settings.BLUETOOTH_SETTINGS");

Unfortunately, this takes the user to the equivalent of the settings > Connected devices screen (see below), and the user still has to click two menus deeper to get to the actual bluetooth toggle.

Connected Devices Screen

The Android documentation here only has "BLUETOOTH_SETTINGS." How might a person programmatically send the user directly to this nested toggle screen (below)?

Bluetooth Toggle Screen


Solution

  • Instead of navigating to the settings screen, you can disable or enable bluetooth programmatically.

    If it suits your needs, you can display a button or a switch which will toggle the state of bluetooth using a library like react-native-bluetooth-state-manager this way:

    import BluetoothStateManager from 'react-native-bluetooth-state-manager';
    import { PermissionsAndroid } from "react-native";
    
    
    
    // Enable bluetooth
    const enable = () => {
       const permission = await PermissionsAndroid.request(
            "android.permission.BLUETOOTH_CONNECT"
          );
       if (permission === "granted") {
         BluetoothStateManager.enable().then((result) => {});
       }
    };
    
    
    // Disable bluetooth
    const disable= () => BluetoothStateManager.disable().then((result) => {});
    

    Check out the complete documentation for react-native-bluetooth-state-manager here: https://www.npmjs.com/package/react-native-bluetooth-state-manager