1# @ohos.bluetooth.access (蓝牙access模块)(系统接口) 2 3access模块提供了打开和关闭蓝牙、获取蓝牙状态的方法。 4 5> **说明:** 6> 7> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.bluetooth.access (蓝牙access模块)](js-apis-bluetooth-access.md) 9 10 11## 导入模块 12 13```js 14import access from '@ohos.bluetooth.access'; 15``` 16 17 18## access.factoryReset<sup>11+</sup> 19 20factoryReset(callback: AsyncCallback<void>): void 21 22恢复蓝牙出厂设置。 23 24**系统接口**:此接口为系统接口。 25 26**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 27 28**系统能力**:SystemCapability.Communication.Bluetooth.Core。 29 30**参数:** 31 32| 参数名 | 类型 | 必填 | 说明 | 33| -------- | ------------------------------------------------- | ----- | ---------------------------------------------------------- | 34| callback | AsyncCallback<void> | 是 | 回调函数。当恢复蓝牙出厂设置时成功,err为undefined,否则为错误对象。 | 35 36**错误码**: 37 38以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 39 40|错误码ID | 错误信息 | 41| -------- | ------------------ | 42|2900001 | Service stopped. | 43|2900099 | Operation failed. | 44 45**示例:** 46 47```js 48import { AsyncCallback, BusinessError } from '@ohos.base'; 49try { 50 access.factoryReset((err: BusinessError) => { 51 if (err) { 52 console.error("factoryReset error"); 53 } 54 }); 55} catch (err) { 56 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 57} 58``` 59 60 61## access.factoryReset<sup>11+</sup> 62 63factoryReset(): Promise<void> 64 65恢复蓝牙出厂设置。 66 67**系统接口**:此接口为系统接口。 68 69**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.MANAGE_BLUETOOTH 70 71**系统能力**:SystemCapability.Communication.Bluetooth.Core。 72 73**返回值:** 74 75| 类型 | 说明 | 76| --------------------------------- | ---------------- | 77| Promise<void> | Promise对象。无返回结果的Promise对象。 | 78 79**错误码**: 80 81以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 82 83|错误码ID | 错误信息 | 84| -------- | ------------------ | 85|2900001 | Service stopped. | 86|2900099 | Operation failed. | 87 88**示例:** 89 90```js 91import { AsyncCallback, BusinessError } from '@ohos.base'; 92try { 93 access.factoryReset().then(() => { 94 console.info("factoryReset"); 95 }); 96} catch (err) { 97 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 98} 99``` 100 101 102## access.getLocalAddress<sup>11+</sup><a name="getLocalAddress"></a> 103 104getLocalAddress(): string; 105 106获取本端设备的蓝牙地址。 107 108**系统接口**:此接口为系统接口。 109 110**需要权限**:ohos.permission.ACCESS_BLUETOOTH 和 ohos.permission.GET_BLUETOOTH_LOCAL_MAC 111 112**系统能力**:SystemCapability.Communication.Bluetooth.Core。 113 114**返回值:** 115 116| 类型 | 说明 | 117| --------- | ------------------ | 118| string | 本端设备的蓝牙地址。 | 119 120**错误码**: 121 122以下错误码的详细介绍请参见[蓝牙服务子系统错误码](errorcode-bluetoothManager.md)。 123 124|错误码ID | 错误信息 | 125| -------- | ------------------ | 126|2900001 | Service stopped. | 127|2900099 | Operation failed. | 128 129**示例:** 130 131```js 132try { 133 let localAddr = access.getLocalAddress(); 134} catch (err) { 135 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 136} 137``` 138 139 140