1# @ohos.wifiManager (WLAN) 2The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with devices over WLAN. 3 4> **NOTE** 5> 6> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7 8 9## Modules to Import 10 11```ts 12import { wifiManager } from '@kit.ConnectivityKit'; 13``` 14 15 16## wifiManager.isWifiActive<sup>9+</sup> 17 18isWifiActive(): boolean 19 20Checks whether WLAN is enabled. 21 22**Atomic service API**: This API can be used in atomic services since API version 11. 23 24**System capability**: SystemCapability.Communication.WiFi.STA 25 26**Return value** 27 28 | **Type**| **Description**| 29 | -------- | -------- | 30 | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| 31 32**Error codes** 33 34For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 35 36| **ID**| **Error Message**| 37| -------- | -------- | 38| 801 | Capability not supported. | 39| 2501000 | Operation failed.| 40 41**Example** 42 43```ts 44 import { wifiManager } from '@kit.ConnectivityKit'; 45 46 try { 47 let isWifiActive = wifiManager.isWifiActive(); 48 console.info("isWifiActive:" + isWifiActive); 49 }catch(error){ 50 console.error("failed:" + JSON.stringify(error)); 51 } 52``` 53 54## wifiManager.scan<sup>9+</sup><sup>(deprecated)</sup> 55 56scan(): void 57 58Starts a scan for WLAN. 59 60> **NOTE** 61> 62> This API is supported since API version 9 and deprecated since API version 10. The substitute API is available only for system applications. 63 64**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 65 66**System capability**: SystemCapability.Communication.WiFi.STA 67 68**Error codes** 69 70For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 71 72| **ID**| **Error Message**| 73| -------- | -------- | 74| 201 | Permission denied. | 75| 801 | Capability not supported. | 76| 2501000 | Operation failed.| 77 78**Example** 79 80```ts 81 import { wifiManager } from '@kit.ConnectivityKit'; 82 83 try { 84 wifiManager.scan(); 85 }catch(error){ 86 console.error("failed:" + JSON.stringify(error)); 87 } 88``` 89 90 91## wifiManager.getScanResults<sup>9+</sup><sup>(deprecated)</sup> 92 93getScanResults(): Promise<Array<WifiScanInfo>> 94 95Obtains the scan result. This API uses a promise to return the result. 96 97> **NOTE** 98> 99> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead. 100 101**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 102ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications. 103 104**System capability**: SystemCapability.Communication.WiFi.STA 105 106**Return value** 107 108| **Type**| **Description**| 109| -------- | -------- | 110| Promise< Array<[WifiScanInfo](#wifiscaninfo9)> > | Promise used to return the hotspots detected.| 111 112**Error codes** 113 114For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 115 116| **ID**| **Error Message**| 117| -------- | -------- | 118| 201 | Permission denied. | 119| 801 | Capability not supported. | 120| 2501000 | Operation failed.| 121 122## wifiManager.getScanResults<sup>9+</sup><sup>(deprecated)</sup> 123 124getScanResults(callback: AsyncCallback<Array<WifiScanInfo>>): void 125 126Obtains the scan result. This API uses an asynchronous callback to return the result. 127 128> **NOTE** 129> 130> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead. 131 132**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 133ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications. 134 135**System capability**: SystemCapability.Communication.WiFi.STA 136 137**Parameters** 138| **Name**| **Type**| **Mandatory**| **Description**| 139| -------- | -------- | -------- | -------- | 140| callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo9)>> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.| 141 142**Error codes** 143 144For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 145 146| **ID**| **Error Message**| 147| -------- | -------- | 148| 201 | Permission denied. | 149| 801 | Capability not supported. | 150| 2501000 | Operation failed.| 151 152**Example** 153```ts 154 import { wifiManager } from '@kit.ConnectivityKit'; 155 156 wifiManager.getScanResults((err, result) => { 157 if (err) { 158 console.error("get scan info error"); 159 return; 160 } 161 162 let len = result.length; 163 console.log("wifi received scan info: " + len); 164 for (let i = 0; i < len; ++i) { 165 console.info("ssid: " + result[i].ssid); 166 console.info("bssid: " + result[i].bssid); 167 console.info("capabilities: " + result[i].capabilities); 168 console.info("securityType: " + result[i].securityType); 169 console.info("rssi: " + result[i].rssi); 170 console.info("band: " + result[i].band); 171 console.info("frequency: " + result[i].frequency); 172 console.info("channelWidth: " + result[i].channelWidth); 173 console.info("timestamp: " + result[i].timestamp); 174 } 175 }); 176 177 wifiManager.getScanResults().then(result => { 178 let len = result.length; 179 console.log("wifi received scan info: " + len); 180 for (let i = 0; i < len; ++i) { 181 console.info("ssid: " + result[i].ssid); 182 console.info("bssid: " + result[i].bssid); 183 console.info("capabilities: " + result[i].capabilities); 184 console.info("securityType: " + result[i].securityType); 185 console.info("rssi: " + result[i].rssi); 186 console.info("band: " + result[i].band); 187 console.info("frequency: " + result[i].frequency); 188 console.info("channelWidth: " + result[i].channelWidth); 189 console.info("timestamp: " + result[i].timestamp); 190 } 191 }).catch((err:number) => { 192 console.error("failed:" + JSON.stringify(err)); 193 }); 194``` 195 196## wifiManager.getScanResultsSync<sup>9+</sup><sup>(deprecated)</sup> 197 198getScanResultsSync(): Array<[WifiScanInfo](#wifiscaninfo9)> 199 200Obtains the scan result. This API returns the result synchronously. 201 202> **NOTE** 203> 204> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead. 205 206**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 207ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications. 208 209**System capability**: SystemCapability.Communication.WiFi.STA 210 211**Return value** 212 213| **Type**| **Description**| 214| -------- | -------- | 215| Array<[WifiScanInfo](#wifiscaninfo9)> | Scan result obtained.| 216 217**Error codes** 218 219For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 220 221| **ID**| **Error Message**| 222| -------- | -------- | 223| 201 | Permission denied. | 224| 801 | Capability not supported. | 225| 2501000 | Operation failed.| 226 227**Example** 228 229```ts 230 import { wifiManager } from '@kit.ConnectivityKit'; 231 232 try { 233 let scanInfoList = wifiManager.getScanResultsSync(); 234 console.info("scanInfoList:" + JSON.stringify(scanInfoList)); 235 let len = scanInfoList.length; 236 console.log("wifi received scan info: " + len); 237 if(len > 0){ 238 for (let i = 0; i < len; ++i) { 239 console.info("ssid: " + scanInfoList[i].ssid); 240 console.info("bssid: " + scanInfoList[i].bssid); 241 console.info("capabilities: " + scanInfoList[i].capabilities); 242 console.info("securityType: " + scanInfoList[i].securityType); 243 console.info("rssi: " + scanInfoList[i].rssi); 244 console.info("band: " + scanInfoList[i].band); 245 console.info("frequency: " + scanInfoList[i].frequency); 246 console.info("channelWidth: " + scanInfoList[i].channelWidth); 247 console.info("timestamp: " + scanInfoList[i].timestamp); 248 } 249 } 250 }catch(error){ 251 console.error("failed:" + JSON.stringify(error)); 252 } 253 254``` 255 256## wifiManager.getScanInfoList<sup>10+</sup> 257 258getScanInfoList(): Array<WifiScanInfo> 259 260Obtains the scanning result. 261 262**Required permissions**: ohos.permission.GET_WIFI_INFO 263 264**Atomic service API**: This API can be used in atomic services since API version 12. 265 266**System capability**: SystemCapability.Communication.WiFi.STA 267 268**Return value** 269 270| **Type**| **Description**| 271| -------- | -------- | 272| Array<[WifiScanInfo](#wifiscaninfo9)> | Hotspots detected. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **bssid** in the return value is a real device address. Otherwise, **bssid** is a random device address.| 273 274**Error codes** 275 276For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 277 278| **ID**| **Error Message**| 279| -------- | -------- | 280| 201 | Permission denied. | 281| 801 | Capability not supported. | 282| 2501000 | Operation failed.| 283 284**Example** 285 286```ts 287 import { wifiManager } from '@kit.ConnectivityKit'; 288 289 try { 290 let scanInfoList = wifiManager.getScanInfoList(); 291 console.info("scanInfoList:" + JSON.stringify(scanInfoList)); 292 let len = scanInfoList.length; 293 console.log("wifi received scan info: " + len); 294 if(len > 0){ 295 for (let i = 0; i < len; ++i) { 296 console.info("ssid: " + scanInfoList[i].ssid); 297 console.info("bssid: " + scanInfoList[i].bssid); 298 console.info("capabilities: " + scanInfoList[i].capabilities); 299 console.info("securityType: " + scanInfoList[i].securityType); 300 console.info("rssi: " + scanInfoList[i].rssi); 301 console.info("band: " + scanInfoList[i].band); 302 console.info("frequency: " + scanInfoList[i].frequency); 303 console.info("channelWidth: " + scanInfoList[i].channelWidth); 304 console.info("timestamp: " + scanInfoList[i].timestamp); 305 console.info("supportedWifiCategory: " + scanInfoList[i].supportedWifiCategory); 306 console.info("isHiLinkNetwork: " + scanInfoList[i].isHiLinkNetwork); 307 } 308 } 309 }catch(error){ 310 console.error("failed:" + JSON.stringify(error)); 311 } 312 313``` 314 315## WifiScanInfo<sup>9+</sup> 316 317Represents WLAN hotspot information. 318 319**System capability**: SystemCapability.Communication.WiFi.STA 320 321 322| **Name**| **Type**| **Readable**| **Writable**| **Description**| 323| -------- | -------- | -------- | -------- | -------- | 324| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format. The maximum length is 32 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 325| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot, for example, **00:11:22:33:44:55**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 326| bssidType<sup>10+</sup>| [DeviceAddressType](#deviceaddresstype10) | Yes| No| BSSID type of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 327| capabilities | string | Yes| No| Hotspot capabilities.| 328| securityType | [WifiSecurityType](#wifisecuritytype9) | Yes| No| WLAN security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 329| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 330| band | number | Yes| No| Frequency band of the WLAN access point (AP). The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.| 331| frequency | number | Yes| No| Frequency of the WLAN AP.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 332| channelWidth | number | Yes| No| Channel width of the WLAN AP. For details, see [WifiChannelWidth](#wifichannelwidth9).| 333| centerFrequency0 | number | Yes| No| Center frequency of the hotspot.| 334| centerFrequency1 | number | Yes| No| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.| 335| infoElems | Array<[WifiInfoElem](#wifiinfoelem9)> | Yes| No| Information elements.| 336| timestamp | number | Yes| No| Timestamp.| 337| supportedWifiCategory<sup>12+</sup> | [WifiCategory](#wificategory12) | Yes| No| Highest Wi-Fi category supported by the hotspot.| 338| isHiLinkNetwork<sup>12+</sup> | boolean | Yes| No| Whether the hotspot supports HiLink. The value **true** indicates that the hotspot supports HiLink. The value **false** means the opposite.| 339 340## DeviceAddressType<sup>10+</sup> 341 342Enumerates the Wi-Fi device address (MAC/BSSID) types. 343 344**System capability**: SystemCapability.Communication.WiFi.Core 345 346**Atomic service API**: This API can be used in atomic services since API version 12. 347 348| **Name**| **Value**| **Description**| 349| -------- | -------- | -------- | 350| RANDOM_DEVICE_ADDRESS | 0 | Random device address.| 351| REAL_DEVICE_ADDRESS | 1 | Read device address.| 352 353## WifiSecurityType<sup>9+</sup> 354 355Enumerates the WLAN security types. 356 357**System capability**: SystemCapability.Communication.WiFi.Core 358 359 360| **Name**| **Value**| **Description**| 361| -------- | -------- | -------- | 362| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.| 363| WIFI_SEC_TYPE_OPEN | 1 | Open security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 364| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP). The candidate network configuration does not support this encryption type.| 365| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK).| 366| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).| 367| WIFI_SEC_TYPE_EAP | 5 | Extensible Authentication protocol (EAP).| 368| WIFI_SEC_TYPE_EAP_SUITE_B | 6 | Suite B 192-bit encryption.| 369| WIFI_SEC_TYPE_OWE | 7 | Opportunistic Wireless Encryption (OWE).| 370| WIFI_SEC_TYPE_WAPI_CERT | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).| 371| WIFI_SEC_TYPE_WAPI_PSK | 9 | WAPI-PSK.| 372 373 374## WifiBandType<sup>10+</sup> 375 376Enumerates the Wi-Fi band types. 377 378**System capability**: SystemCapability.Communication.WiFi.STA 379 380| **Name**| **Value**| **Description**| 381| -------- | -------- | -------- | 382| WIFI_BAND_NONE | 0 | Invalid band type| 383| WIFI_BAND_2G | 1 | 2.4 GHz| 384| WIFI_BAND_5G | 2 | 5 GHz| 385| WIFI_BAND_6G | 3 | 6 GHz| 386| WIFI_BAND_60G | 4 | 60 GHz| 387 388## WifiStandard<sup>10+</sup> 389 390Enumerates the Wi-Fi standards. 391 392**System capability**: SystemCapability.Communication.WiFi.STA 393 394| **Name**| **Value**| **Description**| 395| -------- | -------- | -------- | 396| WIFI_STANDARD_UNDEFINED | 0 | Invalid Wi-Fi standard| 397| WIFI_STANDARD_11A | 1 | 802.11a| 398| WIFI_STANDARD_11B | 2 | 802.11b| 399| WIFI_STANDARD_11G | 3 | 802.11g| 400| WIFI_STANDARD_11N | 4 | 802.11n| 401| WIFI_STANDARD_11AC | 5 | 802.11ac| 402| WIFI_STANDARD_11AX | 6 | 802.11ax| 403| WIFI_STANDARD_11AD | 7 | 802.11ad| 404 405## WifiInfoElem<sup>9+</sup> 406 407Represents a WLAN information element. 408 409**System capability**: SystemCapability.Communication.WiFi.STA 410 411 412| **Name**| **Type**| **Readable**| **Writable**| **Description**| 413| -------- | -------- | -------- | -------- | -------- | 414| eid | number | Yes| No| ID of the information element.| 415| content | Uint8Array | Yes| No| Content of the information element.| 416 417 418## WifiChannelWidth<sup>9+</sup> 419 420Enumerates the WLAN channel widths. 421 422**System capability**: SystemCapability.Communication.WiFi.STA 423 424 425| **Name**| **Value**| **Description**| 426| -------- | -------- | -------- | 427| WIDTH_20MHZ | 0 | 20 MHz| 428| WIDTH_40MHZ | 1 | 40 MHz| 429| WIDTH_80MHZ | 2 | 80 MHz| 430| WIDTH_160MHZ | 3 | 160 MHz| 431| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>| 432| WIDTH_INVALID | 5 | Invalid value| 433 434 435## WifiDeviceConfig<sup>9+</sup> 436 437Represents the WLAN configuration. 438 439**System capability**: SystemCapability.Communication.WiFi.STA 440 441 442| **Name**| **Type**| **Readable**| **Writable**| **Description**| 443| -------- | -------- | -------- | -------- | -------- | 444| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format. The maximum length is 32 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 445| bssid | string | Yes| No| Hotspot BSSID, for example, **00:11:22:33:44:55**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 446| bssidType<sup>10+</sup> | [DeviceAddressType](#deviceaddresstype10) | Yes| No| BSSID type of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 447| preSharedKey | string | Yes| No| PSK of the hotspot, which cannot exceed 64 bytes.<br>When **securityType** is **WIFI_SEC_TYPE_OPEN**, this parameter must be an empty string. When **securityType** is any other value, this parameter cannot be empty.<br>When **securityType** is **WIFI_SEC_TYPE_WEP**, the PSK must be of 5, 10, 13, 26, 16, or 32 bytes. If the PSK length is 10, 26, 16, or 32 bytes, the PSK must be a hexadecimal number.<br>When **securityType** is **WIFI_SEC_TYPE_SAE**, the minimum PSK length is 1 byte.<br>When **securityType** is **WIFI_SEC_TYPE_PSK**, the minimum PSK length is 8 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 448| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.| 449| securityType | [WifiSecurityType](#wifisecuritytype9)| Yes| No| Security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 450| eapConfig<sup>10+</sup> | [WifiEapConfig](#wifieapconfig10) | Yes| No| EAP configuration. This parameter is mandatory only when **securityType** is **WIFI_SEC_TYPE_EAP**.| 451| wapiConfig<sup>12+</sup> | [WifiWapiConfig](#wifiwapiconfig12) | Yes| No| WAPI configuration. This parameter is mandatory only when **securityType** is **WIFI_SEC_TYPE_WAPI_CERT** or** WIFI_SEC_TYPE_WAPI_PSK**.| 452 453## WifiEapConfig<sup>10+</sup> 454 455Represents EAP configuration information. 456 457**System capability**: SystemCapability.Communication.WiFi.STA 458 459| **Name**| **Type**| **Readable**| **Writable**| **Description**| 460| -------- | -------- | -------- | -------- | -------- | 461| eapMethod | [EapMethod](#eapmethod10) | Yes| No| EAP authentication method.| 462| phase2Method | [Phase2Method](#phase2method10) | Yes| No| Phase 2 authentication method. This parameter is mandatory only when **eapMethod** is **EAP_PEAP** or **EAP_TTLS**.| 463| identity | string | Yes| No| Identity Information. When **eapMethod** is **EAP_PEAP**, **EAP_TLS**, or **EAP_PWD**, this parameter cannot be empty.| 464| anonymousIdentity | string | Yes| No| Anonymous identity. This parameter is not used currently.| 465| password | string | Yes| No| Password. When **eapMethod** is **EAP_PEAP** or **EAP_PWD**, this parameter cannot be empty.| 466| caCertAlias | string | Yes| No| CA certificate alias.| 467| caPath | string | Yes| No| CA certificate path.| 468| clientCertAlias | string | Yes| No| Client certificate alias.| 469| certEntry | Uint8Array | Yes| Yes| CA certificate content. If **eapMethod** is **EAP_TLS** and this parameter is not specified, **clientCertAlias** cannot be empty.| 470| certPassword | string | Yes| Yes| CA certificate password.| 471| altSubjectMatch | string | Yes| No| A string to match the alternate subject.| 472| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.| 473| realm | string | Yes| No| Realm for the passpoint credential.| 474| plmn | string | Yes| No| Public land mobile network (PLMN) of the passpoint credential provider.| 475| eapSubId | number | Yes| No| Sub-ID of the SIM card.| 476 477 478## WifiWapiConfig<sup>12+</sup> 479 480Represents WAPI configuration. 481 482**System capability**: SystemCapability.Communication.WiFi.STA 483 484| **Name**| **Type**| **Readable**| **Writable**| **Description**| 485| -------- | -------- | -------- | -------- | -------- | 486| wapiPskType | [WapiPskType](#wapipsktype12)| Yes| Yes| PSK type.| 487| wapiAsCert | string | No| Yes| AS certificate.| 488| wapiUserCert | string | No| Yes| User Certificate.| 489 490## WapiPskType<sup>12+</sup> 491 492Enumerates the WAPI authentication types. 493 494**System capability**: SystemCapability.Communication.WiFi.Core 495 496| Name| Value| Description| 497| -------- | -------- | -------- | 498| WAPI_PSK_ASCII | 0 | ASCII.| 499| WAPI_PSK_HEX | 1 | HEX.| 500 501## EapMethod<sup>10+</sup> 502 503Enumerates the EAP authentication methods. 504 505**System capability**: SystemCapability.Communication.WiFi.STA 506 507| Name| Value| Description| 508| -------- | -------- | -------- | 509| EAP_NONE | 0 | Not specified.| 510| EAP_PEAP | 1 | PEAP.| 511| EAP_TLS | 2 | TLS.| 512| EAP_TTLS | 3 | TTLS.| 513| EAP_PWD | 4 | Password.| 514| EAP_SIM | 5 | SIM.| 515| EAP_AKA | 6 | AKA.| 516| EAP_AKA_PRIME | 7 | AKA Prime.| 517| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.| 518 519## Phase2Method<sup>10+</sup> 520 521Enumerates the Phase 2 authentication methods. 522 523**System capability**: SystemCapability.Communication.WiFi.STA 524 525| Name| Value| Description| 526| -------- | -------- | -------- | 527| PHASE2_NONE | 0 | Not specified.| 528| PHASE2_PAP | 1 | PAP.| 529| PHASE2_MSCHAP | 2 | MS-CHAP.| 530| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.| 531| PHASE2_GTC | 4 | GTC.| 532| PHASE2_SIM | 5 | SIM.| 533| PHASE2_AKA | 6 | AKA.| 534| PHASE2_AKA_PRIME | 7 | AKA Prime.| 535 536## WifiCategory<sup>12+</sup> 537 538Represents the highest Wi-Fi type supported by a hotspot. 539 540**System capability**: SystemCapability.Communication.WiFi.STA 541 542| Name| Value| Description| 543| -------- | -------- | -------- | 544| DEFAULT | 1 | Default, that is, Wi-Fi types lower than Wi-Fi 6.| 545| WIFI6 | 2 | Wi-Fi 6| 546| WIFI6_PLUS | 3 | Wi-Fi 6+| 547 548## wifiManager.addCandidateConfig<sup>9+</sup> 549 550addCandidateConfig(config: WifiDeviceConfig): Promise<number> 551 552Adds the configuration of a candidate network. This API uses a promise to return the result. 553 554**Required permissions**: ohos.permission.SET_WIFI_INFO 555 556**Atomic service API**: This API can be used in atomic services since API version 12. 557 558**System capability**: SystemCapability.Communication.WiFi.STA 559 560**Parameters** 561 562| **Name**| **Type**| **Mandatory**| **Description**| 563| -------- | -------- | -------- | -------- | 564| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 565 566**Return value** 567 568 | **Type**| **Description**| 569 | -------- | -------- | 570 | Promise<number> | Promise used to return the network configuration ID.| 571 572**Error codes** 573 574For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 575 576| **ID**| **Error Message**| 577| -------- | ---------------------------- | 578| 201 | Permission denied. | 579| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.| 580| 801 | Capability not supported. | 581| 2501000 | Operation failed.| 582 583**Example** 584`````ts 585 import { wifiManager } from '@kit.ConnectivityKit'; 586 587 try { 588 let config:wifiManager.WifiDeviceConfig = { 589 ssid : "****", 590 preSharedKey : "****", 591 securityType : 0 592 } 593 wifiManager.addCandidateConfig(config).then(result => { 594 console.info("result:" + JSON.stringify(result)); 595 }).catch((err:number) => { 596 console.error("failed:" + JSON.stringify(err)); 597 }); 598 }catch(error){ 599 console.error("failed:" + JSON.stringify(error)); 600 } 601````` 602 603## wifiManager.addCandidateConfig<sup>9+</sup> 604 605addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 606 607Adds the configuration of a candidate network. This API uses an asynchronous callback to return the result. 608 609**Required permissions**: ohos.permission.SET_WIFI_INFO 610 611**System capability**: SystemCapability.Communication.WiFi.STA 612 613**Atomic service API**: This API can be used in atomic services since API version 12. 614 615**Parameters** 616 617| **Name**| **Type**| **Mandatory**| **Description**| 618| -------- | -------- | -------- | -------- | 619| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 620| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.| 621 622**Error codes** 623 624For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 625 626| **ID**| **Error Message**| 627| -------- | ---------------------------- | 628| 201 | Permission denied. | 629| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.| 630| 801 | Capability not supported. | 631| 2501000 | Operation failed.| 632 633**Example** 634`````ts 635 import { wifiManager } from '@kit.ConnectivityKit'; 636 637 try { 638 let config:wifiManager.WifiDeviceConfig = { 639 ssid : "****", 640 preSharedKey : "****", 641 securityType : 0 642 } 643 wifiManager.addCandidateConfig(config,(error,result) => { 644 console.info("result:" + JSON.stringify(result)); 645 }); 646 }catch(error){ 647 console.error("failed:" + JSON.stringify(error)); 648 } 649````` 650 651## wifiManager.removeCandidateConfig<sup>9+</sup> 652 653removeCandidateConfig(networkId: number): Promise<void> 654 655Removes the configuration of a candidate network. This API uses a promise to return the result. 656 657**Required permissions**: ohos.permission.SET_WIFI_INFO 658 659**Atomic service API**: This API can be used in atomic services since API version 12. 660 661**System capability**: SystemCapability.Communication.WiFi.STA 662 663**Parameters** 664 665 | **Name**| **Type**| **Mandatory**| **Description**| 666 | -------- | -------- | -------- | -------- | 667 | networkId | number | Yes| ID of the network configuration to remove.| 668 669**Return value** 670 671 | **Type**| **Description**| 672 | -------- | -------- | 673 | Promise<void> | Promise used to return the result.| 674 675**Error codes** 676 677For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 678 679| **ID**| **Error Message**| 680| -------- | ---------------------------- | 681| 201 | Permission denied. | 682| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.| 683| 801 | Capability not supported. | 684| 2501000 | Operation failed.| 685| 2501001 | Wi-Fi STA disabled. | 686 687**Example** 688 689```ts 690 import { wifiManager } from '@kit.ConnectivityKit'; 691 692 try { 693 let networkId = 0; 694 wifiManager.removeCandidateConfig(networkId).then(result => { 695 console.info("result:" + JSON.stringify(result)); 696 }).catch((err:number) => { 697 console.error("failed:" + JSON.stringify(err)); 698 }); 699 }catch(error){ 700 console.error("failed:" + JSON.stringify(error)); 701 } 702``` 703 704## wifiManager.removeCandidateConfig<sup>9+</sup> 705 706removeCandidateConfig(networkId: number, callback: AsyncCallback<void>): void 707 708Removes the configuration of a candidate network. This API uses an asynchronous callback to return the result. 709 710**Required permissions**: ohos.permission.SET_WIFI_INFO 711 712**System capability**: SystemCapability.Communication.WiFi.STA 713 714**Atomic service API**: This API can be used in atomic services since API version 12. 715 716**Parameters** 717 718 | **Name**| **Type**| **Mandatory**| **Description**| 719 | -------- | -------- | -------- | -------- | 720 | networkId | number | Yes| ID of the network configuration to remove.| 721 | callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **0**. If the operation fails, **error** is not **0**.| 722 723**Error codes** 724 725For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 726 727| **ID**| **Error Message**| 728| -------- | ---------------------------- | 729| 201 | Permission denied. | 730| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 731| 801 | Capability not supported. | 732| 2501000 | Operation failed.| 733| 2501001 | Wi-Fi STA disabled. | 734 735**Example** 736```ts 737 import { wifiManager } from '@kit.ConnectivityKit'; 738 739 try { 740 let networkId = 0; 741 wifiManager.removeCandidateConfig(networkId,(error,result) => { 742 console.info("result:" + JSON.stringify(result)); 743 }); 744 }catch(error){ 745 console.error("failed:" + JSON.stringify(error)); 746 } 747``` 748 749## wifiManager.getCandidateConfigs<sup>9+</sup> 750 751getCandidateConfigs(): Array<WifiDeviceConfig> 752 753Obtains candidate network configuration. 754 755**Required permissions**: 756 757API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 758 759API version 10 and later: ohos.permission.GET_WIFI_INFO 760 761**Atomic service API**: This API can be used in atomic services since API version 12. 762 763**System capability**: SystemCapability.Communication.WiFi.STA 764 765**Return value** 766 767 | **Type**| **Description**| 768 | -------- | -------- | 769 | Array<[WifiDeviceConfig](#wifideviceconfig9)> | Candidate network configuration obtained.| 770 771**Error codes** 772 773For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 774 775| **ID**| **Error Message**| 776| -------- | ---------------------------- | 777| 201 | Permission denied. | 778| 801 | Capability not supported. | 779| 2501000 | Operation failed.| 780 781**Example** 782 783```ts 784 import { wifiManager } from '@kit.ConnectivityKit'; 785 786 try { 787 let configs = wifiManager.getCandidateConfigs(); 788 console.info("configs:" + JSON.stringify(configs)); 789 let len = configs.length; 790 console.log("result len: " + len); 791 if(len > 0){ 792 for (let i = 0; i < len; ++i) { 793 console.info("ssid: " + configs[i].ssid); 794 console.info("bssid: " + configs[i].bssid); 795 } 796 } 797 }catch(error){ 798 console.error("failed:" + JSON.stringify(error)); 799 } 800 801``` 802 803## wifiManager.connectToCandidateConfig<sup>9+</sup> 804 805connectToCandidateConfig(networkId: number): void 806 807Connects to a candidate network added by the application. If the device is already connected to a hotspot, disconnect it from the hotspot first. 808 809**Required permissions**: ohos.permission.SET_WIFI_INFO 810 811**Atomic service API**: This API can be used in atomic services since API version 12. 812 813**System capability**: SystemCapability.Communication.WiFi.STA 814 815**Parameters** 816 817 | **Name**| **Type**| **Mandatory**| **Description**| 818 | -------- | -------- | -------- | -------- | 819 | networkId | number | Yes| ID of the candidate network configuration.| 820 821**Error codes** 822 823For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 824 825| **ID**| **Error Message**| 826| -------- | ---------------------------- | 827| 201 | Permission denied. | 828| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 829| 801 | Capability not supported. | 830| 2501000 | Operation failed.| 831| 2501001 | Wi-Fi STA disabled.| 832 833**Example** 834```ts 835 import { wifiManager } from '@kit.ConnectivityKit'; 836 837 try { 838 let networkId = 0; // Candidate network ID, which is generated when a candidate network is added. The value is obtained from WifiDeviceConfig.netId. 839 wifiManager.connectToCandidateConfig(networkId); 840 }catch(error){ 841 console.error("failed:" + JSON.stringify(error)); 842 } 843 844``` 845 846 847## wifiManager.getSignalLevel<sup>9+</sup> 848 849getSignalLevel(rssi: number, band: number): number 850 851Obtains the WLAN signal level. 852 853**Required permissions**: ohos.permission.GET_WIFI_INFO 854 855**System capability**: SystemCapability.Communication.WiFi.STA 856 857**Parameters** 858 859 | **Name**| **Type**| **Mandatory**| **Description**| 860 | -------- | -------- | -------- | -------- | 861 | rssi | number | Yes| RSSI of the hotspot, in dBm.| 862 | band | number | Yes| Frequency band of the WLAN AP. The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.| 863 864**Return value** 865 866 | **Type**| **Description**| 867 | -------- | -------- | 868 | number | Signal level obtained. The value range is [0, 4].| 869 870**Error codes** 871 872For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 873 874| **ID**| **Error Message**| 875| -------- | -------- | 876| 201 | Permission denied. | 877| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. | 878| 801 | Capability not supported. | 879| 2501000 | Operation failed.| 880 881**Example** 882```ts 883 import { wifiManager } from '@kit.ConnectivityKit'; 884 885 try { 886 let rssi = 0; 887 let band = 0; 888 let level = wifiManager.getSignalLevel(rssi,band); 889 console.info("level:" + JSON.stringify(level)); 890 }catch(error){ 891 console.error("failed:" + JSON.stringify(error)); 892 } 893 894``` 895 896## wifiManager.getLinkedInfo<sup>9+</sup> 897 898getLinkedInfo(): Promise<WifiLinkedInfo> 899 900Obtains WLAN connection information. This API uses a promise to return the result. 901 902**Required permissions**: ohos.permission.GET_WIFI_INFO 903 904If **macType** to be obtained is **1** (device MAC address), the caller must have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an empty string is returned in **macAddress**. 905 906**Atomic service API**: This API can be used in atomic services since API version 12. 907 908**System capability**: SystemCapability.Communication.WiFi.STA 909 910**Return value** 911 912 | Type| Description| 913 | -------- | -------- | 914 | Promise<[WifiLinkedInfo](#wifilinkedinfo9)> | Promise used to return the WLAN connection information.| 915 916**Error codes** 917 918For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 919 920| **ID**| **Error Message**| 921| -------- | -------- | 922| 201 | Permission denied. | 923| 801 | Capability not supported. | 924| 2501000 | Operation failed.| 925| 2501001 | Wi-Fi STA disabled.| 926 927## wifiManager.getLinkedInfo<sup>9+</sup> 928 929getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void 930 931Obtains WLAN connection information. This API uses an asynchronous callback to return the result. 932 933**Required permissions**: ohos.permission.GET_WIFI_INFO 934 935If **macType** to be obtained is **1** (device MAC address), the caller must have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an empty string is returned in **macAddress**. 936 937**System capability**: SystemCapability.Communication.WiFi.STA 938 939**Parameters** 940 941 | Name| Type| Mandatory| Description| 942 | -------- | -------- | -------- | -------- | 943 | callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo9)> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If the operation fails, **err** is not **0**.| 944 945**Error codes** 946 947For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 948 949| **ID**| **Error Message**| 950| -------- | -------- | 951| 201 | Permission denied. | 952| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 953| 801 | Capability not supported. | 954| 2501000 | Operation failed.| 955| 2501001 | Wi-Fi STA disabled.| 956 957**Example** 958```ts 959 import { wifiManager } from '@kit.ConnectivityKit'; 960 961 wifiManager.getLinkedInfo((err, data) => { 962 if (err) { 963 console.error("get linked info error"); 964 return; 965 } 966 console.info("get wifi linked info: " + JSON.stringify(data)); 967 }); 968 969 wifiManager.getLinkedInfo().then(data => { 970 console.info("get wifi linked info: " + JSON.stringify(data)); 971 }).catch((error:number) => { 972 console.info("get linked info error"); 973 }); 974``` 975 976 977## WifiLinkedInfo<sup>9+</sup> 978 979Represents the WLAN connection information. 980 981**System capability**: SystemCapability.Communication.WiFi.STA 982 983| Name| Type| Readable| Writable| Description| 984| -------- | -------- | -------- | -------- | -------- | 985| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 986| bssid | string | Yes| No| BSSID of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 987| rssi | number | Yes| No| RSSI of the hotspot, in dBm.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 988| band | number | Yes| No| Band of the WLAN AP. The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.| 989| linkSpeed | number | Yes| No| Uplink speed of the WLAN AP.| 990| rxLinkSpeed<sup>10+</sup> | number | Yes| No| Downlink speed of the WLAN AP.| 991| maxSupportedTxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.| 992| maxSupportedRxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.| 993| frequency | number | Yes| No| Frequency of the WLAN AP.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 994| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.| 995| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.| 996| macType | number | Yes| No| MAC address type. <br>The value **0** indicates random MAC address, and **1** indicates device MAC address.| 997| macAddress | string | Yes| No| MAC address of the device.| 998| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.| 999| connState | [ConnState](#connstate9) | Yes| No| WLAN connection state.| 1000| channelWidth<sup>10+</sup> | [WifiChannelWidth](#wifichannelwidth9) | Yes| No| Channel bandwidth of the connected hotspot.| 1001| wifiStandard<sup>10+</sup> | [WifiStandard](#wifistandard10) | Yes| No| Wi-Fi standard used by the connected hotspot.| 1002| supportedWifiCategory<sup>12+</sup> | [WifiCategory](#wificategory12) | Yes| No| Highest Wi-Fi category supported by the hotspot.| 1003| isHiLinkNetwork<sup>12+</sup> | boolean | Yes| No| Whether the hotspot supports HiLink. The value **true** indicates that the hotspot supports HiLink. The value **false** means the opposite.| 1004 1005## ConnState<sup>9+</sup> 1006 1007Enumerates the WLAN connection states. 1008 1009**System capability**: SystemCapability.Communication.WiFi.STA 1010 1011| Name| Value| Description| 1012| -------- | -------- | -------- | 1013| SCANNING | 0 | The device is scanning for available APs.| 1014| CONNECTING | 1 | A WLAN connection is being established.| 1015| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.| 1016| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.| 1017| CONNECTED | 4 | A WLAN connection is established.| 1018| DISCONNECTING | 5 | The WLAN connection is being disconnected.| 1019| DISCONNECTED | 6 | The WLAN connection is disconnected.| 1020| UNKNOWN | 7 | Failed to set up the WLAN connection.| 1021 1022 1023## wifiManager.isConnected<sup>9+</sup> 1024 1025isConnected(): boolean 1026 1027Checks whether WLAN is connected. 1028 1029**Required permissions**: ohos.permission.GET_WIFI_INFO 1030 1031**Atomic service API**: This API can be used in atomic services since API version 12. 1032 1033**System capability**: SystemCapability.Communication.WiFi.STA 1034 1035**Return value** 1036 1037 | **Type**| **Description**| 1038 | -------- | -------- | 1039 | boolean | Returns **true** if WLAN is connected; returns **false** otherwise.| 1040 1041**Error codes** 1042 1043For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1044 1045| **ID**| **Error Message**| 1046| -------- | -------- | 1047| 201 | Permission denied. | 1048| 801 | Capability not supported. | 1049| 2501000 | Operation failed.| 1050 1051**Example** 1052```ts 1053 import { wifiManager } from '@kit.ConnectivityKit'; 1054 1055 try { 1056 let ret = wifiManager.isConnected(); 1057 console.info("isConnected:" + ret); 1058 }catch(error){ 1059 console.error("failed:" + JSON.stringify(error)); 1060 } 1061 1062``` 1063 1064 1065## wifiManager.isFeatureSupported<sup>9+</sup> 1066 1067isFeatureSupported(featureId: number): boolean 1068 1069Checks whether the device supports the specified WLAN feature. 1070 1071**Required permissions**: ohos.permission.GET_WIFI_INFO 1072 1073**System capability**: SystemCapability.Communication.WiFi.Core 1074 1075**Parameters** 1076 1077 | **Name**| **Type**| Mandatory| **Description**| 1078 | -------- | -------- | -------- | -------- | 1079 | featureId | number | Yes| Feature ID.| 1080 1081**Feature IDs** 1082 1083| Value| Description| 1084| -------- | -------- | 1085| 0x0001 | WLAN infrastructure mode| 1086| 0x0002 | 5 GHz feature| 1087| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature| 1088| 0x0008 | Wi-Fi Direct| 1089| 0x0010 | SoftAP| 1090| 0x0040 | Wi-Fi Aware| 1091| 0x8000 | WLAN AP/STA concurrency| 1092| 0x8000000 | WPA3 Personal (WPA-3 SAE)| 1093| 0x10000000 | WPA3-Enterprise Suite B | 1094| 0x20000000 | Enhanced open feature| 1095 1096**Return value** 1097 1098 | **Type**| **Description**| 1099 | -------- | -------- | 1100 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1101 1102**Error codes** 1103 1104For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1105 1106| **ID**| **Error Message**| 1107 | -------- | -------- | 1108| 201 | Permission denied. | 1109| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. | 1110| 801 | Capability not supported. | 1111| 2401000 | Operation failed.| 1112 1113**Example** 1114```ts 1115 import { wifiManager } from '@kit.ConnectivityKit'; 1116 1117 try { 1118 let featureId = 0; 1119 let ret = wifiManager.isFeatureSupported(featureId); 1120 console.info("isFeatureSupported:" + ret); 1121 }catch(error){ 1122 console.error("failed:" + JSON.stringify(error)); 1123 } 1124 1125``` 1126 1127 1128## wifiManager.getIpInfo<sup>9+</sup> 1129 1130getIpInfo(): IpInfo 1131 1132Obtains IP information. 1133 1134**Required permissions**: ohos.permission.GET_WIFI_INFO 1135 1136**System capability**: SystemCapability.Communication.WiFi.STA 1137 1138**Return value** 1139 1140 | **Type**| **Description**| 1141 | -------- | -------- | 1142 | [IpInfo](#ipinfo9) | IP information obtained.| 1143 1144**Error codes** 1145 1146For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1147 1148| **ID**| **Error Message**| 1149| -------- | -------- | 1150| 201 | Permission denied. | 1151| 801 | Capability not supported. | 1152| 2501000 | Operation failed.| 1153 1154**Example** 1155```ts 1156 import { wifiManager } from '@kit.ConnectivityKit'; 1157 1158 try { 1159 let info = wifiManager.getIpInfo(); 1160 console.info("info:" + JSON.stringify(info)); 1161 }catch(error){ 1162 console.error("failed:" + JSON.stringify(error)); 1163 } 1164``` 1165 1166## IpInfo<sup>9+</sup> 1167 1168Represents IP information. 1169 1170**System capability**: SystemCapability.Communication.WiFi.STA 1171 1172| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1173| -------- | -------- | -------- | -------- | -------- | 1174| ipAddress | number | Yes| No| IP address.| 1175| gateway | number | Yes| No| Gateway.| 1176| netmask | number | Yes| No| Subnet mask.| 1177| primaryDns | number | Yes| No| IP address of the preferred DNS server.| 1178| secondDns | number | Yes| No| IP address of the alternate DNS server.| 1179| serverIp | number | Yes| No| IP address of the DHCP server.| 1180| leaseDuration | number | Yes| No| Lease duration of the IP address, in seconds.| 1181 1182 1183## wifiManager.getIpv6Info<sup>10+</sup> 1184 1185getIpv6Info(): Ipv6Info 1186 1187Obtains IPv6 information. 1188 1189**Required permissions**: ohos.permission.GET_WIFI_INFO 1190 1191**System capability**: SystemCapability.Communication.WiFi.STA 1192 1193**Return value** 1194 1195| **Type**| **Description**| 1196| -------- | -------- | 1197| [Ipv6Info](#ipv6info10) | IPv6 information obtained.| 1198 1199**Error codes** 1200 1201For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1202 1203| **ID**| **Error Message**| 1204| -------- | -------- | 1205| 201 | Permission denied. | 1206| 801 | Capability not supported. | 1207| 2501000 | Operation failed.| 1208 1209**Example** 1210```ts 1211 import { wifiManager } from '@kit.ConnectivityKit'; 1212 1213 try { 1214 let info = wifiManager.getIpv6Info(); 1215 console.info("info:" + JSON.stringify(info)); 1216 }catch(error){ 1217 console.error("failed:" + JSON.stringify(error)); 1218 } 1219``` 1220## Ipv6Info<sup>10+</sup> 1221 1222Represents the IPv6 information. 1223 1224**System capability**: SystemCapability.Communication.WiFi.STA 1225 1226| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1227| -------- | -------- | -------- | -------- | -------- | 1228| linkIpv6Address | string | Yes| No| IPv6 address of the link.| 1229| globalIpv6Address | string | Yes| No| Global IPv6 address.| 1230| randomGlobalIpv6Address | string | Yes| No| Random global IPv6 address. This parameter is reserved.| 1231| uniqueIpv6Address<sup>12+</sup> | string | Yes| No| Unique local address (ULA) in IPv6 format.| 1232| randomUniqueIpv6Address<sup>12+</sup> | string | Yes| No| Random unique local address (RULA) in IPv6 format.| 1233| gateway | string | Yes| No| Gateway.| 1234| netmask | string | Yes| No| Subnet mask.| 1235| primaryDNS | string | Yes| No| IPv6 address of the preferred DNS server.| 1236| secondDNS | string | Yes| No| IPv6 address of the alternate DNS server.| 1237 1238## wifiManager.getCountryCode<sup>9+</sup> 1239 1240getCountryCode(): string 1241 1242Obtains the country code. 1243 1244**Required permissions**: ohos.permission.GET_WIFI_INFO 1245 1246**System capability**: SystemCapability.Communication.WiFi.Core 1247 1248**Return value** 1249 1250 | **Type**| **Description**| 1251 | -------- | -------- | 1252 | string | Country code obtained.| 1253 1254**Error codes** 1255 1256For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1257 1258| **ID**| **Error Message**| 1259| -------- | -------- | 1260| 201 | Permission denied. | 1261| 801 | Capability not supported. | 1262| 2401000 | Operation failed.| 1263 1264**Example** 1265```ts 1266 import { wifiManager } from '@kit.ConnectivityKit'; 1267 1268 try { 1269 let code = wifiManager.getCountryCode(); 1270 console.info("code:" + code); 1271 }catch(error){ 1272 console.error("failed:" + JSON.stringify(error)); 1273 } 1274``` 1275 1276 1277 1278 1279## wifiManager.isBandTypeSupported<sup>10+</sup> 1280 1281isBandTypeSupported(bandType: WifiBandType): boolean 1282 1283Checks whether the current frequency band is supported. 1284 1285**Required permissions**: ohos.permission.GET_WIFI_INFO 1286 1287**System capability**: SystemCapability.Communication.WiFi.STA 1288 1289**Parameters** 1290 1291 | **Name**| **Type**| **Mandatory**| **Description**| 1292 | -------- | -------- | -------- | -------- | 1293 | bandType | [WifiBandType](#wifibandtype10) | Yes| Wi-Fi band type.| 1294 1295**Return value** 1296 1297 | **Type**| **Description**| 1298 | -------- | -------- | 1299 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1300 1301**Error codes** 1302 1303For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1304 1305| **ID**| **Error Message**| 1306| -------- | -------- | 1307| 201 | Permission denied. | 1308| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1309| 801 | Capability not supported. | 1310| 2501000 | Operation failed.| 1311 1312**Example** 1313```ts 1314 import { wifiManager } from '@kit.ConnectivityKit'; 1315 1316 try { 1317 let type = 0; 1318 let isBandTypeSupported = wifiManager.isBandTypeSupported(type); 1319 console.info("isBandTypeSupported:" + isBandTypeSupported); 1320 }catch(error){ 1321 console.error("failed:" + JSON.stringify(error)); 1322 } 1323``` 1324 1325 1326## wifiManager.isMeteredHotspot<sup>11+</sup> 1327 1328isMeteredHotspot(): boolean 1329 1330Checks whether the Wi-Fi network connected to the device is a smartphone hotspot. 1331 1332**Required permissions**: ohos.permission.GET_WIFI_INFO 1333 1334**System capability**: SystemCapability.Communication.WiFi.STA 1335 1336**Return value** 1337 1338 | **Type**| **Description**| 1339 | -------- | -------- | 1340 | boolean | Returns **true** if the Wi-Fi network connected is a smartphone hotspot; returns **false** otherwise.| 1341 1342**Error codes** 1343 1344For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1345 1346| **ID**| **Error Message**| 1347| -------- | -------- | 1348| 201 | Permission denied. | 1349| 801 | Capability not supported. | 1350| 2501000 | Operation failed.| 1351| 2501001 | Wi-Fi STA disabled. | 1352 1353**Example** 1354 1355```ts 1356 import { wifiManager } from '@kit.ConnectivityKit'; 1357 1358 try { 1359 let isMeteredHotspot = wifiManager.isMeteredHotspot(); 1360 console.info("isMeteredHotspot:" + isMeteredHotspot); 1361 }catch(error){ 1362 console.error("failed:" + JSON.stringify(error)); 1363 } 1364``` 1365 1366 1367 1368## wifiManager.getP2pLinkedInfo<sup>9+</sup> 1369 1370getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo> 1371 1372Obtains P2P link information. This API uses a promise to return the result. 1373 1374**Required permissions**: ohos.permission.GET_WIFI_INFO 1375 1376To obtain **groupOwnerAddr**, the caller must also have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an all-zero address is returned in **groupOwnerAddr**. 1377 1378**System capability**: SystemCapability.Communication.WiFi.P2P 1379 1380**Return value** 1381 1382 | Type| Description| 1383 | -------- | -------- | 1384| Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Promise used to return the P2P link information obtained.| 1385 1386**Error codes** 1387 1388For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1389 1390| **ID**| **Error Message**| 1391| -------- | -------- | 1392| 201 | Permission denied. | 1393| 801 | Capability not supported. | 1394| 2801000 | Operation failed. | 1395 1396 1397## wifiManager.getP2pLinkedInfo<sup>9+</sup> 1398 1399getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void 1400 1401Obtains P2P link information. This API uses an asynchronous callback to return the result. 1402 1403**Required permissions**: ohos.permission.GET_WIFI_INFO 1404 1405To obtain **groupOwnerAddr**, the caller must also have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an all-zero address is returned in **groupOwnerAddr**. 1406 1407**System capability**: SystemCapability.Communication.WiFi.P2P 1408 1409**Parameters** 1410 1411 | Name| Type| Mandatory| Description| 1412 | -------- | -------- | -------- | -------- | 1413 | callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If the operation fails, **err** is not **0**.| 1414 1415**Error codes** 1416 1417For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1418 1419| **ID**| **Error Message**| 1420| -------- | -------- | 1421| 201 | Permission denied. | 1422| 801 | Capability not supported. | 1423| 2801000 | Operation failed. | 1424| 2801001 | Wi-Fi STA disabled. | 1425 1426**Example** 1427```ts 1428 import { wifiManager } from '@kit.ConnectivityKit'; 1429 1430 wifiManager.getP2pLinkedInfo((err, data) => { 1431 if (err) { 1432 console.error("get p2p linked info error"); 1433 return; 1434 } 1435 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 1436 }); 1437 1438 wifiManager.getP2pLinkedInfo().then(data => { 1439 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 1440 }); 1441``` 1442 1443 1444## WifiP2pLinkedInfo<sup>9+</sup> 1445 1446Represents the P2P link information. 1447 1448**System capability**: SystemCapability.Communication.WiFi.P2P 1449 1450| Name| Type| Readable| Writable| Description| 1451| -------- | -------- | -------- | -------- | -------- | 1452| connectState | [P2pConnectState](#p2pconnectstate9) | Yes| No| P2P connection state.| 1453| isGroupOwner | boolean | Yes| No| Whether the device is the group owner.| 1454| groupOwnerAddr | string | Yes| No| IP address of the group. 1455 1456 1457## P2pConnectState<sup>9+</sup> 1458 1459Enumerates the P2P connection states. 1460 1461**System capability**: SystemCapability.Communication.WiFi.P2P 1462 1463| Name| Value| Description| 1464| -------- | -------- | -------- | 1465| DISCONNECTED | 0 | Disconnected.| 1466| CONNECTED | 1 | Connected.| 1467 1468## wifiManager.getCurrentGroup<sup>9+</sup> 1469 1470getCurrentGroup(): Promise<WifiP2pGroupInfo> 1471 1472Obtains the current P2P group information. This API uses a promise to return the result. 1473 1474**Required permissions**: 1475 1476API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1477 1478API version 10 and later: ohos.permission.GET_WIFI_INFO 1479 1480**System capability**: SystemCapability.Communication.WiFi.P2P 1481 1482**Return value** 1483 1484| Type| Description| 1485| -------- | -------- | 1486| Promise<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Promise used to return the P2P group information obtained. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 1487 1488**Error codes** 1489 1490For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1491 1492| **ID**| **Error Message**| 1493| -------- | -------- | 1494| 201 | Permission denied. | 1495| 801 | Capability not supported. | 1496| 2801000 | Operation failed. | 1497 1498## wifiManager.getCurrentGroup<sup>9+</sup> 1499 1500getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void 1501 1502Obtains the current P2P group information. This API uses an asynchronous callback to return the result. 1503 1504**Required permissions**: 1505 1506API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1507 1508API version 10 and later: ohos.permission.GET_WIFI_INFO 1509 1510**System capability**: SystemCapability.Communication.WiFi.P2P 1511 1512**Parameters** 1513 1514| Name| Type| Mandatory| Description| 1515| -------- | -------- | -------- | -------- | 1516| callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If the operation fails, **error** is not **0**. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 1517 1518**Error codes** 1519 1520For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1521 1522| **ID**| **Error Message**| 1523| -------- | -------- | 1524| 201 | Permission denied. | 1525| 801 | Capability not supported. | 1526| 2801000 | Operation failed. | 1527 1528**Example** 1529```ts 1530 import { wifiManager } from '@kit.ConnectivityKit'; 1531 // The current group information can be obtained only after the P2P group is created or the connection is successful. 1532 wifiManager.getCurrentGroup((err, data) => { 1533 if (err) { 1534 console.error("get current P2P group error"); 1535 return; 1536 } 1537 console.info("get current P2P group: " + JSON.stringify(data)); 1538 }); 1539 1540 wifiManager.getCurrentGroup().then(data => { 1541 console.info("get current P2P group: " + JSON.stringify(data)); 1542 }); 1543``` 1544 1545## wifiManager.getP2pPeerDevices<sup>9+</sup> 1546 1547getP2pPeerDevices(): Promise<WifiP2pDevice[]> 1548 1549Obtains the peer device list in the P2P connection. This API uses a promise to return the result. 1550 1551**Required permissions**: 1552 1553API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1554 1555API version 10 and later: ohos.permission.GET_WIFI_INFO 1556 1557**System capability**: SystemCapability.Communication.WiFi.P2P 1558 1559**Return value** 1560 1561| Type| Description| 1562| -------- | -------- | 1563| Promise<[WifiP2pDevice[]](#wifip2pdevice9)> | Promise used to return the peer device list. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 1564 1565**Error codes** 1566 1567For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1568 1569| **ID**| **Error Message**| 1570| -------- | -------- | 1571| 201 | Permission denied. | 1572| 801 | Capability not supported. | 1573| 2801000 | Operation failed. | 1574 1575## wifiManager.getP2pPeerDevices<sup>9+</sup> 1576 1577getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void 1578 1579Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result. 1580 1581**Required permissions**: 1582 1583API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1584 1585API version 10 and later: ohos.permission.GET_WIFI_INFO 1586 1587**System capability**: SystemCapability.Communication.WiFi.P2P 1588 1589**Parameters** 1590 1591| Name| Type| Mandatory| Description| 1592| -------- | -------- | -------- | -------- | 1593| callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If the operation fails, **err** is not **0**. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 1594 1595**Error codes** 1596 1597For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1598 1599| **ID**| **Error Message**| 1600| -------- | -------- | 1601| 201 | Permission denied. | 1602| 801 | Capability not supported. | 1603| 2801000 | Operation failed. | 1604| 2801001 | Wi-Fi STA disabled. | 1605 1606**Example** 1607```ts 1608 import { wifiManager } from '@kit.ConnectivityKit'; 1609 // The peer device list can be obtained only after the P2P discovery is complete. 1610 wifiManager.getP2pPeerDevices((err, data) => { 1611 if (err) { 1612 console.error("get P2P peer devices error"); 1613 return; 1614 } 1615 console.info("get P2P peer devices: " + JSON.stringify(data)); 1616 }); 1617 1618 wifiManager.getP2pPeerDevices().then(data => { 1619 console.info("get P2P peer devices: " + JSON.stringify(data)); 1620 }); 1621``` 1622 1623## WifiP2pDevice<sup>9+</sup> 1624 1625Represents the P2P device information. 1626 1627**System capability**: SystemCapability.Communication.WiFi.P2P 1628 1629| Name| Type| Readable| Writable| Description| 1630| -------- | -------- | -------- | -------- | -------- | 1631| deviceName | string | Yes| No| Device name.| 1632| deviceAddress | string | Yes| No| MAC address of the device.| 1633| deviceAddressType<sup>10+</sup> | [DeviceAddressType](#deviceaddresstype10) | Yes| No| MAC address type of the device.| 1634| primaryDeviceType | string | Yes| No| Type of the primary device.| 1635| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus9) | Yes| No| Device status.| 1636| groupCapabilities | number | Yes| No| Group capabilities.| 1637 1638 1639## P2pDeviceStatus<sup>9+</sup> 1640 1641Enumerates the P2P device states. 1642 1643**System capability**: SystemCapability.Communication.WiFi.P2P 1644 1645| Name| Value| Description| 1646| -------- | -------- | -------- | 1647| CONNECTED | 0 | Connected.| 1648| INVITED | 1 | Invited.| 1649| FAILED | 2 | Failed.| 1650| AVAILABLE | 3 | Available.| 1651| UNAVAILABLE | 4 | Unavailable.| 1652 1653 1654## wifiManager.getP2pLocalDevice<sup>9+</sup> 1655 1656getP2pLocalDevice(): Promise<WifiP2pDevice> 1657 1658Obtains the local device information in the P2P connection. This API uses a promise to return the result. 1659 1660**Required permissions**: 1661 1662API version 9: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1663 1664API version 11 and later: ohos.permission.GET_WIFI_INFO 1665 1666**System capability**: SystemCapability.Communication.WiFi.P2P 1667 1668**Return value** 1669 1670 | Type| Description| 1671 | -------- | -------- | 1672 | Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| 1673 1674**Error codes** 1675 1676For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1677 1678| **ID**| **Error Message**| 1679| -------- | -------- | 1680| 201 | Permission denied. | 1681| 801 | Capability not supported. | 1682| 2801000 | Operation failed. | 1683 1684## wifiManager.getP2pLocalDevice<sup>9+</sup> 1685 1686getP2pLocalDevice(callback: AsyncCallback<WifiP2pDevice>): void 1687 1688Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result. 1689 1690**Required permissions**: 1691 1692API version 9: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1693 1694API version 11 and later: ohos.permission.GET_WIFI_INFO 1695 1696**System capability**: SystemCapability.Communication.WiFi.P2P 1697 1698**Parameters** 1699 1700 | Name| Type| Mandatory| Description| 1701 | -------- | -------- | -------- | -------- | 1702 | callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If the operation fails, **error** is not **0**.| 1703 1704**Error codes** 1705 1706| **ID**| **Error Message**| 1707| -------- | -------- | 1708| 201 | Permission denied. | 1709| 801 | Capability not supported. | 1710| 2801000 | Operation failed. | 1711| 2801001 | Wi-Fi STA disabled. | 1712 1713**Example** 1714```ts 1715 import { wifiManager } from '@kit.ConnectivityKit'; 1716 // The local device information can be obtained only after a P2P group is created or the connection is successful. 1717 wifiManager.getP2pLocalDevice((err, data) => { 1718 if (err) { 1719 console.error("get P2P local device error"); 1720 return; 1721 } 1722 console.info("get P2P local device: " + JSON.stringify(data)); 1723 }); 1724 1725 wifiManager.getP2pLocalDevice().then(data => { 1726 console.info("get P2P local device: " + JSON.stringify(data)); 1727 }); 1728``` 1729 1730## wifiManager.createGroup<sup>9+</sup> 1731 1732createGroup(config: WifiP2PConfig): void 1733 1734Creates a P2P group. 1735 1736**Required permissions**: ohos.permission.GET_WIFI_INFO 1737 1738**System capability**: SystemCapability.Communication.WiFi.P2P 1739 1740**Parameters** 1741 1742| **Name**| **Type**| Mandatory| **Description**| 1743| -------- | -------- | -------- | -------- | 1744| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration. The default **DeviceAddressType** is random device address.| 1745 1746**Error codes** 1747 1748For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1749 1750| **ID**| **Error Message**| 1751| -------- | -------- | 1752| 201 | Permission denied. | 1753| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1754| 801 | Capability not supported. | 1755| 2801000 | Operation failed. | 1756| 2801001 | Wi-Fi STA disabled. | 1757 1758**Example** 1759```ts 1760 import { wifiManager } from '@kit.ConnectivityKit'; 1761 1762 try { 1763 let config:wifiManager.WifiP2PConfig = { 1764 deviceAddress: "****", 1765 netId: 0, 1766 passphrase: "*****", 1767 groupName: "****", 1768 goBand: 0 1769 } 1770 wifiManager.createGroup(config); 1771 1772 }catch(error){ 1773 console.error("failed:" + JSON.stringify(error)); 1774 } 1775``` 1776 1777## WifiP2PConfig<sup>9+</sup> 1778 1779Represents P2P group configuration. 1780 1781**System capability**: SystemCapability.Communication.WiFi.P2P 1782 1783| Name| Type| Readable| Writable| Description| 1784| -------- | -------- | -------- | -------- | -------- | 1785| deviceAddress | string | Yes| No| Device address.| 1786| deviceAddressType<sup>10+</sup>| [DeviceAddressType](#deviceaddresstype10) | Yes| No| Device address type.| 1787| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.| 1788| passphrase | string | Yes| No| Passphrase of the group.| 1789| groupName | string | Yes| No| Name of the group.| 1790| goBand | [GroupOwnerBand](#groupownerband9) | Yes| No| Frequency band of the group.| 1791 1792 1793## GroupOwnerBand<sup>9+</sup> 1794 1795Enumerates the P2P group frequency bands. 1796 1797**System capability**: SystemCapability.Communication.WiFi.P2P 1798 1799| Name| Value| Description| 1800| -------- | -------- | -------- | 1801| GO_BAND_AUTO | 0 | Auto.| 1802| GO_BAND_2GHZ | 1 | 2.4 GHz.| 1803| GO_BAND_5GHZ | 2 | 5 GHz.| 1804 1805 1806## wifiManager.removeGroup<sup>9+</sup> 1807 1808removeGroup(): void 1809 1810Removes this P2P group. 1811 1812**Required permissions**: ohos.permission.GET_WIFI_INFO 1813 1814**System capability**: SystemCapability.Communication.WiFi.P2P 1815 1816**Error codes** 1817 1818For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1819 1820| **ID**| **Error Message**| 1821| -------- | -------- | 1822| 201 | Permission denied. | 1823| 801 | Capability not supported. | 1824| 2801000 | Operation failed. | 1825| 2801001 | Wi-Fi STA disabled. | 1826 1827**Example** 1828```ts 1829 import { wifiManager } from '@kit.ConnectivityKit'; 1830 1831 try { 1832 wifiManager.removeGroup(); 1833 }catch(error){ 1834 console.error("failed:" + JSON.stringify(error)); 1835 } 1836``` 1837 1838## wifiManager.p2pConnect<sup>9+</sup> 1839 1840p2pConnect(config: WifiP2PConfig): void 1841 1842Sets up a P2P connection. 1843 1844**Required permissions**: 1845 1846API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1847 1848API version 10 and later: ohos.permission.GET_WIFI_INFO 1849 1850**System capability**: SystemCapability.Communication.WiFi.P2P 1851 1852**Parameters** 1853 1854| **Name**| **Type**| Mandatory| **Description**| 1855| -------- | -------- | -------- | -------- | 1856| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration. The default **DeviceAddressType** is random device address.| 1857 1858**Error codes** 1859 1860For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1861 1862| **ID**| **Error Message**| 1863| -------- | -------- | 1864| 201 | Permission denied. | 1865| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1866| 801 | Capability not supported. | 1867| 2801000 | Operation failed. | 1868| 2801001 | Wi-Fi STA disabled. | 1869 1870**Example** 1871```ts 1872 import { wifiManager } from '@kit.ConnectivityKit'; 1873 1874 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 1875 console.info("p2p connection change receive event: " + JSON.stringify(result)); 1876 wifiManager.getP2pLinkedInfo((err, data) => { 1877 if (err) { 1878 console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); 1879 return; 1880 } 1881 console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); 1882 }); 1883 } 1884 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 1885 1886 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 1887 console.info("p2p device change receive event: " + JSON.stringify(result)); 1888 } 1889 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 1890 1891 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 1892 console.info("p2p peer device change receive event: " + JSON.stringify(result)); 1893 wifiManager.getP2pPeerDevices((err, data) => { 1894 if (err) { 1895 console.error('failed to get peer devices: ' + JSON.stringify(err)); 1896 return; 1897 } 1898 console.info("get peer devices: " + JSON.stringify(data)); 1899 let len = data.length; 1900 for (let i = 0; i < len; ++i) { 1901 if (data[i].deviceName === "my_test_device") { 1902 console.info("p2p connect to test device: " + data[i].deviceAddress); 1903 let config:wifiManager.WifiP2PConfig = { 1904 deviceAddress:data[i].deviceAddress, 1905 netId:-2, 1906 passphrase:"", 1907 groupName:"", 1908 goBand:0, 1909 } 1910 wifiManager.p2pConnect(config); 1911 } 1912 } 1913 }); 1914 } 1915 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 1916 1917 let recvP2pPersistentGroupChangeFunc = () => { 1918 console.info("p2p persistent group change receive event"); 1919 1920 wifiManager.getCurrentGroup((err, data) => { 1921 if (err) { 1922 console.error('failed to get current group: ' + JSON.stringify(err)); 1923 return; 1924 } 1925 console.info("get current group: " + JSON.stringify(data)); 1926 }); 1927 } 1928 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 1929 1930 setTimeout(() => {wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); 1931 setTimeout(() => {wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); 1932 setTimeout(() => {wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); 1933 setTimeout(() => {wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); 1934 console.info("start discover devices -> " + wifiManager.startDiscoverDevices()); 1935``` 1936 1937## wifiManager.p2pCancelConnect<sup>9+</sup> 1938 1939p2pCancelConnect(): void 1940 1941Cancels the P2P connection being set up. 1942 1943**Required permissions**: ohos.permission.GET_WIFI_INFO 1944 1945**System capability**: SystemCapability.Communication.WiFi.P2P 1946 1947**Error codes** 1948 1949For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1950 1951| **ID**| **Error Message**| 1952| -------- | -------- | 1953| 201 | Permission denied. | 1954| 801 | Capability not supported. | 1955| 2801000 | Operation failed. | 1956| 2801001 | Wi-Fi STA disabled. | 1957 1958**Example** 1959```ts 1960 import { wifiManager } from '@kit.ConnectivityKit'; 1961 1962 try { 1963 wifiManager.p2pCancelConnect(); 1964 }catch(error){ 1965 console.error("failed:" + JSON.stringify(error)); 1966 } 1967``` 1968 1969## wifiManager.startDiscoverDevices<sup>9+</sup> 1970 1971startDiscoverDevices(): void 1972 1973Starts to discover devices. 1974 1975**Required permissions**: 1976 1977API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1978 1979API version 10 and later: ohos.permission.GET_WIFI_INFO 1980 1981**System capability**: SystemCapability.Communication.WiFi.P2P 1982 1983**Error codes** 1984 1985For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1986 1987| **ID**| **Error Message**| 1988| -------- | -------- | 1989| 201 | Permission denied. | 1990| 801 | Capability not supported. | 1991| 2801000 | Operation failed. | 1992| 2801001 | Wi-Fi STA disabled. | 1993 1994**Example** 1995```ts 1996 import { wifiManager } from '@kit.ConnectivityKit'; 1997 1998 try { 1999 wifiManager.startDiscoverDevices(); 2000 }catch(error){ 2001 console.error("failed:" + JSON.stringify(error)); 2002 } 2003``` 2004 2005## wifiManager.stopDiscoverDevices<sup>9+</sup> 2006 2007stopDiscoverDevices(): void 2008 2009Stops discovering devices. 2010 2011**Required permissions**: ohos.permission.GET_WIFI_INFO 2012 2013**System capability**: SystemCapability.Communication.WiFi.P2P 2014 2015**Error codes** 2016 2017For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2018 2019| **ID**| **Error Message**| 2020| -------- | -------- | 2021| 201 | Permission denied. | 2022| 801 | Capability not supported. | 2023| 2801000 | Operation failed. | 2024| 2801001 | Wi-Fi STA disabled. | 2025 2026**Example** 2027```ts 2028 import { wifiManager } from '@kit.ConnectivityKit'; 2029 2030 try { 2031 wifiManager.stopDiscoverDevices(); 2032 }catch(error){ 2033 console.error("failed:" + JSON.stringify(error)); 2034 } 2035``` 2036 2037 2038 2039## WifiP2pGroupInfo<sup>9+</sup> 2040 2041Represents the P2P group information. 2042 2043**System capability**: SystemCapability.Communication.WiFi.P2P 2044 2045| Name| Type| Readable| Writable| Description| 2046| -------- | -------- | -------- | -------- | -------- | 2047| isP2pGo | boolean | Yes| No| Whether the device is the group owner.| 2048| ownerInfo | [WifiP2pDevice](#wifip2pdevice9) | Yes| No| Device information of the group.| 2049| passphrase | string | Yes| No| Passphrase of the group.| 2050| interface | string | Yes| No| Interface name.| 2051| groupName | string | Yes| No| Group name.| 2052| networkId | number | Yes| No| Network ID.| 2053| frequency | number | Yes| No| Frequency of the group.| 2054| clientDevices | [WifiP2pDevice[]](#wifip2pdevice9) | Yes| No| List of connected devices.| 2055| goIpAddress | string | Yes| No| IP address of the group.| 2056 2057 2058## wifiManager.on('wifiStateChange')<sup>9+</sup> 2059 2060on(type: "wifiStateChange", callback: Callback<number>): void 2061 2062Subscribes to WLAN state changes. 2063 2064**Required permissions**: ohos.permission.GET_WIFI_INFO 2065 2066**Atomic service API**: This API can be used in atomic services since API version 12. 2067 2068**System capability**: SystemCapability.Communication.WiFi.STA 2069 2070**Parameters** 2071 2072 | **Name**| **Type**| **Mandatory**| **Description**| 2073 | -------- | -------- | -------- | -------- | 2074 | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 2075 | callback | Callback<number> | Yes| Callback used to return the WLAN state.| 2076 2077**Error codes** 2078 2079For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2080 2081| **ID**| **Error Message**| 2082| -------- | ---------------------------- | 2083| 201 | Permission denied. | 2084| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2085| 801 | Capability not supported. | 2086| 2501000 | Operation failed.| 2087 2088**WLAN states** 2089 2090| **Value**| **Description**| 2091| -------- | -------- | 2092| 0 | Deactivated| 2093| 1 | Activated| 2094| 2 | Activating| 2095| 3 | Deactivating| 2096 2097 2098## wifiManager.off('wifiStateChange')<sup>9+</sup> 2099 2100off(type: "wifiStateChange", callback?: Callback<number>): void 2101 2102Unsubscribes from WLAN state changes. 2103 2104**Required permissions**: ohos.permission.GET_WIFI_INFO 2105 2106**Atomic service API**: This API can be used in atomic services since API version 12. 2107 2108**System capability**: SystemCapability.Communication.WiFi.STA 2109 2110**Parameters** 2111 2112 | **Name**| **Type**| **Mandatory**| **Description**| 2113 | -------- | -------- | -------- | -------- | 2114 | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 2115 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2116 2117**Error codes** 2118 2119For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2120 2121| **ID**| **Error Message**| 2122| -------- | ---------------------------- | 2123| 201 | Permission denied. | 2124| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2125| 801 | Capability not supported. | 2126| 2501000 | Operation failed.| 2127 2128**Example** 2129```ts 2130 import { wifiManager } from '@kit.ConnectivityKit'; 2131 2132 let recvPowerNotifyFunc = (result:number) => { 2133 console.info("Receive power state change event: " + result); 2134 } 2135 2136 // Register an event. 2137 wifiManager.on("wifiStateChange", recvPowerNotifyFunc); 2138 2139 // Unregister an event. 2140 wifiManager.off("wifiStateChange", recvPowerNotifyFunc); 2141``` 2142 2143 2144## wifiManager.on('wifiConnectionChange')<sup>9+</sup> 2145 2146on(type: "wifiConnectionChange", callback: Callback<number>): void 2147 2148Subscribes to WLAN connection state changes. 2149 2150**Required permissions**: ohos.permission.GET_WIFI_INFO 2151 2152**Atomic service API**: This API can be used in atomic services since API version 12. 2153 2154**System capability**: SystemCapability.Communication.WiFi.STA 2155 2156**Parameters** 2157 2158 | **Name**| **Type**| **Mandatory**| **Description**| 2159 | -------- | -------- | -------- | -------- | 2160 | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 2161 | callback | Callback<number> | Yes| Callback used to return the WLAN connection state.| 2162 2163**WLAN connection states** 2164 2165| **Value**| **Description**| 2166| -------- | -------- | 2167| 0 | Disconnected.| 2168| 1 | Connected.| 2169 2170**Error codes** 2171 2172For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2173 2174| **ID**| **Error Message**| 2175| -------- | ---------------------------- | 2176| 201 | Permission denied. | 2177| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2178| 801 | Capability not supported. | 2179| 2501000 | Operation failed.| 2180 2181## wifiManager.off('wifiConnectionChange')<sup>9+</sup> 2182 2183off(type: "wifiConnectionChange", callback?: Callback<number>): void 2184 2185Unsubscribes from WLAN connection state changes. 2186 2187**Required permissions**: ohos.permission.GET_WIFI_INFO 2188 2189**Atomic service API**: This API can be used in atomic services since API version 12. 2190 2191**System capability**: SystemCapability.Communication.WiFi.STA 2192 2193**Parameters** 2194 2195 | **Name**| **Type**| **Mandatory**| **Description**| 2196 | -------- | -------- | -------- | -------- | 2197 | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 2198| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2199 2200**Error codes** 2201 2202For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2203 2204| **ID**| **Error Message**| 2205| -------- | ---------------------------- | 2206| 201 | Permission denied. | 2207| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2208| 801 | Capability not supported. | 2209| 2501000 | Operation failed.| 2210 2211**Example** 2212```ts 2213 import { wifiManager } from '@kit.ConnectivityKit'; 2214 2215 let recvWifiConnectionChangeFunc = (result:number) => { 2216 console.info("Receive wifi connection change event: " + result); 2217 } 2218 2219 // Register an event. 2220 wifiManager.on("wifiConnectionChange", recvWifiConnectionChangeFunc); 2221 2222 // Unregister an event. 2223 wifiManager.off("wifiConnectionChange", recvWifiConnectionChangeFunc); 2224``` 2225 2226## wifiManager.on('wifiScanStateChange')<sup>9+</sup> 2227 2228on(type: "wifiScanStateChange", callback: Callback<number>): void 2229 2230Subscribes to WLAN scan state changes. 2231 2232**Required permissions**: ohos.permission.GET_WIFI_INFO 2233 2234**Atomic service API**: This API can be used in atomic services since API version 12. 2235 2236**System capability**: SystemCapability.Communication.WiFi.STA 2237 2238**Parameters** 2239 2240 | **Name**| **Type**| **Mandatory**| **Description**| 2241 | -------- | -------- | -------- | -------- | 2242 | type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 2243 | callback | Callback<number> | Yes| Callback used to return the WLAN scan state.| 2244 2245**WLAN scan states** 2246 2247| **Value**| **Description**| 2248| -------- | -------- | 2249| 0 | Scan failed.| 2250| 1 | Scan successful.| 2251 2252**Error codes** 2253 2254For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2255 2256| **ID**| **Error Message**| 2257| -------- | ---------------------------- | 2258| 201 | Permission denied. | 2259| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2260| 801 | Capability not supported. | 2261| 2501000 | Operation failed.| 2262 2263## wifiManager.off('wifiScanStateChange')<sup>9+</sup> 2264 2265off(type: "wifiScanStateChange", callback?: Callback<number>): void 2266 2267Unsubscribes from WLAN scan state changes. 2268 2269**Required permissions**: ohos.permission.GET_WIFI_INFO 2270 2271**Atomic service API**: This API can be used in atomic services since API version 12. 2272 2273**System capability**: SystemCapability.Communication.WiFi.STA 2274 2275**Parameters** 2276 2277| **Name**| **Type**| **Mandatory**| **Description**| 2278| -------- | -------- | -------- | -------- | 2279| type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 2280| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2281 2282**Error codes** 2283 2284For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2285 2286| **ID**| **Error Message**| 2287| -------- | ---------------------------- | 2288| 201 | Permission denied. | 2289| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2290| 801 | Capability not supported. | 2291| 2501000 | Operation failed.| 2292 2293**Example** 2294```ts 2295 import { wifiManager } from '@kit.ConnectivityKit'; 2296 2297 let recvWifiScanStateChangeFunc = (result:number) => { 2298 console.info("Receive Wifi scan state change event: " + result); 2299 } 2300 2301 // Register an event. 2302 wifiManager.on("wifiScanStateChange", recvWifiScanStateChangeFunc); 2303 2304 // Unregister an event. 2305 wifiManager.off("wifiScanStateChange", recvWifiScanStateChangeFunc); 2306``` 2307 2308## wifiManager.on('wifiRssiChange')<sup>9+</sup> 2309 2310on(type: "wifiRssiChange", callback: Callback<number>): void 2311 2312Subscribes to RSSI changes. 2313 2314**Required permissions**: ohos.permission.GET_WIFI_INFO 2315 2316**System capability**: SystemCapability.Communication.WiFi.STA 2317 2318**Parameters** 2319 2320 | **Name**| **Type**| **Mandatory**| **Description**| 2321 | -------- | -------- | -------- | -------- | 2322 | type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 2323 | callback | Callback<number> | Yes| Callback used to return the RSSI, in dBm.| 2324 2325**Error codes** 2326 2327For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2328 2329| **ID**| **Error Message**| 2330| -------- | ---------------------------- | 2331| 201 | Permission denied. | 2332| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2333| 801 | Capability not supported. | 2334| 2501000 | Operation failed.| 2335 2336## wifiManager.off('wifiRssiChange')<sup>9+</sup> 2337 2338off(type: "wifiRssiChange", callback?: Callback<number>): void 2339 2340Unsubscribes from RSSI changes. 2341 2342**Required permissions**: ohos.permission.GET_WIFI_INFO 2343 2344**System capability**: SystemCapability.Communication.WiFi.STA 2345 2346**Parameters** 2347 2348| **Name**| **Type**| **Mandatory**| **Description**| 2349| -------- | -------- | -------- | -------- | 2350| type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 2351| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2352 2353**Error codes** 2354 2355For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2356 2357| **ID**| **Error Message**| 2358| -------- | ---------------------------- | 2359| 201 | Permission denied. | 2360| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2361| 801 | Capability not supported. | 2362| 2501000 | Operation failed.| 2363 2364**Example** 2365```ts 2366 import { wifiManager } from '@kit.ConnectivityKit'; 2367 2368 let recvWifiRssiChangeFunc = (result:number) => { 2369 console.info("Receive wifi rssi change event: " + result); 2370 } 2371 2372 // Register an event. 2373 wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc); 2374 2375 // Unregister an event. 2376 wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc); 2377``` 2378 2379## wifiManager.on('hotspotStateChange')<sup>9+</sup> 2380 2381on(type: "hotspotStateChange", callback: Callback<number>): void 2382 2383Subscribes to hotspot state changes. 2384 2385**Required permissions**: ohos.permission.GET_WIFI_INFO 2386 2387**System capability**: SystemCapability.Communication.WiFi.AP.Core 2388 2389**Parameters** 2390 2391| **Name**| **Type**| **Mandatory**| **Description**| 2392| -------- | -------- | -------- | -------- | 2393| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 2394| callback | Callback<number> | Yes| Callback used to return the hotspot state.| 2395 2396**Hotspot states** 2397 2398| **Value**| **Description**| 2399| -------- | -------- | 2400| 0 | Deactivated| 2401| 1 | Activated| 2402| 2 | Activating| 2403| 3 | Deactivating| 2404 2405**Error codes** 2406 2407For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2408 2409| **ID**| **Error Message**| 2410| -------- | ---------------------------- | 2411| 201 | Permission denied. | 2412| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2413| 801 | Capability not supported. | 2414| 2601000 | Operation failed. | 2415 2416## wifiManager.off('hotspotStateChange')<sup>9+</sup> 2417 2418off(type: "hotspotStateChange", callback?: Callback<number>): void 2419 2420Unsubscribes from hotspot state changes. 2421 2422**Required permissions**: ohos.permission.GET_WIFI_INFO 2423 2424**System capability**: SystemCapability.Communication.WiFi.AP.Core 2425 2426**Parameters** 2427 2428| **Name**| **Type**| **Mandatory**| **Description**| 2429| -------- | -------- | -------- | -------- | 2430| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 2431| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2432 2433**Error codes** 2434 2435For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2436 2437| **ID**| **Error Message**| 2438| -------- | ---------------------------- | 2439| 201 | Permission denied. | 2440| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2441| 801 | Capability not supported. | 2442| 2601000 | Operation failed. | 2443 2444**Example** 2445```ts 2446 import { wifiManager } from '@kit.ConnectivityKit'; 2447 2448 let recvHotspotStateChangeFunc = (result:number) => { 2449 console.info("Receive hotspot state change event: " + result); 2450 } 2451 2452 // Register an event. 2453 wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc); 2454 2455 // Unregister an event. 2456 wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc); 2457``` 2458 2459 2460## wifiManager.on('p2pStateChange')<sup>9+</sup> 2461 2462on(type: "p2pStateChange", callback: Callback<number>): void 2463 2464Subscribes to P2P state changes. 2465 2466**Required permissions**: ohos.permission.GET_WIFI_INFO 2467 2468**System capability**: SystemCapability.Communication.WiFi.P2P 2469 2470**Parameters** 2471 2472| **Name**| **Type**| **Mandatory**| **Description**| 2473| -------- | -------- | -------- | -------- | 2474| type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 2475| callback | Callback<number> | Yes| Callback used to return the P2P state change.| 2476 2477**P2P states** 2478 2479| **Value**| **Description**| 2480| -------- | -------- | 2481| 1 | Available| 2482| 2 | Opening| 2483| 3 | Opened| 2484| 4 | Closing| 2485| 5 | Closed| 2486 2487**Error codes** 2488 2489For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2490 2491| **ID**| **Error Message**| 2492| -------- | ---------------------------- | 2493| 201 | Permission denied. | 2494| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2495| 801 | Capability not supported. | 2496| 2801000 | Operation failed. | 2497 2498## wifiManager.off('p2pStateChange')<sup>9+</sup> 2499 2500off(type: "p2pStateChange", callback?: Callback<number>): void 2501 2502Unsubscribes from P2P state changes. 2503 2504**Required permissions**: ohos.permission.GET_WIFI_INFO 2505 2506**System capability**: SystemCapability.Communication.WiFi.P2P 2507 2508**Parameters** 2509 2510 | **Name**| **Type**| **Mandatory**| **Description**| 2511 | -------- | -------- | -------- | -------- | 2512 | type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 2513 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2514 2515**Error codes** 2516 2517For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2518 2519| **ID**| **Error Message**| 2520| -------- | ---------------------------- | 2521| 201 | Permission denied. | 2522| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2523| 801 | Capability not supported. | 2524| 2801000 | Operation failed. | 2525 2526**Example** 2527```ts 2528 import { wifiManager } from '@kit.ConnectivityKit'; 2529 2530 let recvP2pStateChangeFunc = (result:number) => { 2531 console.info("Receive p2p state change event: " + result); 2532 } 2533 2534 // Register an event. 2535 wifiManager.on("p2pStateChange", recvP2pStateChangeFunc); 2536 2537 // Unregister an event. 2538 wifiManager.off("p2pStateChange", recvP2pStateChangeFunc); 2539``` 2540 2541## wifiManager.on('p2pConnectionChange')<sup>9+</sup> 2542 2543on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void 2544 2545Subscribes to P2P connection state changes. 2546 2547**Required permissions**: ohos.permission.GET_WIFI_INFO 2548 2549**System capability**: SystemCapability.Communication.WiFi.P2P 2550 2551**Parameters** 2552 2553 | **Name**| **Type**| **Mandatory**| **Description**| 2554 | -------- | -------- | -------- | -------- | 2555 | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 2556| callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback used to return the P2P connection state change.| 2557 2558**Error codes** 2559 2560For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2561 2562| **ID**| **Error Message**| 2563| -------- | ---------------------------- | 2564| 201 | Permission denied. | 2565| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2566| 801 | Capability not supported. | 2567| 2801000 | Operation failed. | 2568 2569## wifiManager.off('p2pConnectionChange')<sup>9+</sup> 2570 2571off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): void 2572 2573Unsubscribes from P2P connection state changes. 2574 2575**Required permissions**: ohos.permission.GET_WIFI_INFO 2576 2577**System capability**: SystemCapability.Communication.WiFi.P2P 2578 2579**Parameters** 2580 2581 | **Name**| **Type**| **Mandatory**| **Description**| 2582 | -------- | -------- | -------- | -------- | 2583 | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 2584 | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2585 2586**Error codes** 2587 2588For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2589 2590| **ID**| **Error Message**| 2591| -------- | ---------------------------- | 2592| 201 | Permission denied. | 2593| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2594| 801 | Capability not supported. | 2595| 2801000 | Operation failed. | 2596 2597**Example** 2598```ts 2599 import { wifiManager } from '@kit.ConnectivityKit'; 2600 2601 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 2602 console.info("Receive p2p connection change event: " + result); 2603 } 2604 2605 // Register an event. 2606 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 2607 2608 // Unregister an event. 2609 wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc); 2610``` 2611 2612## wifiManager.on('p2pDeviceChange')<sup>9+</sup> 2613 2614on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void 2615 2616Subscribes to P2P device state changes. 2617 2618**Required permissions**: 2619 2620API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2621 2622API version 10 and later: ohos.permission.GET_WIFI_INFO 2623 2624**System capability**: SystemCapability.Communication.WiFi.P2P 2625 2626**Parameters** 2627 2628 | **Name**| **Type**| **Mandatory**| **Description**| 2629 | -------- | -------- | -------- | -------- | 2630 | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 2631| callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback used to return the device state change.| 2632 2633**Error codes** 2634 2635For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2636 2637| **ID**| **Error Message**| 2638| -------- | ---------------------------- | 2639| 201 | Permission denied. | 2640| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2641| 801 | Capability not supported. | 2642| 2801000 | Operation failed. | 2643 2644## wifiManager.off('p2pDeviceChange')<sup>9+</sup> 2645 2646off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void 2647 2648Unsubscribes from P2P device state changes. 2649 2650**Required permissions**: 2651 2652API version 9: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2653 2654API version 10 and later: No permission is required. 2655 2656**System capability**: SystemCapability.Communication.WiFi.P2P 2657 2658**Parameters** 2659 2660 | **Name**| **Type**| **Mandatory**| **Description**| 2661 | -------- | -------- | -------- | -------- | 2662 | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 2663 | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2664 2665**Error codes** 2666 2667For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2668 2669| **ID**| **Error Message**| 2670| -------- | ---------------------------- | 2671| 201<sup>10+</sup> | Permission denied. | 2672| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2673| 801 | Capability not supported. | 2674| 2801000 | Operation failed. | 2675 2676**Example** 2677```ts 2678 import { wifiManager } from '@kit.ConnectivityKit'; 2679 2680 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 2681 console.info("Receive p2p device change event: " + result); 2682 } 2683 2684 // Register an event. 2685 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 2686 2687 // Unregister an event. 2688 wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc); 2689``` 2690 2691## wifiManager.on('p2pPeerDeviceChange')<sup>9+</sup> 2692 2693on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void 2694 2695Subscribes to P2P peer device state changes. 2696 2697**Required permissions**: 2698 2699API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2700 2701API version 10 and later: ohos.permission.GET_WIFI_INFO 2702 2703**System capability**: SystemCapability.Communication.WiFi.P2P 2704 2705**Parameters** 2706 2707| **Name**| **Type**| **Mandatory**| **Description**| 2708| -------- | -------- | -------- | -------- | 2709| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 2710| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback used to return the P2P peer device state change. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 2711 2712**Error codes** 2713 2714For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2715 2716| **ID**| **Error Message**| 2717| -------- | ---------------------------- | 2718| 201 | Permission denied. | 2719| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2720| 801 | Capability not supported. | 2721| 2801000 | Operation failed. | 2722 2723## wifiManager.off('p2pPeerDeviceChange')<sup>9+</sup> 2724 2725off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): void 2726 2727Unsubscribes from P2P peer device state changes. 2728 2729**Required permissions**: 2730 2731API version 9: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 2732 2733API version 10 and later: No permission is required. 2734 2735**System capability**: SystemCapability.Communication.WiFi.P2P 2736 2737**Parameters** 2738 2739| **Name**| **Type**| **Mandatory**| **Description**| 2740| -------- | -------- | -------- | -------- | 2741| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 2742| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.| 2743 2744**Error codes** 2745 2746For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2747 2748| **ID**| **Error Message**| 2749| -------- | ---------------------------- | 2750| 201<sup>10+</sup> | Permission denied. | 2751| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2752| 801 | Capability not supported. | 2753| 2801000 | Operation failed. | 2754 2755**Example** 2756```ts 2757 import { wifiManager } from '@kit.ConnectivityKit'; 2758 2759 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 2760 console.info("Receive p2p peer device change event: " + result); 2761 } 2762 2763 // Register an event. 2764 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 2765 2766 // Unregister an event. 2767 wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 2768``` 2769 2770## wifiManager.on('p2pPersistentGroupChange')<sup>9+</sup> 2771 2772on(type: "p2pPersistentGroupChange", callback: Callback<void>): void 2773 2774Subscribes to P2P persistent group state changes. 2775 2776**Required permissions**: ohos.permission.GET_WIFI_INFO 2777 2778**System capability**: SystemCapability.Communication.WiFi.P2P 2779 2780**Parameters** 2781 2782 | **Name**| **Type**| **Mandatory**| **Description**| 2783 | -------- | -------- | -------- | -------- | 2784 | type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 2785| callback | Callback<void> | Yes| Callback used to return the P2P persistent group state change.| 2786 2787**Error codes** 2788 2789For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2790 2791| **ID**| **Error Message**| 2792| -------- | ---------------------------- | 2793| 201 | Permission denied. | 2794| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2795| 801 | Capability not supported. | 2796| 2801000 | Operation failed. | 2797 2798## wifiManager.off('p2pPersistentGroupChange')<sup>9+</sup> 2799 2800off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void 2801 2802Unsubscribes from P2P persistent group state changes. 2803 2804**Required permissions**: ohos.permission.GET_WIFI_INFO 2805 2806**System capability**: SystemCapability.Communication.WiFi.P2P 2807 2808**Parameters** 2809 2810| **Name**| **Type**| **Mandatory**| **Description**| 2811| -------- | -------- | -------- | -------- | 2812| type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 2813| callback | Callback<void> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2814 2815**Error codes** 2816 2817For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2818 2819| **ID**| **Error Message**| 2820| -------- | ---------------------------- | 2821| 201 | Permission denied. | 2822| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2823| 801 | Capability not supported. | 2824| 2801000 | Operation failed. | 2825 2826**Example** 2827```ts 2828 import { wifiManager } from '@kit.ConnectivityKit'; 2829 2830 let recvP2pPersistentGroupChangeFunc = (result:void) => { 2831 console.info("Receive p2p persistent group change event: " + result); 2832 } 2833 2834 // Register an event. 2835 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 2836 2837 // Unregister an event. 2838 wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 2839``` 2840 2841## wifiManager.on('p2pDiscoveryChange')<sup>9+</sup> 2842 2843on(type: "p2pDiscoveryChange", callback: Callback<number>): void 2844 2845Subscribes to P2P device discovery state changes. 2846 2847**Required permissions**: ohos.permission.GET_WIFI_INFO 2848 2849**System capability**: SystemCapability.Communication.WiFi.P2P 2850 2851**Parameters** 2852 2853 | **Name**| **Type**| **Mandatory**| **Description**| 2854 | -------- | -------- | -------- | -------- | 2855 | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 2856 | callback | Callback<number> | Yes| Callback used to return the P2P device discovery state change.| 2857 2858**P2P discovered device states** 2859 2860| **Value**| **Description**| 2861| -------- | -------- | 2862| 0 | Initial state.| 2863| 1 | Discovered.| 2864 2865**Error codes** 2866 2867For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2868 2869| **ID**| **Error Message**| 2870| -------- | ---------------------------- | 2871| 201 | Permission denied. | 2872| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2873| 801 | Capability not supported. | 2874| 2801000 | Operation failed. | 2875 2876## wifiManager.off('p2pDiscoveryChange')<sup>9+</sup> 2877 2878off(type: "p2pDiscoveryChange", callback?: Callback<number>): void 2879 2880Unsubscribes from P2P device discovery state changes. 2881 2882**Required permissions**: ohos.permission.GET_WIFI_INFO 2883 2884**System capability**: SystemCapability.Communication.WiFi.P2P 2885 2886**Parameters** 2887 2888 | **Name**| **Type**| **Mandatory**| **Description**| 2889 | -------- | -------- | -------- | -------- | 2890 | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 2891 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. | 2892 2893**Error codes** 2894 2895For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2896 2897| **ID**| **Error Message**| 2898| -------- | ---------------------------- | 2899| 201 | Permission denied. | 2900| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2901| 801 | Capability not supported. | 2902| 2801000 | Operation failed. | 2903 2904**Example** 2905```ts 2906 import { wifiManager } from '@kit.ConnectivityKit'; 2907 2908 let recvP2pDiscoveryChangeFunc = (result:number) => { 2909 console.info("Receive p2p discovery change event: " + result); 2910 } 2911 2912 // Register an event. 2913 wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 2914 2915 // Unregister an event. 2916 wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 2917``` 2918