1# @ohos.wifiManagerExt (WLAN Extension) 2This **wifiext** module provides WLAN extension interfaces for non-universal products. 3 4> **NOTE** 5> 6> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7> - The APIs described in this document are used only for non-universal products, such as routers. 8 9 10## Modules to Import 11 12```js 13import wifiManagerExt from '@ohos.wifiManagerExt'; 14``` 15 16## wifiext.enableHotspot<sup>9+</sup> 17 18enableHotspot(): void; 19 20Enables the WLAN hotspot. 21 22**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 23 24**System capability**: SystemCapability.Communication.WiFi.AP.Extension 25 26**Error codes** 27 28For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 29 30| **ID**| **Error Message**| 31| -------- | -------- | 32| 2701000 | Operation failed.| 33 34**Example** 35 36```ts 37 import wifiManagerExt from '@ohos.wifiManagerExt'; 38 39 try { 40 wifiManagerExt.enableHotspot(); 41 }catch(error){ 42 console.error("failed:" + JSON.stringify(error)); 43 } 44``` 45 46## wifiext.disableHotspot<sup>9+</sup> 47 48disableHotspot(): void; 49 50Disables the WLAN hotspot. 51 52**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 53 54**System capability**: SystemCapability.Communication.WiFi.AP.Extension 55 56**Error codes** 57 58For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 59 60| **ID**| **Error Message**| 61| -------- | -------- | 62| 2701000 | Operation failed.| 63 64**Example** 65 66```ts 67 import wifiManagerExt from '@ohos.wifiManagerExt'; 68 69 try { 70 wifiManagerExt.disableHotspot(); 71 }catch(error){ 72 console.error("failed:" + JSON.stringify(error)); 73 } 74``` 75 76## wifiext.getSupportedPowerMode<sup>9+</sup> 77 78getSupportedPowerMode(): Promise<Array<PowerMode>> 79 80Obtains the supported power modes. This API uses a promise to return the result. 81 82**Required permissions**: ohos.permission.GET_WIFI_INFO 83 84**System capability**: SystemCapability.Communication.WiFi.AP.Extension 85 86**Return value** 87 88| Type| Description| 89| -------- | -------- | 90| Promise<Array<[PowerMode](#powermode9)>> | Promise used to return the power modes obtained.| 91 92**Error codes** 93 94For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 95 96| **ID**| **Error Message**| 97| -------- | -------- | 98| 2701000 | Operation failed.| 99 100## PowerMode<sup>9+</sup> 101 102Enumerates the power modes. 103 104**System capability**: SystemCapability.Ability.AbilityRuntime.Core 105 106| Name| Value| Description| 107| -------- | -------- | -------- | 108| SLEEPING | 0 | Sleeping| 109| GENERAL | 1 | General| 110| THROUGH_WALL | 2 | Through_wall| 111 112 113## wifiext.getSupportedPowerMode<sup>9+</sup> 114 115getSupportedPowerMode(callback: AsyncCallback<Array<PowerMode>>): void 116 117Obtains the supported power modes. This API uses an asynchronous callback to return the result. 118 119**Required permissions**: ohos.permission.GET_WIFI_INFO 120 121**System capability**: SystemCapability.Communication.WiFi.AP.Extension 122 123**Parameters** 124 125| Name| Type| Mandatory| Description| 126| -------- | -------- | -------- | -------- | 127| callback | AsyncCallback<Array<[PowerMode](#powermode9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power modes obtained. If the operation fails, **err** is not **0**.| 128 129**Error codes** 130 131For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 132 133| **ID**| **Error Message**| 134| -------- | -------- | 135| 2701000 | Operation failed.| 136 137**Example** 138 139```ts 140 import wifiManagerExt from '@ohos.wifiManagerExt'; 141 142 wifiManagerExt.getSupportedPowerMode((err, data) => { 143 if (err) { 144 console.error("get supported power mode info error"); 145 return; 146 } 147 console.info("get supported power mode info: " + JSON.stringify(data)); 148 }); 149 150 wifiManagerExt.getSupportedPowerMode().then(data => { 151 console.info("get supported power mode info: " + JSON.stringify(data)); 152 }).catch((error:number) => { 153 console.info("get supported power mode error"); 154 }); 155``` 156 157## wifiext.getPowerMode<sup>9+</sup> 158 159getPowerMode(): Promise<PowerMode> 160 161Obtains the power mode. This API uses a promise to return the result. 162 163**Required permissions**: ohos.permission.GET_WIFI_INFO 164 165**System capability**: SystemCapability.Communication.WiFi.AP.Extension 166 167**Return value** 168 169| Type| Description| 170| -------- | -------- | 171| Promise<[PowerMode](#powermode9)> | Promise used to return the power modes obtained.| 172 173**Error codes** 174 175For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 176 177| **ID**| **Error Message**| 178| -------- | -------- | 179| 2701000 | Operation failed.| 180 181**Example** 182 183```ts 184 import wifiManagerExt from '@ohos.wifiManagerExt'; 185 186 try { 187 let model = wifiManagerExt.getPowerMode(); 188 console.info("model info:" + model); 189 }catch(error){ 190 console.error("failed:" + JSON.stringify(error)); 191 } 192``` 193 194## wifiext.getPowerMode<sup>9+</sup> 195 196getPowerMode(callback: AsyncCallback<PowerMode>): void 197 198Obtains the power mode. This API uses an asynchronous callback to return the result. 199 200**Required permissions**: ohos.permission.GET_WIFI_INFO 201 202**System capability**: SystemCapability.Communication.WiFi.AP.Extension 203 204**Parameters** 205 206| Name| Type| Mandatory| Description| 207| -------- | -------- | -------- | -------- | 208| callback | AsyncCallback<[PowerMode](#powermode9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power mode obtained. If the operation fails, **err** is not **0**.| 209 210**Error codes** 211 212For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 213 214| **ID**| **Error Message**| 215| -------- | -------- | 216| 2701000 | Operation failed.| 217 218**Example** 219 220```ts 221 import wifiManagerExt from '@ohos.wifiManagerExt'; 222 223 wifiManagerExt.getPowerMode((err, data) => { 224 if (err) { 225 console.error("get linked info error"); 226 return; 227 } 228 console.info("get power mode info: " + JSON.stringify(data)); 229 }); 230 231 wifiManagerExt.getPowerMode().then(data => { 232 console.info("get power mode info: " + JSON.stringify(data)); 233 }).catch((error:number) => { 234 console.info("get power mode error"); 235 }); 236``` 237 238## wifiext.setPowerMode<sup>9+</sup> 239 240setPowerMode(mode: PowerMode) : void; 241 242 Sets the power mode. 243 244**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 245 246**System capability**: SystemCapability.Communication.WiFi.AP.Extension 247 248**Parameters** 249 250| Name| Type| Mandatory| Description| 251| -------- | -------- | -------- | -------- | 252| model | [PowerMode](#powermode9) | Yes| Power mode to set.| 253 254**Error codes** 255 256For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 257 258| **ID**| **Error Message**| 259| -------- | -------- | 260| 2701000 | Operation failed.| 261 262**Example** 263 264```ts 265 import wifiManagerExt from '@ohos.wifiManagerExt'; 266 267 try { 268 let model = 0; 269 wifiManagerExt.setPowerMode(model); 270 }catch(error){ 271 console.error("failed:" + JSON.stringify(error)); 272 } 273``` 274