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