最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

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

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.

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

Share asked Mar 5 at 18:44 AllxieAllxie 5874 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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/package/react-native-bluetooth-state-manager

发布评论

评论列表(0)

  1. 暂无评论