三方应用如何获取蓝牙mac地址?

三方应用如何获取蓝牙mac地址

阅读 522
1 个回答

解决措施

调用bluetoothManager.startBluetoothDiscovery()接口,使用蓝牙扫描功能,在扫描结果中即可获取蓝牙mac地址。

示例代码

import { connection } from '@kit.ConnectivityKit'; 
import { BusinessError } from '@kit.BasicServicesKit'; 
 
function onReceiveEvent(data: Array<string>) { // data为蓝牙设备地址集合 
  console.info('bluetooth device find = '+ JSON.stringify(data)); 
} 
 
try { 
  connection.on('bluetoothDeviceFind', onReceiveEvent); 
  connection.startBluetoothDiscovery(); 
} catch (err) { 
  console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 
}

参考链接

发现蓝牙设备

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进