Device
# Power
# getBatteryInfoSync
getBatteryInfoSync()
ft.get a synchronized version ofBatteryInfo
Return Value
Object res
| Properties | Type | Description |
|---|---|---|
| level | string | Device power, ranging from 1 - 100 |
| isCharging | boolean | Whether the |
# getBatteryInfo
getBatteryInfo(Object object)
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object object
| Properties | Type | Description |
|---|---|---|
| level | string | Device power, ranging from 1 - 100 |
| isCharging | boolean | Whether the |
# Clipboard
# setClipboardData
Base Library 1.3.9 started support, iOS version 2.1.23, Android version 2.1.38, dependency extension SDK since iOS version 2.35.13, Android 2.35.9, the API requires host app injection implementation, the SDK has been removed.
setClipboardData(Object object)
Sets the contents of the system clipboard.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| data | string | Yes | The contents of the clipboard are | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# getClipboardData
Base Library 1.3.9 started support, iOS version 2.1.23, Android version 2.1.38, dependency extension SDK since iOS version 2.35.13, Android 2.35.9, the API requires host app injection implementation, the SDK has been removed.
getClipboardData(Object object)
Gets the contents of the system clipboard.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object object
| Properties | Type | Description |
|---|---|---|
| data | string | The contents of the clipboard are |
Sample Code
# Network
# onNetworkStatusChange
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
onNetworkStatusChange(function callback)
Listen for network state change events.
Parameters
function callback
A callback function for network state change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| isConnected | boolean | Whether there is currently a network connection |
| networkType | string | Network Type |
The legal value of res.networkType
| The value | Description |
|---|---|
| wifi | Wifi network |
| 2g | 2G network |
| 3g | 3G network |
| 4g | 4G network |
| unknown | Wifi network |
| none | No network |
Sample Code
# offNetworkStatusChange
offNetworkStatusChange(function callback)
Cancel listening for network state change events, and if the parameter is empty, cancel all event listening.
Parameters
function callback
A callback function for network state change events
# getNetworkType
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
getNetworkType(Object object)
Gets the network type.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| networkType | string | Network Type |
Legal value for res.networkType
| The value | Description |
|---|---|
| wifi | Wifi network |
| 2g | 2G network |
| 3g | 3G network |
| 4g | 4G network |
| unknown | Wifi network |
| none | No network |
Sample Code
# screen
# setScreenBrightness
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
setScreenBrightness(Object object)
Set the screen brightness.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| value | number | Yes | Screen brightness value, ranging from 0 to 1. 0 Darkest, 1 Brightest | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# setKeepScreenOn
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
setKeepScreenOn(Object object)
Sets whether to stay on.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| keepScreenOn | boolean | Yes | Whether to keep the screen on | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# onUserCaptureScreen
onUserCaptureScreen(function callback)
Listen for user active screenshot events. Triggered when the user takes a screenshot using the system screenshot button, only one listener can be registered
Parameters
function callback
A callback function for a user active screenshot event
Sample Code
# offUserCaptureScreen
offUserCaptureScreen(function callback)
User active screenshot events. Cancels event listening.
Parameters
function callback
A callback function for a user active screenshot event
# getScreenBrightness
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
getScreenBrightness(Object object)
Gets the screen brightness.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object object
| Properties | Type | Description |
|---|---|---|
| value | number | Screen brightness values, ranging from 0 to 1, 0 darkest, 1 brightest |
# Keyboard
# onKeyboardHeightChange
onKeyboardHeightChange(function callback)
Listen for keyboard height changes
Parameters
function callback
Parameters
object res
| Properties | Type | Description |
|---|---|---|
| height | number | Keyboard height |
Sample Code
# offKeyboardHeightChange
offKeyboardHeightChange(function callback)
Cancels listening for keyboard height change events
Parameters
function callback
A callback function for the keyboard height change event
# hideKeyboard
hideKeyboard(Object object)
After the keyboard is pulled up by focus such as input, textarea, etc., manually call this interface to collapse the keyboard
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
getSelectedTextRange(Object object)
After the input, textarea, and so on, get the cursor position of the input box. Note: This interface is only valid if called at focus.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| start | number | Enter the box cursor start position |
| end | number | The input box cursor ends at |
Sample Code
# Phone
# makePhoneCall
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
makePhoneCall(Object object)
Dial number.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| phoneNumber | string | Yes | The phone number that needs to be dialed | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# Accelerometer
# stopAccelerometer
stopAccelerometer(Object object)
Stop listening for acceleration data.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# startAccelerometer
startAccelerometer(Object object)
Start listening for acceleration data.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| interval | string | normal | No | The frequency of execution of the listening acceleration data callback function |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.interval
| The value | Description |
|---|---|
| game | The callback frequency for updating the game is around 20ms/time |
| ui | The callback frequency for updating the UI is around 60ms/ |
| normal | The ordinary callback frequency is around 200ms/time |
Sample Code
# onAccelerometerChange
onAccelerometerChange(function callback)
Listen for acceleration data events. According to the interval parameter of ft.startAccelerometer(), the listening will automatically start after the interface is called.
Parameters
function callback
Callback function for acceleration data events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| x | number | X-axis |
| y | number | Y axis |
| z | number | Z-axis |
Sample Code
# offAccelerometerChange
offAccelerometerChange(function callback)
Cancels listening for acceleration data events, and if the parameter is empty, cancels all event listening.
Parameters
function callback
Callback function for acceleration data events
# Compass
# stopCompass
stopCompass(Object object)
Stop listening for compass data
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# startCompass
startCompass(Object object)
Start listening for compass data
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Sample Code
# onCompassChange
onCompassChange(function callback)
Listen for compass data change events. Frequency: 5 times/sec, the listening will start automatically after the interface is called, and the listening can be stopped by using ft.stopCompass.
Parameters
function callback
A callback function for compass data change events
Parameters
Object object
| Properties | Type | Description |
|---|---|---|
| direction | number | The degree of direction faced is |
| accuracy | number/string | Accuracy |
Sample Code
Accuracy Differences in iOS/Android
Due to platform differences, accuracy values differ on iOS/Android.
- iOS:accuracy is a number type value that represents a deviation from the magnetic north pole. 0 means the device points to magnetic north, 90 points east, 180 points south, and so on.
- Android:accuracy is an enumeration value of type string.
| The value | Description |
|---|---|
| high | High precision |
| medium | Medium accuracy |
| low | Low precision |
| no-contact | Not trusted, sensor lost connectivity |
| unreliable | Not credible, unknown cause |
| unknow ${value} | The unknown precision enumeration value, that is, the value returned by the Android system at this time representing the precision is not a standard precision enumeration value |
# offCompassChange
offCompassChange(function callback)
Cancel the listening for compass data change events, and if the parameter is empty, cancel all event monitoring.
Parameters
function callback
A callback function for compass data change events
# Device orientation
# stopDeviceMotionListening
stopDeviceMotionListening(Object object)
Stops listening for changes in device orientation.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# startDeviceMotionListening
startDeviceMotionListening(Object object)
Start listening for changes in device orientation.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| interval | string | normal | No | The frequency at which the callback function that listens for changes in the direction of the device is |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.interval
| The value | Description |
|---|---|
| game | The callback frequency for updating the game is around 20ms/time |
| ui | The callback frequency for updating the UI is around 60ms/ |
| normal | The ordinary callback frequency is around 200ms/time |
# onDeviceMotionChange
onDeviceMotionChange(function callback)
Listen for device orientation change events. The frequency is based on the interval parameter of ft.startDeviceMotionListening(). You can use ft.stopDeviceMotionListening() to stop listening.
Parameters
function callback
A callback function for device orientation change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| alpha | number | When the phone coordinates X/Y and Earth X/Y coincide, the angle of rotation around the Z axis is alpha and the range value is [0, 2*PI). Turn counterclockwise to positive. |
| beta | number | When the phone coordinates Y/Z coincide with the Earth Y/Z, the angle of rotation around the X axis is beta. The range value is [-1*PI, PI). The top rotates positive toward the earth's surface. It is also possible to be positive towards the user. |
| gamma | number | When the phone X/Z and earth X/Z coincide, the angle around the Y axis is gamma. The range value is [-1*PI/2, PI/2). The right side rotates positive toward the earth's surface. |
# offDeviceMotionChange
offDeviceMotionChange(function callback)
Cancels the listening device direction change event, and if the parameter is empty, cancels all event listening.
Parameters
function callback
A callback function for device orientation change events
# Gyroscope
# stopGyroscope
stopGyroscope(Object object)
Stop listening for gyroscope data.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# startGyroscope
startGyroscope(Object object)
Start listening for gyroscope data.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| interval | string | normal | No | The execution frequency of the listening gyroscope data callback function |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
legal value for object.interval
| The value | Description |
|---|---|
| game | The callback frequency for updating the game is around 20ms/time |
| ui | The callback frequency for updating the UI is around 60ms/ |
| normal | The ordinary callback frequency is around 200ms/time |
# onGyroscopeChange
onGyroscopeChange(function callback)
Listen for gyroscope data change events. The frequency is based on the interval parameter of ft.startGyroscope(). You can use ft.stopGyroscope() to stop listening.
Parameters
function callback
Callback function for gyroscope data change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| x | number | The angular velocity of the x-axis is |
| y | number | The angular velocity of the y-axis is |
| z | number | The angular velocity of the z-axis is |
# offGyroscopeChange
offGyroscopeChange(function callback)
Cancels listening for gyroscope data change events.
Parameters
function callback
Callback function for gyroscope data change events
# Scan the code
# scanCode
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
scanCode(Object object)
Turn up the client scan code interface to scan the code.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| onlyFromCamera | boolean | false | No | Whether you can only scan the code from the camera, do not allow you to select pictures from the album |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The interface calls the failed callback function (returns an error message when authorization fails: fail unauthorized user did not grant camera permissions) | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
Sample Code
note
- Interface Authorization Failed (iOS):
- The user refuses authorization and returns an error message: unauthorized, the user did not grant camera permissions
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: unauthorized disableauthorized, sdk is prohibited from applying for camera permissions
- Interface authorization failed (Android):
- The user denies authorization and returns an error message: fail unauthorized The user did not grant permission to the camera
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: Unauthorized disableauthorized SDK is prohibited from initiating permission applications
# Vibration
# vibrateShort
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
vibrateShort(Object object)
Causes the phone to vibrate for a shorter period of time (15 ms). Valid only on iPhone 7 / 7 Plus and Android models.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The interface calls the failed callback function (returns an error message when authorization fails: fail unauthorized user did not grant shock permissions) | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
note
- Interface authorization failed (Android):
- When the user refuses authorization, an error message is returned: The unauthorized user has not granted the vibrate permission
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: Unauthorized disableauthorized SDK is prohibited from initiating permission applications
# vibrateLong
Base Library 1.3.9 is supported, iOS version 2.1.23, Android version 2.1.38
vibrateLong(Object object)
Causes the phone to vibrate for a long time (400 ms).
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The interface calls the failed callback function (returns an error message when authorization fails: fail unauthorized user did not grant shock permissions) | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
note
- Interface authorization failed (Android):
- When the user refuses authorization, an error message is returned: The unauthorized user has not granted the vibrate permission
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: Unauthorized disableauthorized SDK is prohibited from initiating permission applications
# Bluetooth- Universal
# stopBluetoothDevicesDiscovery
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK. Starting with 2.35.7, the Bluetooth module is self-contained and needs to rely on the NeuxnetBluetooth SDK separately
stopBluetoothDevicesDiscovery(Object object)
Stop searching for nearby Bluetooth peripherals. If you have found the required Bluetooth device and do not need to continue searching, it is recommended to call this interface to stop Bluetooth search.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# startBluetoothDevicesDiscovery
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
startBluetoothDevicesDiscovery(Object object)
Start searching for nearby Bluetooth peripherals.
This operation is more expensive system resources, please call ft.stopBluetoothDevicesDiscovery to stop the search after searching for the required device.
Parameters
Object object
| Properties | Type | The default value is | Required | illustrate |
|---|---|---|---|---|
| services | Array.string | No | A list of UUIDs for the Bluetooth device master service to search for (16/32/128-bit UUIDs are supported). Some Bluetooth devices broadcast the UUID of their own master service. If you set this parameter, only Bluetooth devices that have the primary service corresponding to the UUID are searched for broadcast packets. It is recommended that you filter out other Bluetooth devices around you that do not need to be processed. | |
| allowDuplicatesKey | boolean | false | No | Whether to allow duplicate escalations of the same device. If duplicate escalations are allowed, the onBlueToothDeviceFound method reports the same device multiple times, but the RSSI values will be different. |
| interval | number | 0 | No | The interval between reporting devices, in ms. 0 indicates that new devices are found to be reported immediately, and other values are reported according to the intervals passed in. |
| powerLevel | string | medium | No | Scan mode, the higher the scan, the faster the scan, and the more power consumption |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.powerLevel 的合法值
| The value | Description | Minimum version |
|---|---|---|
| low | Low | |
| medium | Medium | |
| high | High |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# openBluetoothAdapter
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
openBluetoothAdapter(Object object)
Initialize the Bluetooth module. When the host/slave (peripheral) mode is enabled on iOS, you need to call it once and specify the corresponding mode.
Parameters
Object object
| Properties | Type | The default value is | Required | Description | Minimum version |
|---|---|---|---|---|---|
| mode | string | central | No | Bluetooth mode, available as a master/slave device, only required by iOS. | |
| success | function | No | The interface calls the callback function successfully | ||
| fail | function | No | The callback function that failed the interface callback function | ||
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Legal value of object.mode
| The value | Description | Minimum version |
|---|---|---|
| central | Host mode | |
| peripheral | Slave (peripheral) mode |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
State argument returned by the object.fail callback function (iOS only)
| Status code | Description |
|---|---|
| 0 | Unknown |
| 1 | Reset the |
| 2 | |
| 3 | Unauthorized |
| 4 |
NOTE
- Other Bluetooth-related APIs must be used after the openBluetoothAdapter call. Otherwise the API returns an error (errCode=10000).
- In the case that the user's Bluetooth switch is not turned on or the phone does not support Bluetooth function, calling openBluetoothAdapter will return an error (errCode=10001), indicating that the bluetooth function of the phone is not available. At this time, the Mini App Bluetooth module has been initialized, and you can listen to the change of the Bluetooth state of the mobile phone through onBluetoothAdapterStateChange, and you can also call all the APIs of the Bluetooth module.
note
- Interface Authorization Failed (iOS):
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: unauthorized disableauthorized, sdk is forbidden to apply for Bluetooth permissions
# onBluetoothDeviceFound
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, depending on the extension SDK onBluetoothDeviceFound(function callback) listens for events searching for new devices
Parameters
function callback
A callback function that searches for events for a new device
Parameters
object res
| Properties | Type | Description |
|---|---|---|
| devices | Array.Object | The list of newly searched devices |
Structure of res.devices
| Properties | Type | Description |
|---|---|---|
| name | string | Bluetooth device names, some devices may not have |
| deviceId | string | Bluetooth device id |
| RSSI | number | The signal strength of the current Bluetooth device, in dBm |
| advertisData | ArrayBuffer | The ManufacturerData data segment in the broadcast data segment of the current Bluetooth device. |
| advertisServiceUUIDs | Array.string | The ServiceUUIDs data segment in the broadcast data segment of the current Bluetooth device |
| localName | string | The LocalName data segment in the broadcast data segment of the current Bluetooth device |
| serviceData | Object | The ServiceData data segment in the broadcast data segment of the current Bluetooth device |
NOTE
- If a device is called back on onBluetoothDeviceFound, the device is added to the array obtained by the getBluetoothDevices interface.
- Some models of Android need to have location permissions to search for devices, and you need to pay attention to whether location permissions are enabled
- Repeated calls overwrite previous callbacks
# onBluetoothAdapterStateChange
Base Library 2.11.2 Started Support, iOS Version 2.34.1, Android Version 2.34.1, Dependency Extension SDK onBluetoothAdapterStateChange(function callback)
Listen for Bluetooth adapter state change events
Parameters
function callback
Callback function for Bluetooth adapter state change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| available | boolean | Whether the Bluetooth adapter is available |
| discovering | boolean | Whether the Bluetooth adapter is searching for |
Note** Repeated calls overwrite previous callbacks
# offBluetoothDeviceFound
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
Cancels listening for events that find new devices.
# offBluetoothAdapterStateChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
Cancels listening for Bluetooth adapter state change events.
# makeBluetoothPair
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
makeBluetoothPair(Object object)
Bluetooth pairing interface, only Android support.
Usually (when you need to specify a pin or password), the system will take over the pairing process and directly call createBLEConnection. This interface should only be used when the developer does not want the user to manually enter the PIN code and the real machine verification confirmation can work normally
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| pin | string | Yes | pin, Base64 format. | |
| timeout | number | 20000 | No | Timeout, in ms |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# getConnectedBluetoothDevices
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
getConnectedBluetoothDevices(Object object)
Get the connected Bluetooth device based on the master service UUID.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| services | Array.string | Yes | The list of UUIDs for the Bluetooth device master service (supporting 16/32/128-bit UUIDs) | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails to execute the |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| devices | Array.Object | The list of discovered devices |
Structure of res.devices
| Properties | Type | Description |
|---|---|---|
| name | string | Bluetooth device names, some devices may not have |
| deviceId | string | The id |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# getBluetoothDevices
getBluetoothDevices(Object object)
Gets all discovered Bluetooth devices during the Bluetooth module is in effect. Includes devices that are already connected to the unit.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| devices | Array.Object | The list of connected devices corresponding to the UUID |
Structure of res.devices
| Properties | Type | Description |
|---|---|---|
| name | string | Bluetooth device names, some devices may not have |
| deviceId | string | Bluetooth device id |
| RSSI | number | The signal strength of the current Bluetooth device, in dBm |
| advertisData | ArrayBuffer | The ManufacturerData data segment in the broadcast data segment of the current Bluetooth device. |
| advertisServiceUUIDs | Array.string | The ServiceUUIDs data segment in the broadcast data segment of the current Bluetooth device |
| localName | string | The LocalName data segment in the broadcast data segment of the current Bluetooth device |
| serviceData | Object | The ServiceData data segment in the broadcast data segment of the current Bluetooth device |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# getBluetoothAdapterState
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
getBluetoothAdapterState(Object object)
Gets the native Bluetooth adapter status.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| discovering | boolean | Whether you are searching for device |
| available | boolean | Whether the Bluetooth adapter is available |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# closeBluetoothAdapter
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
closeBluetoothAdapter(Object object)
Turn off the Bluetooth module. Calling this method disconnects all established connections and frees system resources. It is recommended that after using the Bluetooth process, it is called in pairs with openBluetoothAdapter.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# Bluetooth-Low Energy Hub Device
# writeBLECharacteristicValue
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
writeBLECharacteristicValue(Object object)
Writes binary data to the Bluetooth low energy device signature value. Note: The characteristics of the device must support write for a successful call.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| serviceId | string | Yes | The Bluetooth signature corresponds to the UUID | |
| characteristicId | string | Yes | The UUID | |
| value | ArrayBuffer | Yes | The binary value corresponding to the Bluetooth device characteristic | |
| writeType | string | Yes | There are two modes for the Write Mode setting of the Bluetooth signature value, iOS Priority Write, Android Priority WriteNoResponse | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
writeType
| The legal value | Type |
|---|---|
| write | Mandatory reply write, do not support the wrong |
| writeNoResponse | Force no reply to write, do not support the wrong |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# setBLEMTU
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
setBLEMTU(Object object)
Negotiate to set the Maximum Transmission Unit (MTU) for Bluetooth Low Energy. It needs to be called after the createBLEConnection call is successful. Only Android version 5.1 or later is valid, iOS is not supported due to system limitations.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| mtu | number | Yes | Maximum transmission unit. The setting range is within the (22,512) interval, and the unit bytes | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| mtu | number | The final negotiated MTU value, which is consistent with the incoming parameters. Android client 8.0.9 starts supporting |
object.fail callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| mtu | number | The MTU value that is finally negotiated. This parameter is not available if the negotiation fails. Android client 8.0.9 is supported. |
# readBLECharacteristicValue
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
readBLECharacteristicValue(Object object)
Reads binary data for Bluetooth low energy device characteristic values. Note: The characteristics of the device must support read for a successful call.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| serviceId | string | Yes | The Bluetooth signature corresponds to the UUID | |
| characteristicId | string | Yes | The UUID | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
NOTE
- Multiple parallel calls have the possibility of failing to read.
- The information read by the interface needs to be obtained in the callback registered by the onBLECharacteristicValueChange method
# onBLEConnectionStateChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
onBLEConnectionStateChange(function callback)
Listen for Bluetooth low energy connection state change events. This includes developers actively connecting or disconnecting, device loss, abnormal disconnection, and so on
Parameters
function callback
Callback function for bluetooth low energy connection state change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| deviceId | string | Bluetooth device id |
| connected | boolean | Whether it is in the connected state |
NOTE
Repeated calls overwrite the original callback
# onBLECharacteristicValueChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
onBLECharacteristicValueChange(function callback)
Listens for feature change events for Bluetooth low energy devices. You must call the notifyBLECharacteristicValueChange interface to receive notification pushed by the device.
Parameters
function callback
Callback function for the characteristic value change event of a Bluetooth low energy device
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| deviceId | string | Bluetooth device id |
| serviceId | string | The Bluetooth signature corresponds to the UUID |
| characteristicId | string | The UUID |
| value | ArrayBuffer | The most recent value of the feature is |
NOTE
Repeated calls overwrite the original callback
# offBLEConnectionStateChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
Cancels listening for bluetooth low energy connection state change events
# offBLECharacteristicValueChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
Cancels listening for feature change events for Bluetooth low energy devices.
# notifyBLECharacteristicValueChange
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
notifyBLECharacteristicValueChange(Object object)
Enable the notify function when the characteristic value of a Bluetooth low energy device changes to subscribe to the feature. Note: The characteristics of the device must support notify or indicate for the call to succeed.
In addition, notifyBLECharacteristicValueChange must be enabled to listen for device characteristicValueChange events
Parameters
Object res
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| serviceId | string | Yes | The Bluetooth signature corresponds to the UUID | |
| characteristicId | string | Yes | The UUID | |
| state | boolean | Yes | Whether to enable the notify | |
| type | string | indication | No | Set the signature subscription type, valid values are 'notification' and 'indication' |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
NOTE
After the subscription operation is successful, the device needs to actively update the value of the feature before the onBLECharacteristicValueChange callback is triggered. On the Android platform, the writeBLECharacteristicValue interface is called immediately after the successful call to this interface, and a 10008 system error will occur on some models
# getBLEDeviceServices
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
getBLEDeviceServices(Object object)
Gets all services (services) for Bluetooth low energy devices.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device ID. You need to have established a connection | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| services | Array.Object | Device Service List |
| Structure Properties | Type | Description |
|---|---|---|
| uuid | string | The UUID for the Bluetooth device service |
| isPrimary | boolean | Whether the service is a primary service |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
getBLEDeviceRSSI(Object object)
Gets the signal strength of a Bluetooth low energy device (Received Signal Strength Indication, RSSI).
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| RSSI | Number | Signal strength, in dBm |
# getBLEDeviceCharacteristics
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
getBLEDeviceCharacteristics(Object object)
Gets all the characteristics in a service of a Bluetooth low energy device.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device ID. You need to have established a connection | |
| serviceId | string | Yes | Bluetooth service UUID. You need to call getBLEDeviceServices to get the | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| characteristics | Array.Object | Device Characteristics List |
characteristics
| Structure Properties | Type | Description |
|---|---|---|
| uuid | string | The UUID |
| properties | Object | The operation type supported by this feature is |
properties
| Structure Properties | Type | Description |
|---|---|---|
| read | boolean | Whether the feature supports the read operation |
| write | boolean | Whether the feature supports the write operation |
| notify | boolean | Whether the feature supports the notify operation |
| indicate | boolean | Whether the feature supports the indicate operation |
| writeNoResponse | boolean | Whether the feature supports no reply write operations |
| writeDefault | boolean | Whether the feature supports reply-write operations |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# createBLEConnection
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
createBLEConnection(Object object)
Connect a Bluetooth low energy device.
If the Mini App has searched for a Bluetooth device before and successfully established a connection, it can directly pass in the deviceId obtained by the previous search to directly try to connect to the device without searching again.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| timeout | number | No | The timeout period, in ms, is not filled out to indicate that the timeout will not be | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
NOTE
Make sure to make as many pairs of calles as possible to createbleConnection and closeBLEConnection interfaces. If Android repeatedly calls createBLEConnection to create a connection, it may cause the system to hold multiple connected instances of the same device, resulting in the call of closeBLEConnection can not really disconnect from the device. Bluetooth connection may be lost at any time, it is recommended to listen for onBLEConnectionStateChange callback events, when the Bluetooth device is disconnected to perform a reconnection operation on demand If you call the interface for data read and write operations on an unconnected device or a disconnected device, a 10006 error will be returned, and a reconnection operation is recommended.
# closeBLEConnection
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
closeBLEConnection(Object object)
Disconnect from the Bluetooth low energy device.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| deviceId | string | Yes | Bluetooth device id | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| -1 | already connet | The |
| 10000 | not init | The Bluetooth adapter |
| 10001 | not available | The current Bluetooth adapter is not available |
| 10002 | no device | The specified device |
| 10003 | connection fail | Connection failed |
| 10004 | no service | The specified service |
| 10005 | no characteristic | The specified feature |
| 10006 | no connection | The current connection is disconnected |
| 10007 | property not support | This operation is not supported |
| 10008 | system error | Exceptions reported by all remaining systems |
| 10009 | system not support | Android is unique to the system, and BLE |
| 10012 | operate time out | Connection timeout |
| 10013 | invalid_data | The connection deviceId is empty or the format is incorrect |
# Bluetooth- Low energy peripherals
# onBLEPeripheralConnectionStateChanged
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
onBLEPeripheralConnectionStateChanged(function callback)
Listens for current peripheral connected or disconnected events
Parameters
Object object
A callback function for the current peripheral device being connected or disconnected event
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| deviceId | String | The device ID |
| serverId | String | The UUID of the server |
| connected | Boolean | The connection currently has a status of |
# offBLEPeripheralConnectionStateChanged
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
Cancels listening for the current peripheral device being connected or disconnected events
# createBLEPeripheralServer
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
createBLEPeripheralServer(Object object)
Establish multiple servers that are local as Bluetooth low energy peripherals and can be created.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| server | BLEPeripheralServer | The server side of the peripheral. |
# BLEPeripheralServer.addService
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.addService(Object object)
Add a service.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| service | Object | Yes | Describes the Object | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Structure of object.service
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| uuid | String | Yes | The UUID for bluetooth services | |
| characteristics | Array.Object | Yes | The characteristics list |
Structure of characteristics
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| uuid | String | Yes | The characteristic UUID | |
| properties | Object | No | The operations supported by the feature | |
| permission | Object | No | Feature Permissions | |
| value | ArrayBuffer | No | The binary value of the feature corresponds to | |
| descriptors | Array.Object | No | Descriptor data |
properties structure
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| write | Boolean | false | No | Write |
| writeNoResponse | Boolean | false | No | Write |
| read | Boolean | false | No | Read |
| notify | Boolean | false | No | Subscribe to |
| indicate | Boolean | false | No | Back to package |
permission structure
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| readable | Boolean | false | No | Readable |
| writeable | Boolean | false | No | Writeable |
| readEncryptionRequired | Boolean | false | No | Encrypt read requests |
| writeEncryptionRequired | Boolean | false | No | Encrypt the write request |
Descriptors Structure
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| uuid | String | Yes | Descriptor's UUID | |
| permission | Object | No | The descriptor's permissions | |
| value | ArrayBuffer | No | Descriptor data |
permission structure
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| write | Boolean | false | No | Write |
| read | Boolean | false | No | Read |
# BLEPeripheralServer.close
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.close(Object object)
Close the current server.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# BLEPeripheralServer.offCharacteristicReadRequest
BLEPeripheralServer.offCharacteristicReadRequest()
Cancels listening for connected device requests to read characteristic values events for the current peripheral
# BLEPeripheralServer.offCharacteristicSubscribed
BLEPeripheralServer.offCharacteristicSubscribed()
Unsnoop feature subscription events
# BLEPeripheralServer.offCharacteristicUnsubscribed
BLEPeripheralServer.offCharacteristicUnsubscribed()
Unsnoop unsubscribe events
# BLEPeripheralServer.offCharacteristicWriteRequest
BLEPeripheralServer.offCharacteristicWriteRequest()
Cancels listening for connected device requests to write signature events for the current peripheral
# BLEPeripheralServer.onCharacteristicReadRequest
BLEPeripheralServer.onCharacteristicReadRequest(function callback)
Parameters
function callback
The connected device requests a callback function that reads the characteristic value event of the current peripheral
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| serviceId | String | The Bluetooth signature corresponds to the UUID |
| characteristicId | String | The UUID |
| callbackId | Number | Unique identifier that uses |
Note Repeated calls overwrite the original callback
# BLEPeripheralServer.onCharacteristicSubscribed
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.onCharacteristicSubscribed(function callback)
The listening feature subscribes to events and is only supported by iOS.
Parameters
function callback
A callback function that features subscription events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| serviceId | String | The Bluetooth signature corresponds to the UUID |
| characteristicId | String | The UUID |
Note Repeated calls overwrite the original callback
# BLEPeripheralServer.onCharacteristicUnsubscribed
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.onCharacteristicUnsubscribed(function callback)
Listening for unsubscribe events is supported by iOS only.
Parameters
function callback
A callback function that unsubscribes the feature to an event
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| serviceId | String | The Bluetooth signature corresponds to the UUID |
| characteristicId | String | The UUID |
Note Repeated calls overwrite the original callback
# BLEPeripheralServer.onCharacteristicWriteRequest
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.onCharacteristicWriteRequest(function callback)
Listens for connected device requests to write characteristic values events for the current peripheral. After receiving the message, you need to call writeCharacteristicValue to write back data, otherwise the host will not receive a response.
Parameters
function callback
The connected device requests a callback function that writes the characteristic value event of the current peripheral
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| serviceId | String | The Bluetooth signature corresponds to the UUID |
| characteristicId | String | The UUID |
Note Repeated calls overwrite the original callback
# BLEPeripheralServer.removeService
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.removeService(Object object)
Remove the service.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| serviceId | String | Yes | The UUID of the service | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# BLEPeripheralServer.startAdvertising
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.startAdvertising(Object Object)
Start broadcasting locally created peripherals
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| advertiseRequest | Object | Yes | Broadcast custom parameters | |
| powerLevel | String | medium | No | Broadcast power |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Structure of Object.advertiseRequest
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| connectable | Boolean | true | No | Whether the current device can connect to the |
| deviceName | String | No | The deviceName field in the broadcast, which defaults to an empty | |
| serviceUuids | Array.String | No | A list of services to broadcast UUIDs. Refer to considerations when using 16/32-bit UUIDs. | |
| manufacturerData | Array.Object | No | Broadcast manufacturer information. Android only, iOS cannot be customized due to system limitations. |
Structure of manufacturerData
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| manufacturerId | String | Yes | Manufacturer ID, hexadecimal | |
| manufacturerSpecificData | ArrayBuffer | No | Manufacturer Information |
Object.powerLevel 的合法值
| The value | Description | Minimum version |
|---|---|---|
| low | Low power | |
| medium | Moderate power | |
| high | High power |
NOTE
- Android 8.0.9, support for direct use of 16/32/128-bit UUID;
- Android 8.0.9 versions only support 128-bit UUIDs, and requires a patch when using 16/32-bit UUIDs (the system will automatically identify if it belongs to a pre-allocated range)
- iOS must use a 16-bit UUID directly and cannot be padded to 128 bits, otherwise the system will still be transferred according to 128 bits when it is packaged. 32-bit UUIDs are not currently supported for iOS.
- iOS can only initiate one broadcast at a time, Android supports multiple broadcasts at the same time.
# BLEPeripheralServer.stopAdvertising
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.stopAdvertising(Object object)
Stop broadcasting.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# BLEPeripheralServer.writeCharacteristicValue
Base Library 2.11.2 is supported, iOS version 2.34.1, Android version 2.34.1, dependent extension SDK
BLEPeripheralServer.writeCharacteristicValue(Object Object)
Writes binary data values to the specified feature and notifies the connected host that the slave's feature value has changed, and the interface handles whether to go back to the packet or go to the subscription.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| serviceId | String | Yes | The Bluetooth signature corresponds to the UUID | |
| characteristicId | String | Yes | The UUID | |
| value | ArrayBuffer | Yes | The characteristic corresponds to the binary value | |
| needNotify | Boolean | Yes | Whether you need to notify the host that value has been updated | |
| callbackId | Number | No | Optionally, use | |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
# Bluetooth-Beacon
# stopBeaconDiscovery
Base Library 2.11.2 started support, iOS version 2.34.1, dependency extension SDK, Android version 2.35.9, dependency on BluetoothSDK
stopBeaconDiscovery(Object object)
Stop searching for nearby Beacon devices
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| 11000 | unsupport | The system or device does not support |
| 11001 | bluetooth service unavailable | Bluetooth service is not available |
| 11002 | location service unavailable | Location services are not available |
| 11003 | already start | A search for |
| 11004 | not startBeaconDiscovery | The search for |
| 11005 | system error | System error |
| 11006 | invalid data | The parameter is incorrect |
# startBeaconDiscovery
Base Library 2.11.2 started support, iOS version 2.34.1, dependency extension SDK, Android version 2.35.9, dependency on BluetoothSDK
startBeaconDiscovery(Object object)
Start searching for nearby Beacon devices
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| uuids | Array.<string> | Yes | The UUID list broadcast by beacon devices | |
| ignoreBluetoothAvailable | boolean | false | No | Check the Bluetooth switch, which is only valid under iOS. Starting with iOS 11, bluetooth is turned off in the control panel, and you can still continue to use the Beacon service. |
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| 11000 | unsupport | The system or device does not support |
| 11001 | bluetooth service unavailable | Bluetooth service is not available |
| 11002 | location service unavailable | Location services are not available |
| 11003 | already start | A search for |
| 11004 | not startBeaconDiscovery | The search for |
| 11005 | system error | System error |
| 11006 | invalid data | The parameter is incorrect |
note
- Interface Authorization Failed (iOS):
- The host App prohibits the Mini App from actively applying for permissions, and will return an error message: unauthorized disableauthorized, sdk is forbidden to apply for Bluetooth permissions
# onBeaconUpdate
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
onBeaconUpdate(function callback)
Only one listener can be registered for Beacon device update events
Parameters
function callback
Callback function for Beacon device update events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| beacons | Array.BeaconInfo | The list of all Beacon devices currently found |
# onBeaconServiceChange
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
onBeaconServiceChange(function callback)
You can listen for Beacon service status change events, and only one listener can be registered
Parameters
function callback
A callback function for beacon service state change events
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| available | boolean | Whether the service is currently available |
| discovering | boolean | Whether it is currently searching for |
# offBeaconUpdate
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
Cancel listening for Beacon device update events
# offBeaconServiceChange
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
Cancels listening for Beacon service status change events
# getBeacons
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
getBeacons(Object object)
Gets all searched Beacon devices
Parameters
Object object
A callback function for beacon service state change events
Parameters
Object res
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| beacons | Array.BeaconInfo | Beacon Device List |
Error
| Error code | Error message | Description |
|---|---|---|
| 0 | ok | Normal |
| 11000 | unsupport | The system or device does not support |
| 11001 | bluetooth service unavailable | Bluetooth service is not available |
| 11002 | location service unavailable | Location services are not available |
| 11003 | already start | A search for |
| 11004 | not startBeaconDiscovery | The search for |
| 11005 | system error | System error |
| 11006 | invalid data | The parameter is incorrect |
# BeaconInfo
Beacon devices
Properties
string uuid
The UUID broadcast by the Beacon device
number major
The primary ID of the Beacon device
number minor
The secondary ID of the Beacon device
number proximity
Enumeration value representing device distance (iOS only)
Legal value of proximity
| The value | Description | Minimum version |
|---|---|---|
| 0 | The signal is too weak to calculate distance, or a non-iOS device | |
| 1 | Very close to | |
| 2 | Relatively close to | |
| 3 | Far |
number accuracy
The distance of the Beacon device, in m. On iOS, when proximity is 0, accuracy is -1.
number rssi
Represents the signal strength of the device in dBm
# offBeaconServiceChange
Base Library 2.11.2 is supported, iOS version 2.34.1, dependent extension SDK, Android does not support Beacon related interfaces
Cancels listening for Beacon service status change events
# Accessibility
# checkIsOpenAccessibility
Base Library 2.12.1 is supported
checkIsOpenAccessibility(Object object)
Detects if visual accessibility is turned on.
Parameters
Object object
| Properties | Type | The default value is | Required | Description |
|---|---|---|---|---|
| success | function | No | The interface calls the callback function successfully | |
| fail | function | No | The callback function that failed the interface callback function | |
| complete | function | No | The callback function at the end of the interface call (the call succeeds or fails) |
object.success callback function
Parameters
Object res
| Properties | Type | Description |
|---|---|---|
| open | Boolean | Enable accessibility narration on iOS, and return true |