For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt, and this page is available as Markdown at /apps-plugin/docs/js-api/device/bluetooth/getBluetoothDevices.md.

getBluetoothDevices

获取当前蓝牙模块发现的设备列表。

扫码预览

扫码预览 getBluetoothDevices

支持版本

前端库版本不低于 0.0.25。

支持平台

平台支持情况
Android支持
iOS支持
PC不支持
HarmonyOS不支持

支持场景

场景支持情况
页面支持
卡片不支持

接入准备

权限要求

类型标识是否必须平台说明
系统权限蓝牙权限按条件Android、iOS使用蓝牙能力需要系统蓝牙权限

授权行为

  • 依赖 openBluetoothAdapter 阶段已获得的系统蓝牙权限;权限被拒绝或在系统设置中撤销后调用失败,需引导用户在系统设置中开启蓝牙权限

前置条件

  • 需先调用 startBluetoothDevicesDiscovery 开始搜索

使用说明

通常先调用 startBluetoothDevicesDiscovery。

  • advertisData 与 serviceData 以 ArrayBuffer 返回

调用方式

异步 API

getBluetoothDevices(params: object): Promise<GetBluetoothDevicesResult>

入参

无。

调用示例

import { getBluetoothDevices } from '@doubao-dev/framework/api';

const { devices } = await getBluetoothDevices();

console.log(devices.map((device) => device.name));

成功返回

名称类型必返说明
devicesBluetoothDevice[]是当前蓝牙模块已发现的设备列表。
devices[].advertisDataArrayBuffer否广播二进制数据。
devices[].advertisServiceUUIDsstring[]否广播中的服务 UUID 列表。
devices[].connectableboolean否是否可连接。
devices[].deviceIdstring是设备 ID。
devices[].localNamestring否广播中的本地名称。
devices[].namestring是设备名称。
devices[].RSSInumber是RSSI 信号强度,单位 dBm。
devices[].serviceDataBluetoothBinaryField否广播中的服务数据。

返回示例

{
  "devices": [
    {
      "deviceId": "device-id",
      "name": "Doubao BLE",
      "RSSI": -60,
      "connectable": true
    }
  ]
}

错误处理

错误对象和通用错误码见 通用错误处理。

错误码

通用错误码

errNoerrMsg说明平台
102internal error内部错误Android、iOS
116resource not found资源不存在Android、iOS