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/startBluetoothDevicesDiscovery.md.

startBluetoothDevicesDiscovery

开始搜索附近的蓝牙设备。

扫码预览

扫码预览 startBluetoothDevicesDiscovery

支持版本

前端库版本不低于 0.0.25。

支持平台

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

支持场景

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

接入准备

权限要求

类型标识是否必须平台说明
系统权限蓝牙权限按条件Android、iOS扫描附近蓝牙设备需要系统蓝牙权限,Android 低版本还需定位权限

授权行为

  • 首次搜索时会触发系统蓝牙权限申请;用户拒绝后调用失败,需引导用户在系统设置中开启蓝牙权限

前置条件

  • 需先调用 openBluetoothAdapter 打开蓝牙适配器

使用说明

通常先调用 openBluetoothAdapter。

  • 通过 onBluetoothDeviceFound 接收扫描结果,不再需要搜索时应调用 stopBluetoothDevicesDiscovery 以降低功耗

调用方式

异步 API

startBluetoothDevicesDiscovery(params?: StartBluetoothDevicesDiscoveryParams): Promise<object>

入参

名称类型必填默认值约束说明
allowDuplicatesKeyboolean否false-是否允许重复上报同一设备。
intervalnumber否由平台使用默认上报间隔-上报设备的间隔,单位毫秒。
powerLevelBluetoothPowerLevel否medium-扫描功耗等级。
servicesstring[]否不按服务 UUID 过滤-按主服务 UUID 过滤搜索范围。

调用示例

import { openBluetoothAdapter, startBluetoothDevicesDiscovery } from '@doubao-dev/framework/api';

await openBluetoothAdapter();
await startBluetoothDevicesDiscovery({ allowDuplicatesKey: false });

成功返回

无返回字段。

返回示例

{}

错误处理

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

错误码

通用错误码

errNoerrMsg说明平台
102internal error内部错误Android、iOS
104invalid parameter参数不合法Android、iOS
106system permission denied系统权限未授予Android、iOS
116resource not found资源不存在Android、iOS
118already exists资源已存在Android、iOS