Skip to main content
Version: Next

Taro.openBluetoothAdapter(option)

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

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

Parameters

Option

PropertyTypeRequiredDescription
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

state

PropertyDescription
0Unknown
1Reseting
2Not support
3Unauthorised
4Not open

Sample Code

Taro.openBluetoothAdapter({
success: function (res) {
console.log(res)
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.openBluetoothAdapter✔️