HomeDocs
Skip to main content

dlt.onBluetoothDeviceFound(function listener)

Introduction

Add a listener for the discovery of Bluetooth devices.

Usage Restrictions

This function must be registered before calling dlt.startBluetoothDevicesDiscovery.

Parameters

function listener

The listener function for Bluetooth devices being discovered.

Parameters

Object res

PropertyTypeDescription
addressstringThe MAC address of the Bluetooth device
namestringThe name of the Bluetooth device; some devices may not have a name
RSSIstringThe received signal strength indication (RSSI)
system_codenumberReturns when scanning fails

Explanation of system_code

system_codeDescription
1Fails to start scanning because a BLE scan with the same settings is already started by the app.
2Fails to start scanning because the app cannot be registered.
3Fails to start scanning due to an internal error.
4Fails to start a power-optimized scan because this feature is not supported.
5Fails to start scanning because it is out of hardware resources.
6Fails to start scanning because the application tries to scan too frequently.

Sample Code

dlt.onBluetoothDeviceFound(function (res) {
console.log(res);
});

In the sample code provided, dlt.onBluetoothDeviceFound is used to add a listener for the discovery of Bluetooth devices. When a Bluetooth device is discovered, the provided listener function is called, and it logs information about the discovered device to the console.

Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.