title: Taro.openBluetoothAdapter(option)

sidebar_label: openBluetoothAdapter

Initializes the Bluetooth module.

Notes

  • Other Bluetooth-related APIs can only be used after Taro.openBluetoothAdapter is called. Otherwise, the API will return an error (errCode=10000).
  • When the user’s Bluetooth switch is off or the phone does not support Bluetooth, calls to Taro.openBluetoothAdapter will return an error (errCode=10001). This indicates the phone’s Bluetooth feature is unavailable. In such cases, after initializing the Mini Program Bluetooth module, you can use Taro.onBluetoothAdapterStateChange to listen on changes to the phone’s Bluetooth status. You can also call all Bluetooth module APIs.

Reference

Type

  1. (option?: Option) => Promise<CallbackResult>

Parameters

Option

Property Type Required Description
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

state

Property Description
0 Unknown
1 Reseting
2 Not support
3 Unauthorised
4 Not open

Sample Code

  1. Taro.openBluetoothAdapter({
  2. success: function (res) {
  3. console.log(res)
  4. }
  5. })

API Support

API WeChat Mini-Program H5 React Native
Taro.openBluetoothAdapter ✔️