1# @ohos.bluetooth.access (Bluetooth Access Module) (System API) 2 3The **access** module provides APIs for enabling and disabling Bluetooth and obtaining the Bluetooth status. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.bluetooth.access (Bluetooth Access Module)](js-apis-bluetooth-access.md). 9 10 11## Modules to Import 12 13```js 14import { access } from '@kit.ConnectivityKit'; 15``` 16 17 18## access.factoryReset<sup>11+</sup> 19 20factoryReset(callback: AsyncCallback<void>): void 21 22Restores the Bluetooth factory settings. This API uses an asynchronous callback to return the result. 23 24**System API**: This is a system API. 25 26**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 27 28**System capability**: SystemCapability.Communication.Bluetooth.Core 29 30**Parameters** 31 32| Name | Type | Mandatory | Description | 33| -------- | ------------------------------------------------- | ----- | ---------------------------------------------------------- | 34| callback | AsyncCallback<void> | Yes | Callback used to return the result.<br>If the Bluetooth factory settings are restored successfully, **err** is **undefined**. Otherwise, **err** is an error object. | 35 36**Error codes** 37 38For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 39 40|ID | Error Message | 41| -------- | ------------------ | 42|201 | Permission denied. | 43|202 | Non-system applications are not allowed to use system APIs. | 44|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 45|801 | Capability not supported. | 46|2900001 | Service stopped. | 47|2900099 | Operation failed. | 48 49**Example** 50 51```js 52import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 53try { 54 access.factoryReset((err: BusinessError) => { 55 if (err) { 56 console.error("factoryReset error"); 57 } 58 }); 59} catch (err) { 60 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 61} 62``` 63 64 65## access.factoryReset<sup>11+</sup> 66 67factoryReset(): Promise<void> 68 69Restores the Bluetooth factory settings. This API uses a promise to return the result. 70 71**System API**: This is a system API. 72 73**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 74 75**System capability**: SystemCapability.Communication.Bluetooth.Core 76 77**Return value** 78 79| Type | Description | 80| --------------------------------- | ---------------- | 81| Promise<void> | Promise that returns no value.| 82 83**Error codes** 84 85For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 86 87|ID | Error Message | 88| -------- | ------------------ | 89|201 | Permission denied. | 90|202 | Non-system applications are not allowed to use system APIs. | 91|801 | Capability not supported. | 92|2900001 | Service stopped. | 93|2900099 | Operation failed. | 94 95**Example** 96 97```js 98import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 99try { 100 access.factoryReset().then(() => { 101 console.info("factoryReset"); 102 }); 103} catch (err) { 104 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 105} 106``` 107 108 109## access.getLocalAddress<sup>11+</sup><a name="getLocalAddress"></a> 110 111getLocalAddress(): string; 112 113Obtains the Bluetooth address of the local device. 114 115**System API**: This is a system API. 116 117**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.GET_BLUETOOTH_LOCAL_MAC 118 119**System capability**: SystemCapability.Communication.Bluetooth.Core 120 121**Return value** 122 123| Type | Description | 124| --------- | ------------------ | 125| string | Bluetooth address obtained.| 126 127**Error codes** 128 129For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 130 131|ID | Error Message | 132| -------- | ------------------ | 133|201 | Permission denied. | 134|202 | Non-system applications are not allowed to use system APIs. | 135|801 | Capability not supported. | 136|2900001 | Service stopped. | 137|2900099 | Operation failed. | 138 139**Example** 140 141```js 142try { 143 let localAddr = access.getLocalAddress(); 144} catch (err) { 145 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 146} 147``` 148 149 150## access.restrictBluetooth<sup>12+</sup><a name="restrictBluetooth"></a> 151 152restrictBluetooth(): Promise<void> 153 154Restricts the BR/EDR capability of this Bluetooth device. 155 156**System API**: This is a system API. 157 158**Required permissions**: ohos.permission.ACCESS_BLUETOOTH and ohos.permission.MANAGE_BLUETOOTH 159 160**System capability**: SystemCapability.Communication.Bluetooth.Core 161 162**Return value** 163 164| Type | Description | 165| --------------------------------- | ---------------- | 166| Promise<void> | Promise that returns no value.| 167 168**Error codes** 169 170For details about the error codes, see [Bluetooth Error Codes](errorcode-bluetoothManager.md). 171 172|ID | Error Message | 173| -------- | ------------------ | 174|201 | Permission denied. | 175|202 | Non-system applications are not allowed to use system APIs. | 176|801 | Capability not supported. | 177|2900001 | Service stopped. | 178|2900099 | Operation failed. | 179 180**Example** 181 182```js 183import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 184try { 185 access.restrictBluetooth().then(() => { 186 console.info("restrictBluetooth"); 187 }); 188} catch (err) { 189 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 190} 191``` 192