harmony 鸿蒙@ohos.bluetooth.access (蓝牙access模块)(系统接口)

  • 2025-06-12
  • 浏览 (1)

@ohos.bluetooth.access (蓝牙access模块)(系统接口)

access模块提供了打开蓝牙、关闭蓝牙和获取蓝牙状态的方法。

说明:

本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 当前页面仅包含本模块的系统接口,其他公开接口参见@ohos.bluetooth.access (蓝牙access模块)

导入模块

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,否则为错误对象。

错误码

以下错误码的详细介绍请参见通用错误码说明文档蓝牙服务子系统错误码

错误码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.

示例:

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对象。

错误码

以下错误码的详细介绍请参见通用错误码说明文档蓝牙服务子系统错误码

错误码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.

示例:

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 本端设备的蓝牙地址。

错误码

以下错误码的详细介绍请参见通用错误码说明文档蓝牙服务子系统错误码

错误码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.

示例:

import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
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对象。

错误码

以下错误码的详细介绍请参见通用错误码说明文档蓝牙服务子系统错误码

错误码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.

示例:

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);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Connectivity Kit(短距通信服务)

harmony 鸿蒙Bluetooth

harmony 鸿蒙Wifi

harmony 鸿蒙蓝牙服务子系统错误码

harmony 鸿蒙NFC错误码

harmony 鸿蒙SE(secureElement)错误码

harmony 鸿蒙WIFI错误码

harmony 鸿蒙@ohos.bluetooth.a2dp (蓝牙a2dp模块)(系统接口)

harmony 鸿蒙@ohos.bluetooth.a2dp (蓝牙a2dp模块)

harmony 鸿蒙@ohos.bluetooth.access (蓝牙access模块)

0  赞