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

# getBLEDeviceCharacteristics

获取 BLE 特征值列表。

## 扫码预览

![扫码预览 getBLEDeviceCharacteristics](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fdevice%252Fbluetooth-services%252Findex)

## 支持版本

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

## 支持平台

<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>使用蓝牙能力需要系统蓝牙权限</td></tr>
</tbody>
</table>

### 授权行为

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

### 前置条件

- 需先调用 getBLEDeviceServices 获取服务列表

## 使用说明

通常先获取 BLE 服务列表。

- 通过 properties 判断特征值支持的读写与订阅能力

## 调用方式

### 异步 API

```typescript
getBLEDeviceCharacteristics(params: GetBLEDeviceCharacteristicsParams): Promise<GetBLEDeviceCharacteristicsResult>
```

## 入参

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必填</th><th>默认值</th><th>约束</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>deviceId</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>蓝牙设备 ID。</td></tr>
<tr><td><code>serviceId</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>服务 ID。</td></tr>
</tbody>
</table>

## 调用示例

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

const { characteristics } = await getBLEDeviceCharacteristics({
  deviceId: 'device-id',
  serviceId: 'service-id'
});

console.log(characteristics);
```

## 成功返回

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>characteristics</code></td><td><code>BluetoothCharacteristic[]</code></td><td>是</td><td>特征值列表。</td></tr>
<tr><td><code>characteristics[].properties</code></td><td><code>BluetoothCharacteristicProperties</code></td><td>是</td><td>特征值能力。</td></tr>
<tr><td><code>characteristics[].properties.indicate</code></td><td><code>boolean</code></td><td>是</td><td>是否支持 indicate。</td></tr>
<tr><td><code>characteristics[].properties.notify</code></td><td><code>boolean</code></td><td>是</td><td>是否支持 notify。</td></tr>
<tr><td><code>characteristics[].properties.read</code></td><td><code>boolean</code></td><td>是</td><td>是否支持 read。</td></tr>
<tr><td><code>characteristics[].properties.write</code></td><td><code>boolean</code></td><td>是</td><td>是否支持 write。</td></tr>
<tr><td><code>characteristics[].properties.writeDefault</code></td><td><code>boolean</code></td><td>是</td><td>是否支持带响应写入。</td></tr>
<tr><td><code>characteristics[].properties.writeNoResponse</code></td><td><code>boolean</code></td><td>是</td><td>是否支持无响应写入。</td></tr>
<tr><td><code>characteristics[].uuid</code></td><td><code>string</code></td><td>是</td><td>特征值 UUID。</td></tr>
</tbody>
</table>

### 返回示例

```json
{
  "characteristics": [
    {
      "uuid": "00002A37-0000-1000-8000-00805F9B34FB",
      "properties": {
        "indicate": false,
        "notify": true,
        "read": true,
        "write": false,
        "writeNoResponse": false,
        "writeDefault": false
      }
    }
  ]
}
```

## 错误处理

错误对象和通用错误码见 [通用错误处理](/apps-plugin/docs/js-api/common-errors.md#错误返回)。

### 错误码

#### 通用错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>说明</th><th>平台</th></tr>
</thead>
<tbody>
<tr><td><code>102</code></td><td><code>internal error</code></td><td>内部错误</td><td>Android、iOS</td></tr>
<tr><td><code>104</code></td><td><code>invalid parameter</code></td><td>参数不合法</td><td>Android、iOS</td></tr>
<tr><td><code>116</code></td><td><code>resource not found</code></td><td>资源不存在</td><td>Android、iOS</td></tr>
</tbody>
</table>
