> 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.

# onBluetoothDeviceFound

注册发现蓝牙设备回调。

## 支持版本

前端库版本不低于 `0.0.36`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 接入准备

### 权限要求

<table>
<thead>
<tr><th>类型</th><th>标识</th><th>是否必须</th><th>平台</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td>系统权限</td><td>蓝牙权限</td><td>按条件</td><td>Android、iOS</td><td>扫描附近蓝牙设备需要系统蓝牙权限，Android 低版本还需定位权限</td></tr>
</tbody>
</table>

### 授权行为

- 依赖 startBluetoothDevicesDiscovery 阶段已获得的系统蓝牙权限；权限被拒绝或在系统设置中撤销后事件不再回调，需引导用户在系统设置中开启蓝牙权限

### 前置条件

- 需先调用 startBluetoothDevicesDiscovery 开始搜索

## 使用说明

- `advertisData` 与 `serviceData` 以 ArrayBuffer 返回

## 调用方式

### 事件监听 API

```typescript
onBluetoothDeviceFound(callback: BluetoothDeviceFoundListener): () => void
```

## 入参

无。

## 调用示例

```typescript
import { onBluetoothDeviceFound } from '@doubao-dev/framework/api';

const off = onBluetoothDeviceFound(({ devices }) => {
  console.log(devices);
});

off();
```

## 回调参数

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>event.devices</code></td><td><code>BluetoothDeviceFoundDevice[]</code></td><td>是</td><td>本次扫描上报的新发现设备列表。</td></tr>
<tr><td><code>event.devices[].advertisData</code></td><td><code>ArrayBuffer</code></td><td>否</td><td>广播二进制数据。</td></tr>
<tr><td><code>event.devices[].advertisServiceUUIDs</code></td><td><code>string[]</code></td><td>否</td><td>广播中的服务 UUID 列表。</td></tr>
<tr><td><code>event.devices[].connectable</code></td><td><code>boolean</code></td><td>否</td><td>是否可连接。</td></tr>
<tr><td><code>event.devices[].deviceId</code></td><td><code>string</code></td><td>是</td><td>设备 ID。</td></tr>
<tr><td><code>event.devices[].localName</code></td><td><code>string</code></td><td>否</td><td>广播中的本地名称。</td></tr>
<tr><td><code>event.devices[].name</code></td><td><code>string</code></td><td>是</td><td>设备名称。</td></tr>
<tr><td><code>event.devices[].RSSI</code></td><td><code>number</code></td><td>是</td><td>RSSI 信号强度，单位 dBm。</td></tr>
<tr><td><code>event.devices[].serviceData</code></td><td><code>BluetoothBinaryField</code></td><td>否</td><td>广播中的服务数据。</td></tr>
</tbody>
</table>

## 返回值

返回取消当前监听函数的函数。

### 回调示例

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