# @ohos.bluetooth.access (蓝牙access模块)(系统接口)
access模块提供了打开和关闭蓝牙、获取蓝牙状态的方法。
> **说明:**
>
> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.access (蓝牙access模块)](js-apis-bluetooth-access.md)
## 导入模块
```js
import { access } from '@kit.ConnectivityKit';
```
## access.factoryReset11+
factoryReset(callback: AsyncCallback<void>): void
恢复蓝牙出厂设置。使用Callback异步回调。
**系统接口**:此接口为系统接口。
**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ----- | ---------------------------------------------------------- |
| callback | AsyncCallback<void> | 是 | 回调函数。当恢复蓝牙出厂设置时成功,err为undefined,否则为错误对象。 |
**错误码**:
以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
|错误码ID | 错误信息 |
| -------- | ------------------ |
|201 | Permission denied. |
|202 | Non-system applications are not allowed to use system APIs. |
|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
|801 | Capability not supported. |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**示例:**
```js
import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
access.factoryReset((err: BusinessError) => {
if (err) {
console.error("factoryReset error");
}
});
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}
```
## access.factoryReset11+
factoryReset(): Promise<void>
恢复蓝牙出厂设置。使用Promise异步回调。
**系统接口**:此接口为系统接口。
**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ---------------- |
| Promise<void> | Promise对象。无返回结果的Promise对象。 |
**错误码**:
以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
|错误码ID | 错误信息 |
| -------- | ------------------ |
|201 | Permission denied. |
|202 | Non-system applications are not allowed to use system APIs. |
|801 | Capability not supported. |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**示例:**
```js
import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
access.factoryReset().then(() => {
console.info("factoryReset");
});
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}
```
## access.getLocalAddress11+
getLocalAddress(): string;
获取本端设备的蓝牙地址。
**系统接口**:此接口为系统接口。
**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.GET_BLUETOOTH_LOCAL_MAC
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
**返回值:**
| 类型 | 说明 |
| --------- | ------------------ |
| string | 本端设备的蓝牙地址。 |
**错误码**:
以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
|错误码ID | 错误信息 |
| -------- | ------------------ |
|201 | Permission denied. |
|202 | Non-system applications are not allowed to use system APIs. |
|801 | Capability not supported. |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**示例:**
```js
try {
let localAddr = access.getLocalAddress();
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}
```
## access.restrictBluetooth12+
restrictBluetooth(): Promise<void>
约束当前蓝牙设备的BR/EDR能力。
**系统接口**:此接口为系统接口。
**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH
**系统能力**:SystemCapability.Communication.Bluetooth.Core。
**返回值:**
| 类型 | 说明 |
| --------------------------------- | ---------------- |
| Promise<void> | Promise对象。无返回结果的Promise对象。 |
**错误码**:
以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。
|错误码ID | 错误信息 |
| -------- | ------------------ |
|201 | Permission denied. |
|202 | Non-system applications are not allowed to use system APIs. |
|801 | Capability not supported. |
|2900001 | Service stopped. |
|2900099 | Operation failed. |
**示例:**
```js
import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
try {
access.restrictBluetooth().then(() => {
console.info("restrictBluetooth");
});
} catch (err) {
console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message);
}
```