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 | Operation failed because the service is being closed.| 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 the value **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, and the value **false** indicates 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 type 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 the value **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## wifiManager.getLinkedInfoSync<sup>18+</sup> 1227 1228getLinkedInfoSync(): WifiLinkedInfo; 1229 1230Obtains the WLAN connection information. This API returns the result synchronously. 1231 1232**Required permissions**: ohos.permission.GET_WIFI_INFO 1233 1234If **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**. 1235 1236**Atomic service API**: This API can be used in atomic services since API version 16. 1237 1238**System capability**: SystemCapability.Communication.WiFi.STA 1239 1240**Return value** 1241 1242 | Type| Description| 1243 | -------- | -------- | 1244 | [WifiLinkedInfo](#wifilinkedinfo9) | return the WLAN connection information.| 1245 1246**Error codes** 1247 1248For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1249 1250| **ID**| **Error Message**| 1251| -------- | -------- | 1252| 201 | Permission denied. | 1253| 801 | Capability not supported. | 1254| 2501000 | Operation failed.| 1255| 2501001 | Wi-Fi STA disabled.| 1256 1257**Example** 1258```ts 1259 import { wifiManager } from '@kit.ConnectivityKit'; 1260 try { 1261 let linkInfo = wifiManager.getLinkedInfoSync(); 1262 console.info("get linked info:" + JSON.stringify(linkInfo)); 1263 } catch(error) { 1264 console.error("get linked info failed:" + JSON.stringify(error)); 1265 } 1266``` 1267 1268## WifiLinkedInfo<sup>9+</sup> 1269 1270Represents the WLAN connection information. 1271 1272**System capability**: SystemCapability.Communication.WiFi.STA 1273 1274| Name| Type| Readable| Writable| Description| 1275| -------- | -------- | -------- | -------- | -------- | 1276| 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.| 1277| bssid | string | Yes| No| BSSID of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1278| 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.| 1279| band | number | Yes| No| Frequency band of the WLAN AP. The value **1** indicates 2.4 GHz, and the value **2** indicates 5 GHz.| 1280| linkSpeed | number | Yes| No| Uplink speed of the WLAN AP, in Mbps/s.| 1281| rxLinkSpeed<sup>10+</sup> | number | Yes| No| Downlink speed of the WLAN AP, in Mbps/s.| 1282| maxSupportedTxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported, in Mbps/s.| 1283| maxSupportedRxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum downlink speed supported, in Mbps/s.| 1284| 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.| 1285| 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.| 1286| 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.| 1287| macType | number | Yes| No| MAC address type. <br>The value **0** indicates a random MAC address, and the value **1** indicates device MAC address.| 1288| macAddress | string | Yes| No| MAC address of the device.| 1289| 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.)| 1290| connState | [ConnState](#connstate9) | Yes| No| WLAN connection state.| 1291| channelWidth<sup>10+</sup> | [WifiChannelWidth](#wifichannelwidth9) | Yes| No| Channel bandwidth of the connected hotspot.| 1292| wifiStandard<sup>10+</sup> | [WifiStandard](#wifistandard10) | Yes| No| Wi-Fi standard used by the connected hotspot.| 1293| supportedWifiCategory<sup>12+</sup> | [WifiCategory](#wificategory12) | Yes| No| Highest Wi-Fi category supported by the hotspot.| 1294| isHiLinkNetwork<sup>12+</sup> | boolean | Yes| No| Whether the hotspot supports HiLink. The value **true** indicates that the hotspot supports HiLink, and the value **false** indicates the opposite.| 1295 1296## ConnState<sup>9+</sup> 1297 1298Enumerates the WLAN connection states. 1299 1300**System capability**: SystemCapability.Communication.WiFi.STA 1301 1302| Name| Value| Description| 1303| -------- | -------- | -------- | 1304| SCANNING | 0 | The device is scanning for available APs.| 1305| CONNECTING | 1 | A WLAN connection is being established.| 1306| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.| 1307| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.| 1308| CONNECTED | 4 | A WLAN connection is established.| 1309| DISCONNECTING | 5 | The WLAN connection is being disconnected.| 1310| DISCONNECTED | 6 | The WLAN connection is disconnected.| 1311| UNKNOWN | 7 | Failed to set up the WLAN connection.| 1312 1313 1314## wifiManager.isConnected<sup>9+</sup> 1315 1316isConnected(): boolean 1317 1318Checks whether WLAN is connected. 1319 1320**Required permissions**: ohos.permission.GET_WIFI_INFO 1321 1322**Atomic service API**: This API can be used in atomic services since API version 12. 1323 1324**System capability**: SystemCapability.Communication.WiFi.STA 1325 1326**Return value** 1327 1328 | **Type**| **Description**| 1329 | -------- | -------- | 1330 | boolean | Returns **true** if WLAN is connected; returns **false** otherwise.| 1331 1332**Error codes** 1333 1334For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1335 1336| **ID**| **Error Message**| 1337| -------- | -------- | 1338| 201 | Permission denied. | 1339| 801 | Capability not supported. | 1340| 2501000 | Operation failed.| 1341 1342**Example** 1343```ts 1344 import { wifiManager } from '@kit.ConnectivityKit'; 1345 1346 try { 1347 let ret = wifiManager.isConnected(); 1348 console.info("isConnected:" + ret); 1349 }catch(error){ 1350 console.error("failed:" + JSON.stringify(error)); 1351 } 1352 1353``` 1354 1355 1356## wifiManager.disconnect<sup>15+</sup> 1357 1358disconnect(): void 1359 1360Disconnects from a WLAN. 1361 1362**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) or 1363 ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION (available only to enterprise applications) 1364 1365**System capability**: SystemCapability.Communication.WiFi.STA 1366 1367**Error codes** 1368 1369For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1370 1371| **ID**| **Error Message**| 1372| -------- | -------- | 1373| 201 | Permission denied. | 1374| 801 | Capability not supported. | 1375| 2501000 | Operation failed.| 1376| 2501001 | Wi-Fi STA disabled.| 1377 1378**Example** 1379```ts 1380 import { wifiManager } from '@kit.ConnectivityKit'; 1381 1382 try { 1383 wifiManager.disconnect(); 1384 }catch(error){ 1385 console.error("failed:" + JSON.stringify(error)); 1386 } 1387 1388``` 1389 1390 1391## wifiManager.isFeatureSupported<sup>9+</sup> 1392 1393isFeatureSupported(featureId: number): boolean 1394 1395Checks whether the device supports the specified WLAN feature. 1396 1397**Required permissions**: ohos.permission.GET_WIFI_INFO 1398 1399**System capability**: SystemCapability.Communication.WiFi.Core 1400 1401**Parameters** 1402 1403 | **Name**| **Type**| Mandatory| **Description**| 1404 | -------- | -------- | -------- | -------- | 1405 | featureId | number | Yes| Feature ID.| 1406 1407**Feature IDs** 1408 1409| Value| Description| 1410| -------- | -------- | 1411| 0x0001 | WLAN infrastructure mode| 1412| 0x0002 | 5 GHz feature| 1413| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature| 1414| 0x0008 | Wi-Fi Direct| 1415| 0x0010 | SoftAP| 1416| 0x0040 | Wi-Fi Aware| 1417| 0x8000 | WLAN AP/STA concurrency| 1418| 0x8000000 | WPA3 Personal (WPA-3 SAE)| 1419| 0x10000000 | WPA3-Enterprise Suite B| 1420| 0x20000000 | Enhanced open feature| 1421 1422**Return value** 1423 1424 | **Type**| **Description**| 1425 | -------- | -------- | 1426 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1427 1428**Error codes** 1429 1430For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1431 1432| **ID**| **Error Message**| 1433 | -------- | -------- | 1434| 201 | Permission denied. | 1435| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. | 1436| 801 | Capability not supported. | 1437| 2401000 | Operation failed.| 1438 1439**Example** 1440```ts 1441 import { wifiManager } from '@kit.ConnectivityKit'; 1442 1443 try { 1444 let featureId = 0; 1445 let ret = wifiManager.isFeatureSupported(featureId); 1446 console.info("isFeatureSupported:" + ret); 1447 }catch(error){ 1448 console.error("failed:" + JSON.stringify(error)); 1449 } 1450 1451``` 1452 1453 1454## wifiManager.getIpInfo<sup>9+</sup> 1455 1456getIpInfo(): IpInfo 1457 1458Obtains IPv4 information. 1459 1460**Required permissions**: ohos.permission.GET_WIFI_INFO 1461 1462**System capability**: SystemCapability.Communication.WiFi.STA 1463 1464**Return value** 1465 1466 | **Type**| **Description**| 1467 | -------- | -------- | 1468 | [IpInfo](#ipinfo9) | IP information obtained.| 1469 1470**Error codes** 1471 1472For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1473 1474| **ID**| **Error Message**| 1475| -------- | -------- | 1476| 201 | Permission denied. | 1477| 801 | Capability not supported. | 1478| 2501000 | Operation failed.| 1479 1480**Example** 1481```ts 1482 import { wifiManager } from '@kit.ConnectivityKit'; 1483 1484 try { 1485 let info = wifiManager.getIpInfo(); 1486 console.info("info:" + JSON.stringify(info)); 1487 }catch(error){ 1488 console.error("failed:" + JSON.stringify(error)); 1489 } 1490``` 1491 1492## IpInfo<sup>9+</sup> 1493 1494Represents IPv4 information. 1495 1496**System capability**: SystemCapability.Communication.WiFi.STA 1497 1498| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1499| -------- | -------- | -------- | -------- | -------- | 1500| ipAddress | number | Yes| No| IP address.| 1501| gateway | number | Yes| No| Gateway.| 1502| netmask | number | Yes| No| Subnet mask.| 1503| primaryDns | number | Yes| No| IP address of the preferred DNS server.| 1504| secondDns | number | Yes| No| IP address of the alternate DNS server.| 1505| serverIp | number | Yes| No| IP address of the DHCP server.| 1506| leaseDuration | number | Yes| No| Lease duration of the IP address, in seconds.| 1507 1508 1509## wifiManager.getIpv6Info<sup>10+</sup> 1510 1511getIpv6Info(): Ipv6Info 1512 1513Obtains IPv6 information. 1514 1515**Required permissions**: ohos.permission.GET_WIFI_INFO 1516 1517**System capability**: SystemCapability.Communication.WiFi.STA 1518 1519**Return value** 1520 1521| **Type**| **Description**| 1522| -------- | -------- | 1523| [Ipv6Info](#ipv6info10) | IPv6 information obtained.| 1524 1525**Error codes** 1526 1527For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1528 1529| **ID**| **Error Message**| 1530| -------- | -------- | 1531| 201 | Permission denied. | 1532| 801 | Capability not supported. | 1533| 2501000 | Operation failed.| 1534 1535**Example** 1536```ts 1537 import { wifiManager } from '@kit.ConnectivityKit'; 1538 1539 try { 1540 let info = wifiManager.getIpv6Info(); 1541 console.info("info:" + JSON.stringify(info)); 1542 }catch(error){ 1543 console.error("failed:" + JSON.stringify(error)); 1544 } 1545``` 1546## Ipv6Info<sup>10+</sup> 1547 1548Represents the IPv6 information. 1549 1550**System capability**: SystemCapability.Communication.WiFi.STA 1551 1552| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1553| -------- | -------- | -------- | -------- | -------- | 1554| linkIpv6Address | string | Yes| No| IPv6 address of the link.| 1555| globalIpv6Address | string | Yes| No| Global IPv6 address.| 1556| randomGlobalIpv6Address | string | Yes| No| Random global IPv6 address. This parameter is reserved.| 1557| uniqueIpv6Address<sup>12+</sup> | string | Yes| No| Unique local address (ULA) in IPv6 format.| 1558| randomUniqueIpv6Address<sup>12+</sup> | string | Yes| No| Random unique local address (RULA) in IPv6 format.| 1559| gateway | string | Yes| No| Gateway.| 1560| netmask | string | Yes| No| Subnet mask.| 1561| primaryDNS | string | Yes| No| IPv6 address of the preferred DNS server.| 1562| secondDNS | string | Yes| No| IPv6 address of the alternate DNS server.| 1563 1564## wifiManager.getCountryCode<sup>9+</sup> 1565 1566getCountryCode(): string 1567 1568Obtains the country code. 1569 1570**Required permissions**: ohos.permission.GET_WIFI_INFO 1571 1572**System capability**: SystemCapability.Communication.WiFi.Core 1573 1574**Return value** 1575 1576 | **Type**| **Description**| 1577 | -------- | -------- | 1578 | string | Country code obtained.| 1579 1580**Error codes** 1581 1582For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1583 1584| **ID**| **Error Message**| 1585| -------- | -------- | 1586| 201 | Permission denied. | 1587| 801 | Capability not supported. | 1588| 2401000 | Operation failed.| 1589 1590**Example** 1591```ts 1592 import { wifiManager } from '@kit.ConnectivityKit'; 1593 1594 try { 1595 let code = wifiManager.getCountryCode(); 1596 console.info("code:" + code); 1597 }catch(error){ 1598 console.error("failed:" + JSON.stringify(error)); 1599 } 1600``` 1601 1602 1603 1604 1605## wifiManager.isBandTypeSupported<sup>10+</sup> 1606 1607isBandTypeSupported(bandType: WifiBandType): boolean 1608 1609Checks whether the current frequency band is supported. 1610 1611**Required permissions**: ohos.permission.GET_WIFI_INFO 1612 1613**System capability**: SystemCapability.Communication.WiFi.STA 1614 1615**Parameters** 1616 1617 | **Name**| **Type**| **Mandatory**| **Description**| 1618 | -------- | -------- | -------- | -------- | 1619 | bandType | [WifiBandType](#wifibandtype10) | Yes| Wi-Fi band type.| 1620 1621**Return value** 1622 1623 | **Type**| **Description**| 1624 | -------- | -------- | 1625 | boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1626 1627**Error codes** 1628 1629For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1630 1631| **ID**| **Error Message**| 1632| -------- | -------- | 1633| 201 | Permission denied. | 1634| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1635| 801 | Capability not supported. | 1636| 2501000 | Operation failed.| 1637 1638**Example** 1639```ts 1640 import { wifiManager } from '@kit.ConnectivityKit'; 1641 1642 try { 1643 let type = 0; 1644 let isBandTypeSupported = wifiManager.isBandTypeSupported(type); 1645 console.info("isBandTypeSupported:" + isBandTypeSupported); 1646 }catch(error){ 1647 console.error("failed:" + JSON.stringify(error)); 1648 } 1649``` 1650 1651 1652## wifiManager.isMeteredHotspot<sup>11+</sup> 1653 1654isMeteredHotspot(): boolean 1655 1656Checks whether the Wi-Fi network connected to the device is a smartphone hotspot. 1657 1658**Required permissions**: ohos.permission.GET_WIFI_INFO 1659 1660**System capability**: SystemCapability.Communication.WiFi.STA 1661 1662**Return value** 1663 1664 | **Type**| **Description**| 1665 | -------- | -------- | 1666 | boolean | Returns **true** if the Wi-Fi network connected is a smartphone hotspot; returns **false** otherwise.| 1667 1668**Error codes** 1669 1670For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1671 1672| **ID**| **Error Message**| 1673| -------- | -------- | 1674| 201 | Permission denied. | 1675| 801 | Capability not supported. | 1676| 2501000 | Operation failed.| 1677| 2501001 | Wi-Fi STA disabled. | 1678 1679**Example** 1680 1681```ts 1682 import { wifiManager } from '@kit.ConnectivityKit'; 1683 1684 try { 1685 let isMeteredHotspot = wifiManager.isMeteredHotspot(); 1686 console.info("isMeteredHotspot:" + isMeteredHotspot); 1687 }catch(error){ 1688 console.error("failed:" + JSON.stringify(error)); 1689 } 1690``` 1691 1692 1693## wifiManager.isHotspotActive<sup>15+</sup> 1694 1695isHotspotActive(): boolean 1696 1697Checks whether this hotspot is active. 1698 1699**Required permissions**: ohos.permission.GET_WIFI_INFO 1700 1701**System capability**: SystemCapability.Communication.WiFi.AP.Core 1702 1703**Return value** 1704 1705 | **Type**| **Description**| 1706 | -------- | -------- | 1707 | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| 1708 1709**Error codes** 1710 1711For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1712 1713| **ID**| **Error Message**| 1714| -------- | -------- | 1715| 201 | Permission denied. | 1716| 801 | Capability not supported. | 1717| 2601000 | Operation failed. | 1718 1719**Example** 1720```ts 1721 import { wifiManager } from '@kit.ConnectivityKit'; 1722 1723 try { 1724 let ret = wifiManager.isHotspotActive(); 1725 console.info("result:" + ret); 1726 } catch(error) { 1727 console.error("failed:" + JSON.stringify(error)); 1728 } 1729``` 1730 1731 1732## wifiManager.getP2pLinkedInfo<sup>9+</sup> 1733 1734getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo> 1735 1736Obtains P2P connection information. This API uses a promise to return the result. 1737 1738**Required permissions**: ohos.permission.GET_WIFI_INFO 1739 1740To 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**. 1741 1742**System capability**: SystemCapability.Communication.WiFi.P2P 1743 1744**Return value** 1745 1746 | Type| Description| 1747 | -------- | -------- | 1748 | Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Promise used to return the P2P connection information obtained.| 1749 1750**Error codes** 1751 1752For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1753 1754| **ID**| **Error Message**| 1755| -------- | -------- | 1756| 201 | Permission denied. | 1757| 801 | Capability not supported. | 1758| 2801000 | Operation failed. | 1759 1760 1761## wifiManager.getP2pLinkedInfo<sup>9+</sup> 1762 1763getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void 1764 1765Obtains P2P link information. This API uses an asynchronous callback to return the result. 1766 1767**Required permissions**: ohos.permission.GET_WIFI_INFO 1768 1769To 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**. 1770 1771**System capability**: SystemCapability.Communication.WiFi.P2P 1772 1773**Parameters** 1774 1775 | Name| Type| Mandatory| Description| 1776 | -------- | -------- | -------- | -------- | 1777 | 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**.| 1778 1779**Error codes** 1780 1781For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1782 1783| **ID**| **Error Message**| 1784| -------- | -------- | 1785| 201 | Permission denied. | 1786| 801 | Capability not supported. | 1787| 2801000 | Operation failed. | 1788| 2801001 | Wi-Fi STA disabled. | 1789 1790**Example** 1791```ts 1792 import { wifiManager } from '@kit.ConnectivityKit'; 1793 1794 wifiManager.getP2pLinkedInfo((err, data:wifiManager.WifiP2pLinkedInfo) => { 1795 if (err) { 1796 console.error("get p2p linked info error"); 1797 return; 1798 } 1799 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 1800 }); 1801 1802 wifiManager.getP2pLinkedInfo().then(data => { 1803 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 1804 }); 1805``` 1806 1807 1808## WifiP2pLinkedInfo<sup>9+</sup> 1809 1810Represents the P2P link information. 1811 1812**System capability**: SystemCapability.Communication.WiFi.P2P 1813 1814| Name| Type| Readable| Writable| Description| 1815| -------- | -------- | -------- | -------- | -------- | 1816| connectState | [P2pConnectState](#p2pconnectstate9) | Yes| No| P2P connection state.| 1817| 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.| 1818| groupOwnerAddr | string | Yes| No| IP address of the group.| 1819 1820 1821## P2pConnectState<sup>9+</sup> 1822 1823Enumerates the P2P connection states. 1824 1825**System capability**: SystemCapability.Communication.WiFi.P2P 1826 1827| Name| Value| Description| 1828| -------- | -------- | -------- | 1829| DISCONNECTED | 0 | Disconnected.| 1830| CONNECTED | 1 | Connected.| 1831 1832## wifiManager.getCurrentGroup<sup>9+</sup> 1833 1834getCurrentGroup(): Promise<WifiP2pGroupInfo> 1835 1836Obtains the current P2P group information. This API uses a promise to return the result. 1837 1838**Required permissions**: 1839 1840API version 10 and later: ohos.permission.GET_WIFI_INFO 1841 1842**System capability**: SystemCapability.Communication.WiFi.P2P 1843 1844**Return value** 1845 1846| Type| Description| 1847| -------- | -------- | 1848| 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.| 1849 1850**Error codes** 1851 1852For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1853 1854| **ID**| **Error Message**| 1855| -------- | -------- | 1856| 201 | Permission denied. | 1857| 801 | Capability not supported. | 1858| 2801000 | Operation failed. | 1859 1860## wifiManager.getCurrentGroup<sup>9+</sup> 1861 1862getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void 1863 1864Obtains the current P2P group information. This API uses an asynchronous callback to return the result. 1865 1866**Required permissions**: 1867 1868API version 10 and later: ohos.permission.GET_WIFI_INFO 1869 1870**System capability**: SystemCapability.Communication.WiFi.P2P 1871 1872**Parameters** 1873 1874| Name| Type| Mandatory| Description| 1875| -------- | -------- | -------- | -------- | 1876| 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.| 1877 1878**Error codes** 1879 1880For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1881 1882| **ID**| **Error Message**| 1883| -------- | -------- | 1884| 201 | Permission denied. | 1885| 801 | Capability not supported. | 1886| 2801000 | Operation failed. | 1887 1888**Example** 1889```ts 1890 import { wifiManager } from '@kit.ConnectivityKit'; 1891 // The current group information can be obtained only after the P2P group is created or the connection is successful. 1892 wifiManager.getCurrentGroup((err, data:wifiManager.WifiP2pGroupInfo) => { 1893 if (err) { 1894 console.error("get current P2P group error"); 1895 return; 1896 } 1897 console.info("get current P2P group: " + JSON.stringify(data)); 1898 }); 1899 1900 wifiManager.getCurrentGroup().then(data => { 1901 console.info("get current P2P group: " + JSON.stringify(data)); 1902 }); 1903``` 1904 1905## wifiManager.getP2pPeerDevices<sup>9+</sup> 1906 1907getP2pPeerDevices(): Promise<WifiP2pDevice[]> 1908 1909Obtains the peer device list in the P2P connection. This API uses a promise to return the result. 1910 1911**Required permissions**: 1912 1913API version 10 and later: ohos.permission.GET_WIFI_INFO 1914 1915**System capability**: SystemCapability.Communication.WiFi.P2P 1916 1917**Return value** 1918 1919| Type| Description| 1920| -------- | -------- | 1921| 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.| 1922 1923**Error codes** 1924 1925For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1926 1927| **ID**| **Error Message**| 1928| -------- | -------- | 1929| 201 | Permission denied. | 1930| 801 | Capability not supported. | 1931| 2801000 | Operation failed. | 1932 1933## wifiManager.getP2pPeerDevices<sup>9+</sup> 1934 1935getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void 1936 1937Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result. 1938 1939**Required permissions**: 1940 1941API version 10 and later: ohos.permission.GET_WIFI_INFO 1942 1943**System capability**: SystemCapability.Communication.WiFi.P2P 1944 1945**Parameters** 1946 1947| Name| Type| Mandatory| Description| 1948| -------- | -------- | -------- | -------- | 1949| 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.| 1950 1951**Error codes** 1952 1953For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1954 1955| **ID**| **Error Message**| 1956| -------- | -------- | 1957| 201 | Permission denied. | 1958| 801 | Capability not supported. | 1959| 2801000 | Operation failed. | 1960| 2801001 | Wi-Fi STA disabled. | 1961 1962**Example** 1963```ts 1964 import { wifiManager } from '@kit.ConnectivityKit'; 1965 // The peer device list can be obtained only after the P2P discovery is complete. 1966 wifiManager.getP2pPeerDevices((err, data:wifiManager.WifiP2pDevice[]) => { 1967 if (err) { 1968 console.error("get P2P peer devices error"); 1969 return; 1970 } 1971 console.info("get P2P peer devices: " + JSON.stringify(data)); 1972 }); 1973 1974 wifiManager.getP2pPeerDevices().then(data => { 1975 console.info("get P2P peer devices: " + JSON.stringify(data)); 1976 }); 1977``` 1978 1979## WifiP2pDevice<sup>9+</sup> 1980 1981Represents the P2P device information. 1982 1983**System capability**: SystemCapability.Communication.WiFi.P2P 1984 1985| Name| Type| Readable| Writable| Description| 1986| -------- | -------- | -------- | -------- | -------- | 1987| deviceName | string | Yes| No| Device name.| 1988| deviceAddress | string | Yes| No| MAC address of the device.| 1989| deviceAddressType<sup>10+</sup> | [DeviceAddressType](#deviceaddresstype10) | Yes| No| MAC address type of the device.| 1990| primaryDeviceType | string | Yes| No| Type of the primary device.| 1991| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus9) | Yes| No| Device status.| 1992| groupCapabilities | number | Yes| No| Group capabilities.| 1993 1994 1995## P2pDeviceStatus<sup>9+</sup> 1996 1997Enumerates the P2P device states. 1998 1999**System capability**: SystemCapability.Communication.WiFi.P2P 2000 2001| Name| Value| Description| 2002| -------- | -------- | -------- | 2003| CONNECTED | 0 | Connected.| 2004| INVITED | 1 | Invited.| 2005| FAILED | 2 | Failed.| 2006| AVAILABLE | 3 | Available.| 2007| UNAVAILABLE | 4 | Unavailable.| 2008 2009 2010## wifiManager.getP2pLocalDevice<sup>9+</sup> 2011 2012getP2pLocalDevice(): Promise<WifiP2pDevice> 2013 2014Obtains the local device information in the P2P connection. This API uses a promise to return the result. 2015 2016**Required permissions**: 2017 2018API version 11 and later: ohos.permission.GET_WIFI_INFO 2019 2020**System capability**: SystemCapability.Communication.WiFi.P2P 2021 2022**Return value** 2023 2024 | Type| Description| 2025 | -------- | -------- | 2026 | Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| 2027 2028**Error codes** 2029 2030For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2031 2032| **ID**| **Error Message**| 2033| -------- | -------- | 2034| 201 | Permission denied. | 2035| 801 | Capability not supported. | 2036| 2801000 | Operation failed. | 2037 2038## wifiManager.getP2pLocalDevice<sup>9+</sup> 2039 2040getP2pLocalDevice(callback: AsyncCallback<WifiP2pDevice>): void 2041 2042Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result. 2043 2044**Required permissions**: 2045 2046API version 11 and later: ohos.permission.GET_WIFI_INFO 2047 2048**System capability**: SystemCapability.Communication.WiFi.P2P 2049 2050**Parameters** 2051 2052 | Name| Type| Mandatory| Description| 2053 | -------- | -------- | -------- | -------- | 2054 | 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**.| 2055 2056**Error codes** 2057 2058| **ID**| **Error Message**| 2059| -------- | -------- | 2060| 201 | Permission denied. | 2061| 801 | Capability not supported. | 2062| 2801000 | Operation failed. | 2063| 2801001 | Wi-Fi STA disabled. | 2064 2065**Example** 2066```ts 2067 import { wifiManager } from '@kit.ConnectivityKit'; 2068 // The local device information can be obtained only after a P2P group is created or the connection is successful. 2069 wifiManager.getP2pLocalDevice((err, data:wifiManager.WifiP2pDevice) => { 2070 if (err) { 2071 console.error("get P2P local device error"); 2072 return; 2073 } 2074 console.info("get P2P local device: " + JSON.stringify(data)); 2075 }); 2076 2077 wifiManager.getP2pLocalDevice().then(data => { 2078 console.info("get P2P local device: " + JSON.stringify(data)); 2079 }); 2080``` 2081 2082## wifiManager.createGroup<sup>9+</sup> 2083 2084createGroup(config: WifiP2PConfig): void 2085 2086Creates a P2P group. 2087 2088**Required permissions**: ohos.permission.GET_WIFI_INFO 2089 2090**System capability**: SystemCapability.Communication.WiFi.P2P 2091 2092**Parameters** 2093 2094| **Name**| **Type**| Mandatory| **Description**| 2095| -------- | -------- | -------- | -------- | 2096| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration. The default **DeviceAddressType** is random device address.| 2097 2098**Error codes** 2099 2100For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2101 2102| **ID**| **Error Message**| 2103| -------- | -------- | 2104| 201 | Permission denied. | 2105| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 2106| 801 | Capability not supported. | 2107| 2801000 | Operation failed. | 2108| 2801001 | Wi-Fi STA disabled. | 2109 2110**Example** 2111```ts 2112 import { wifiManager } from '@kit.ConnectivityKit'; 2113 2114 try { 2115 let config:wifiManager.WifiP2PConfig = { 2116 deviceAddress: "****", 2117 netId: 0, 2118 passphrase: "*****", 2119 groupName: "****", 2120 goBand: 0 2121 } 2122 wifiManager.createGroup(config); 2123 2124 }catch(error){ 2125 console.error("failed:" + JSON.stringify(error)); 2126 } 2127``` 2128 2129## WifiP2PConfig<sup>9+</sup> 2130 2131Represents P2P group configuration. 2132 2133**System capability**: SystemCapability.Communication.WiFi.P2P 2134 2135| Name| Type| Readable| Writable| Description| 2136| -------- | -------- | -------- | -------- | -------- | 2137| deviceAddress | string | Yes| No| Device address.| 2138| deviceAddressType<sup>10+</sup>| [DeviceAddressType](#deviceaddresstype10) | Yes| No| Device address type.| 2139| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and the value **-2** indicates a persistent group.| 2140| passphrase | string | Yes| No| Passphrase of the group.| 2141| groupName | string | Yes| No| Name of the group.| 2142| goBand | [GroupOwnerBand](#groupownerband9) | Yes| No| Frequency band of the group.| 2143 2144 2145## GroupOwnerBand<sup>9+</sup> 2146 2147Enumerates the P2P group frequency bands. 2148 2149**System capability**: SystemCapability.Communication.WiFi.P2P 2150 2151| Name| Value| Description| 2152| -------- | -------- | -------- | 2153| GO_BAND_AUTO | 0 | Auto.| 2154| GO_BAND_2GHZ | 1 | 2.4 GHz.| 2155| GO_BAND_5GHZ | 2 | 5 GHz.| 2156 2157 2158## wifiManager.removeGroup<sup>9+</sup> 2159 2160removeGroup(): void 2161 2162Removes this P2P group. 2163 2164**Required permissions**: ohos.permission.GET_WIFI_INFO 2165 2166**System capability**: SystemCapability.Communication.WiFi.P2P 2167 2168**Error codes** 2169 2170For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2171 2172| **ID**| **Error Message**| 2173| -------- | -------- | 2174| 201 | Permission denied. | 2175| 801 | Capability not supported. | 2176| 2801000 | Operation failed. | 2177| 2801001 | Wi-Fi STA disabled. | 2178 2179**Example** 2180```ts 2181 import { wifiManager } from '@kit.ConnectivityKit'; 2182 2183 try { 2184 wifiManager.removeGroup(); 2185 }catch(error){ 2186 console.error("failed:" + JSON.stringify(error)); 2187 } 2188``` 2189 2190## wifiManager.p2pConnect<sup>9+</sup> 2191 2192p2pConnect(config: WifiP2PConfig): void 2193 2194Sets up a P2P connection. 2195 2196**Required permissions**: 2197 2198API version 10 and later: ohos.permission.GET_WIFI_INFO 2199 2200**System capability**: SystemCapability.Communication.WiFi.P2P 2201 2202**Parameters** 2203 2204| **Name**| **Type**| Mandatory| **Description**| 2205| -------- | -------- | -------- | -------- | 2206| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration. The default **DeviceAddressType** is random device address.| 2207 2208**Error codes** 2209 2210For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2211 2212| **ID**| **Error Message**| 2213| -------- | -------- | 2214| 201 | Permission denied. | 2215| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 2216| 801 | Capability not supported. | 2217| 2801000 | Operation failed. | 2218| 2801001 | Wi-Fi STA disabled. | 2219 2220**Example** 2221```ts 2222 import { wifiManager } from '@kit.ConnectivityKit'; 2223 2224 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 2225 console.info("p2p connection change receive event: " + JSON.stringify(result)); 2226 wifiManager.getP2pLinkedInfo((err, data:wifiManager.WifiP2pLinkedInfo) => { 2227 if (err) { 2228 console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); 2229 return; 2230 } 2231 console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); 2232 }); 2233 } 2234 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 2235 2236 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 2237 console.info("p2p device change receive event: " + JSON.stringify(result)); 2238 } 2239 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 2240 2241 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 2242 console.info("p2p peer device change receive event: " + JSON.stringify(result)); 2243 wifiManager.getP2pPeerDevices((err, data:wifiManager.WifiP2pDevice[]) => { 2244 if (err) { 2245 console.error('failed to get peer devices: ' + JSON.stringify(err)); 2246 return; 2247 } 2248 console.info("get peer devices: " + JSON.stringify(data)); 2249 let len = data.length; 2250 for (let i = 0; i < len; ++i) { 2251 if (data[i].deviceName === "my_test_device") { 2252 console.info("p2p connect to test device: " + data[i].deviceAddress); 2253 let config:wifiManager.WifiP2PConfig = { 2254 deviceAddress:data[i].deviceAddress, 2255 netId:-2, 2256 passphrase:"", 2257 groupName:"", 2258 goBand:0, 2259 } 2260 wifiManager.p2pConnect(config); 2261 } 2262 } 2263 }); 2264 } 2265 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 2266 2267 let recvP2pPersistentGroupChangeFunc = () => { 2268 console.info("p2p persistent group change receive event"); 2269 2270 wifiManager.getCurrentGroup((err, data:wifiManager.WifiP2pGroupInfo) => { 2271 if (err) { 2272 console.error('failed to get current group: ' + JSON.stringify(err)); 2273 return; 2274 } 2275 console.info("get current group: " + JSON.stringify(data)); 2276 }); 2277 } 2278 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 2279 2280 setTimeout(() => {wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); 2281 setTimeout(() => {wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); 2282 setTimeout(() => {wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); 2283 setTimeout(() => {wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); 2284 console.info("start discover devices -> " + wifiManager.startDiscoverDevices()); 2285``` 2286 2287## wifiManager.p2pCancelConnect<sup>9+</sup> 2288 2289p2pCancelConnect(): void 2290 2291Cancels the P2P connection being set up. 2292 2293**Required permissions**: ohos.permission.GET_WIFI_INFO 2294 2295**System capability**: SystemCapability.Communication.WiFi.P2P 2296 2297**Error codes** 2298 2299For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2300 2301| **ID**| **Error Message**| 2302| -------- | -------- | 2303| 201 | Permission denied. | 2304| 801 | Capability not supported. | 2305| 2801000 | Operation failed. | 2306| 2801001 | Wi-Fi STA disabled. | 2307 2308**Example** 2309```ts 2310 import { wifiManager } from '@kit.ConnectivityKit'; 2311 2312 try { 2313 wifiManager.p2pCancelConnect(); 2314 }catch(error){ 2315 console.error("failed:" + JSON.stringify(error)); 2316 } 2317``` 2318 2319## wifiManager.startDiscoverDevices<sup>9+</sup> 2320 2321startDiscoverDevices(): void 2322 2323Starts to discover devices. 2324 2325**Required permissions**: 2326 2327API version 10 and later: ohos.permission.GET_WIFI_INFO 2328 2329**System capability**: SystemCapability.Communication.WiFi.P2P 2330 2331**Error codes** 2332 2333For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2334 2335| **ID**| **Error Message**| 2336| -------- | -------- | 2337| 201 | Permission denied. | 2338| 801 | Capability not supported. | 2339| 2801000 | Operation failed. | 2340| 2801001 | Wi-Fi STA disabled. | 2341 2342**Example** 2343```ts 2344 import { wifiManager } from '@kit.ConnectivityKit'; 2345 2346 try { 2347 wifiManager.startDiscoverDevices(); 2348 }catch(error){ 2349 console.error("failed:" + JSON.stringify(error)); 2350 } 2351``` 2352 2353## wifiManager.stopDiscoverDevices<sup>9+</sup> 2354 2355stopDiscoverDevices(): void 2356 2357Stops discovering devices. 2358 2359**Required permissions**: ohos.permission.GET_WIFI_INFO 2360 2361**System capability**: SystemCapability.Communication.WiFi.P2P 2362 2363**Error codes** 2364 2365For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2366 2367| **ID**| **Error Message**| 2368| -------- | -------- | 2369| 201 | Permission denied. | 2370| 801 | Capability not supported. | 2371| 2801000 | Operation failed. | 2372| 2801001 | Wi-Fi STA disabled. | 2373 2374**Example** 2375```ts 2376 import { wifiManager } from '@kit.ConnectivityKit'; 2377 2378 try { 2379 wifiManager.stopDiscoverDevices(); 2380 }catch(error){ 2381 console.error("failed:" + JSON.stringify(error)); 2382 } 2383``` 2384 2385 2386 2387## WifiP2pGroupInfo<sup>9+</sup> 2388 2389Represents the P2P group information. 2390 2391**System capability**: SystemCapability.Communication.WiFi.P2P 2392 2393| Name| Type| Readable| Writable| Description| 2394| -------- | -------- | -------- | -------- | -------- | 2395| isP2pGo | boolean | Yes| No| Whether the device is the group owner.| 2396| ownerInfo | [WifiP2pDevice](#wifip2pdevice9) | Yes| No| Device information of the group.| 2397| passphrase | string | Yes| No| Passphrase of the group.| 2398| interface | string | Yes| No| Interface name.| 2399| groupName | string | Yes| No| Group name.| 2400| networkId | number | Yes| No| Network ID.| 2401| frequency | number | Yes| No| Frequency of the group.| 2402| clientDevices | [WifiP2pDevice[]](#wifip2pdevice9) | Yes| No| List of connected devices.| 2403| goIpAddress | string | Yes| No| IP address of the group.| 2404 2405 2406## wifiManager.on('wifiStateChange')<sup>9+</sup> 2407 2408on(type: 'wifiStateChange', callback: Callback<number>): void 2409 2410Subscribes to WLAN state changes. When the service exits, call off(type: 'wifiStateChange', callback?: Callback<number>) to unregister the callback registered. 2411 2412**Required permissions**: ohos.permission.GET_WIFI_INFO 2413 2414**Atomic service API**: This API can be used in atomic services since API version 12. 2415 2416**System capability**: SystemCapability.Communication.WiFi.STA 2417 2418**Parameters** 2419 2420 | **Name**| **Type**| **Mandatory**| **Description**| 2421 | -------- | -------- | -------- | -------- | 2422 | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 2423 | callback | Callback<number> | Yes| Callback used to return the WLAN state.| 2424 2425**Error codes** 2426 2427For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2428 2429| **ID**| **Error Message**| 2430| -------- | ---------------------------- | 2431| 201 | Permission denied. | 2432| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2433| 801 | Capability not supported. | 2434| 2501000 | Operation failed.| 2435 2436**WLAN states** 2437 2438| **Value**| **Description**| 2439| -------- | -------- | 2440| 0 | Deactivated| 2441| 1 | Activated| 2442| 2 | Activating| 2443| 3 | Deactivating| 2444 2445 2446## wifiManager.off('wifiStateChange')<sup>9+</sup> 2447 2448off(type: 'wifiStateChange', callback?: Callback<number>): void 2449 2450Unsubscribes from WLAN state changes. 2451 2452**Required permissions**: ohos.permission.GET_WIFI_INFO 2453 2454**Atomic service API**: This API can be used in atomic services since API version 12. 2455 2456**System capability**: SystemCapability.Communication.WiFi.STA 2457 2458**Parameters** 2459 2460 | **Name**| **Type**| **Mandatory**| **Description**| 2461 | -------- | -------- | -------- | -------- | 2462 | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 2463 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2464 2465**Error codes** 2466 2467For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2468 2469| **ID**| **Error Message**| 2470| -------- | ---------------------------- | 2471| 201 | Permission denied. | 2472| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2473| 801 | Capability not supported. | 2474| 2501000 | Operation failed.| 2475 2476**Example** 2477```ts 2478 import { wifiManager } from '@kit.ConnectivityKit'; 2479 2480 let recvPowerNotifyFunc = (result:number) => { 2481 console.info("Receive power state change event: " + result); 2482 } 2483 2484 // Register an event. 2485 wifiManager.on("wifiStateChange", recvPowerNotifyFunc); 2486 2487 // Unregister an event. 2488 wifiManager.off("wifiStateChange", recvPowerNotifyFunc); 2489``` 2490 2491 2492## wifiManager.on('wifiConnectionChange')<sup>9+</sup> 2493 2494on(type: 'wifiConnectionChange', callback: Callback<number>): void 2495 2496Subscribes to WLAN connection state changes. When the service exits, call off(type: 'wifiConnectionChange', callback?: Callback<number>) to unregister the callback registered. 2497 2498**Required permissions**: ohos.permission.GET_WIFI_INFO 2499 2500**Atomic service API**: This API can be used in atomic services since API version 12. 2501 2502**System capability**: SystemCapability.Communication.WiFi.STA 2503 2504**Parameters** 2505 2506 | **Name**| **Type**| **Mandatory**| **Description**| 2507 | -------- | -------- | -------- | -------- | 2508 | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 2509 | callback | Callback<number> | Yes| Callback used to return the WLAN connection state.| 2510 2511**WLAN connection states** 2512 2513| **Value**| **Description**| 2514| -------- | -------- | 2515| 0 | Disconnected.| 2516| 1 | Connected.| 2517 2518**Error codes** 2519 2520For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2521 2522| **ID**| **Error Message**| 2523| -------- | ---------------------------- | 2524| 201 | Permission denied. | 2525| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2526| 801 | Capability not supported. | 2527| 2501000 | Operation failed.| 2528 2529## wifiManager.off('wifiConnectionChange')<sup>9+</sup> 2530 2531off(type: 'wifiConnectionChange', callback?: Callback<number>): void 2532 2533Unsubscribes from WLAN connection state changes. 2534 2535**Required permissions**: ohos.permission.GET_WIFI_INFO 2536 2537**Atomic service API**: This API can be used in atomic services since API version 12. 2538 2539**System capability**: SystemCapability.Communication.WiFi.STA 2540 2541**Parameters** 2542 2543 | **Name**| **Type**| **Mandatory**| **Description**| 2544 | -------- | -------- | -------- | -------- | 2545 | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 2546 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2547 2548**Error codes** 2549 2550For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2551 2552| **ID**| **Error Message**| 2553| -------- | ---------------------------- | 2554| 201 | Permission denied. | 2555| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2556| 801 | Capability not supported. | 2557| 2501000 | Operation failed.| 2558 2559**Example** 2560```ts 2561 import { wifiManager } from '@kit.ConnectivityKit'; 2562 2563 let recvWifiConnectionChangeFunc = (result:number) => { 2564 console.info("Receive wifi connection change event: " + result); 2565 } 2566 2567 // Register an event. 2568 wifiManager.on("wifiConnectionChange", recvWifiConnectionChangeFunc); 2569 2570 // Unregister an event. 2571 wifiManager.off("wifiConnectionChange", recvWifiConnectionChangeFunc); 2572``` 2573 2574## wifiManager.on('wifiScanStateChange')<sup>9+</sup> 2575 2576on(type: 'wifiScanStateChange', callback: Callback<number>): void 2577 2578Subscribes to WLAN scan state changes. When the service exits, call off(type: 'wifiScanStateChange', callback?: Callback<number>) to unregister the callback registered. 2579 2580**Required permissions**: ohos.permission.GET_WIFI_INFO 2581 2582**Atomic service API**: This API can be used in atomic services since API version 12. 2583 2584**System capability**: SystemCapability.Communication.WiFi.STA 2585 2586**Parameters** 2587 2588 | **Name**| **Type**| **Mandatory**| **Description**| 2589 | -------- | -------- | -------- | -------- | 2590 | type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 2591 | callback | Callback<number> | Yes| Callback used to return the WLAN scan state.| 2592 2593**WLAN scan states** 2594 2595| **Value**| **Description**| 2596| -------- | -------- | 2597| 0 | Scan failed.| 2598| 1 | Scan successful.| 2599 2600**Error codes** 2601 2602For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2603 2604| **ID**| **Error Message**| 2605| -------- | ---------------------------- | 2606| 201 | Permission denied. | 2607| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2608| 801 | Capability not supported. | 2609| 2501000 | Operation failed.| 2610 2611## wifiManager.off('wifiScanStateChange')<sup>9+</sup> 2612 2613off(type: 'wifiScanStateChange', callback?: Callback<number>): void 2614 2615Unsubscribes from WLAN scan state changes. 2616 2617**Required permissions**: ohos.permission.GET_WIFI_INFO 2618 2619**Atomic service API**: This API can be used in atomic services since API version 12. 2620 2621**System capability**: SystemCapability.Communication.WiFi.STA 2622 2623**Parameters** 2624 2625| **Name**| **Type**| **Mandatory**| **Description**| 2626| -------- | -------- | -------- | -------- | 2627| type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 2628| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2629 2630**Error codes** 2631 2632For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2633 2634| **ID**| **Error Message**| 2635| -------- | ---------------------------- | 2636| 201 | Permission denied. | 2637| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2638| 801 | Capability not supported. | 2639| 2501000 | Operation failed.| 2640 2641**Example** 2642```ts 2643 import { wifiManager } from '@kit.ConnectivityKit'; 2644 2645 let recvWifiScanStateChangeFunc = (result:number) => { 2646 console.info("Receive Wifi scan state change event: " + result); 2647 } 2648 2649 // Register an event. 2650 wifiManager.on("wifiScanStateChange", recvWifiScanStateChangeFunc); 2651 2652 // Unregister an event. 2653 wifiManager.off("wifiScanStateChange", recvWifiScanStateChangeFunc); 2654``` 2655 2656## wifiManager.on('wifiRssiChange')<sup>9+</sup> 2657 2658on(type: 'wifiRssiChange', callback: Callback<number>): void 2659 2660Subscribes to RSSI changes. When the service exits, call off(type: 'wifiRssiChange', callback?: Callback<number>) to unregister the callback registered. 2661 2662**Required permissions**: ohos.permission.GET_WIFI_INFO 2663 2664**System capability**: SystemCapability.Communication.WiFi.STA 2665 2666**Parameters** 2667 2668 | **Name**| **Type**| **Mandatory**| **Description**| 2669 | -------- | -------- | -------- | -------- | 2670 | type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 2671 | callback | Callback<number> | Yes| Callback used to return the RSSI, in dBm.| 2672 2673**Error codes** 2674 2675For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2676 2677| **ID**| **Error Message**| 2678| -------- | ---------------------------- | 2679| 201 | Permission denied. | 2680| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2681| 801 | Capability not supported. | 2682| 2501000 | Operation failed.| 2683 2684## wifiManager.off('wifiRssiChange')<sup>9+</sup> 2685 2686off(type: 'wifiRssiChange', callback?: Callback<number>): void 2687 2688Unsubscribes from RSSI changes. 2689 2690**Required permissions**: ohos.permission.GET_WIFI_INFO 2691 2692**System capability**: SystemCapability.Communication.WiFi.STA 2693 2694**Parameters** 2695 2696| **Name**| **Type**| **Mandatory**| **Description**| 2697| -------- | -------- | -------- | -------- | 2698| type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 2699| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2700 2701**Error codes** 2702 2703For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2704 2705| **ID**| **Error Message**| 2706| -------- | ---------------------------- | 2707| 201 | Permission denied. | 2708| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2709| 801 | Capability not supported. | 2710| 2501000 | Operation failed.| 2711 2712**Example** 2713```ts 2714 import { wifiManager } from '@kit.ConnectivityKit'; 2715 2716 let recvWifiRssiChangeFunc = (result:number) => { 2717 console.info("Receive wifi rssi change event: " + result); 2718 } 2719 2720 // Register an event. 2721 wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc); 2722 2723 // Unregister an event. 2724 wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc); 2725``` 2726 2727## wifiManager.on('hotspotStateChange')<sup>9+</sup> 2728 2729on(type: 'hotspotStateChange', callback: Callback<number>): void 2730 2731Subscribes to hotspot state changes. When the service exits, call off(type: 'hotspotStateChange', callback?: Callback<number>) to unregister the callback registered. 2732 2733**Required permissions**: ohos.permission.GET_WIFI_INFO 2734 2735**System capability**: SystemCapability.Communication.WiFi.AP.Core 2736 2737**Parameters** 2738 2739| **Name**| **Type**| **Mandatory**| **Description**| 2740| -------- | -------- | -------- | -------- | 2741| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 2742| callback | Callback<number> | Yes| Callback used to return the hotspot state.| 2743 2744**Hotspot states** 2745 2746| **Value**| **Description**| 2747| -------- | -------- | 2748| 0 | Deactivated| 2749| 1 | Activated| 2750| 2 | Activating| 2751| 3 | Deactivating| 2752 2753**Error codes** 2754 2755For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2756 2757| **ID**| **Error Message**| 2758| -------- | ---------------------------- | 2759| 201 | Permission denied. | 2760| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2761| 801 | Capability not supported. | 2762| 2601000 | Operation failed. | 2763 2764## wifiManager.off('hotspotStateChange')<sup>9+</sup> 2765 2766off(type: 'hotspotStateChange', callback?: Callback<number>): void 2767 2768Unsubscribes from hotspot state changes. 2769 2770**Required permissions**: ohos.permission.GET_WIFI_INFO 2771 2772**System capability**: SystemCapability.Communication.WiFi.AP.Core 2773 2774**Parameters** 2775 2776| **Name**| **Type**| **Mandatory**| **Description**| 2777| -------- | -------- | -------- | -------- | 2778| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 2779| callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2780 2781**Error codes** 2782 2783For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2784 2785| **ID**| **Error Message**| 2786| -------- | ---------------------------- | 2787| 201 | Permission denied. | 2788| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2789| 801 | Capability not supported. | 2790| 2601000 | Operation failed. | 2791 2792**Example** 2793```ts 2794 import { wifiManager } from '@kit.ConnectivityKit'; 2795 2796 let recvHotspotStateChangeFunc = (result:number) => { 2797 console.info("Receive hotspot state change event: " + result); 2798 } 2799 2800 // Register an event. 2801 wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc); 2802 2803 // Unregister an event. 2804 wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc); 2805``` 2806 2807 2808## wifiManager.on('p2pStateChange')<sup>9+</sup> 2809 2810on(type: 'p2pStateChange', callback: Callback<number>): void 2811 2812Subscribes to P2P state changes. When the service exits, call off(type: 'p2pStateChange', callback?: Callback<number>) to unregister the callback registered. 2813 2814**Required permissions**: ohos.permission.GET_WIFI_INFO 2815 2816**System capability**: SystemCapability.Communication.WiFi.P2P 2817 2818**Parameters** 2819 2820| **Name**| **Type**| **Mandatory**| **Description**| 2821| -------- | -------- | -------- | -------- | 2822| type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 2823| callback | Callback<number> | Yes| Callback used to return the P2P state.| 2824 2825**P2P states** 2826 2827| **Value**| **Description**| 2828| -------- | -------- | 2829| 1 | Available| 2830| 2 | Opening| 2831| 3 | Opened| 2832| 4 | Closing| 2833| 5 | Closed| 2834 2835**Error codes** 2836 2837For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2838 2839| **ID**| **Error Message**| 2840| -------- | ---------------------------- | 2841| 201 | Permission denied. | 2842| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2843| 801 | Capability not supported. | 2844| 2801000 | Operation failed. | 2845 2846## wifiManager.off('p2pStateChange')<sup>9+</sup> 2847 2848off(type: 'p2pStateChange', callback?: Callback<number>): void 2849 2850Unsubscribes from P2P state changes. 2851 2852**Required permissions**: ohos.permission.GET_WIFI_INFO 2853 2854**System capability**: SystemCapability.Communication.WiFi.P2P 2855 2856**Parameters** 2857 2858 | **Name**| **Type**| **Mandatory**| **Description**| 2859 | -------- | -------- | -------- | -------- | 2860 | type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 2861 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2862 2863**Error codes** 2864 2865For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2866 2867| **ID**| **Error Message**| 2868| -------- | ---------------------------- | 2869| 201 | Permission denied. | 2870| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2871| 801 | Capability not supported. | 2872| 2801000 | Operation failed. | 2873 2874**Example** 2875```ts 2876 import { wifiManager } from '@kit.ConnectivityKit'; 2877 2878 let recvP2pStateChangeFunc = (result:number) => { 2879 console.info("Receive p2p state change event: " + result); 2880 } 2881 2882 // Register an event. 2883 wifiManager.on("p2pStateChange", recvP2pStateChangeFunc); 2884 2885 // Unregister an event. 2886 wifiManager.off("p2pStateChange", recvP2pStateChangeFunc); 2887``` 2888 2889## wifiManager.on('p2pConnectionChange')<sup>9+</sup> 2890 2891on(type: 'p2pConnectionChange', callback: Callback<WifiP2pLinkedInfo>): void 2892 2893Subscribes to P2P connection state changes. When the service exits, call off(type: 'p2pConnectionChange', callback?: Callback<WifiP2pLinkedInfo>) to unregister the callback registered. 2894 2895**Required permissions**: ohos.permission.GET_WIFI_INFO 2896 2897**System capability**: SystemCapability.Communication.WiFi.P2P 2898 2899**Parameters** 2900 2901 | **Name**| **Type**| **Mandatory**| **Description**| 2902 | -------- | -------- | -------- | -------- | 2903 | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 2904 | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback used to return the WLAN state.| 2905 2906**Error codes** 2907 2908For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2909 2910| **ID**| **Error Message**| 2911| -------- | ---------------------------- | 2912| 201 | Permission denied. | 2913| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2914| 801 | Capability not supported. | 2915| 2801000 | Operation failed. | 2916 2917## wifiManager.off('p2pConnectionChange')<sup>9+</sup> 2918 2919off(type: 'p2pConnectionChange', callback?: Callback<WifiP2pLinkedInfo>): void 2920 2921Unsubscribes from P2P connection state changes. 2922 2923**Required permissions**: ohos.permission.GET_WIFI_INFO 2924 2925**System capability**: SystemCapability.Communication.WiFi.P2P 2926 2927**Parameters** 2928 2929 | **Name**| **Type**| **Mandatory**| **Description**| 2930 | -------- | -------- | -------- | -------- | 2931 | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 2932 | callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 2933 2934**Error codes** 2935 2936For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2937 2938| **ID**| **Error Message**| 2939| -------- | ---------------------------- | 2940| 201 | Permission denied. | 2941| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2942| 801 | Capability not supported. | 2943| 2801000 | Operation failed. | 2944 2945**Example** 2946```ts 2947 import { wifiManager } from '@kit.ConnectivityKit'; 2948 2949 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 2950 console.info("Receive p2p connection change event: " + result); 2951 } 2952 2953 // Register an event. 2954 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 2955 2956 // Unregister an event. 2957 wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc); 2958``` 2959 2960## wifiManager.on('p2pDeviceChange')<sup>9+</sup> 2961 2962on(type: 'p2pDeviceChange', callback: Callback<WifiP2pDevice>): void 2963 2964Subscribes to P2P device status changes. When the service exits, call off(type: 'p2pDeviceChange', callback?: Callback<WifiP2pDevice>) to unregister the callback registered. 2965 2966**Required permissions**: 2967 2968API version 10 and later: ohos.permission.GET_WIFI_INFO 2969 2970**System capability**: SystemCapability.Communication.WiFi.P2P 2971 2972**Parameters** 2973 2974 | **Name**| **Type**| **Mandatory**| **Description**| 2975 | -------- | -------- | -------- | -------- | 2976 | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 2977 | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback used to return the WLAN state.| 2978 2979**Error codes** 2980 2981For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2982 2983| **ID**| **Error Message**| 2984| -------- | ---------------------------- | 2985| 201 | Permission denied. | 2986| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2987| 801 | Capability not supported. | 2988| 2801000 | Operation failed. | 2989 2990## wifiManager.off('p2pDeviceChange')<sup>9+</sup> 2991 2992off(type: 'p2pDeviceChange', callback?: Callback<WifiP2pDevice>): void 2993 2994Unsubscribes from P2P device state changes. 2995 2996**System capability**: SystemCapability.Communication.WiFi.P2P 2997 2998**Parameters** 2999 3000 | **Name**| **Type**| **Mandatory**| **Description**| 3001 | -------- | -------- | -------- | -------- | 3002 | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 3003 | callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 3004 3005**Error codes** 3006 3007For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3008 3009| **ID**| **Error Message**| 3010| -------- | ---------------------------- | 3011| 201<sup>10+</sup> | Permission denied. | 3012| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3013| 801 | Capability not supported. | 3014| 2801000 | Operation failed. | 3015 3016**Example** 3017```ts 3018 import { wifiManager } from '@kit.ConnectivityKit'; 3019 3020 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 3021 console.info("Receive p2p device change event: " + result); 3022 } 3023 3024 // Register an event. 3025 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 3026 3027 // Unregister an event. 3028 wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc); 3029``` 3030 3031## wifiManager.on('p2pPeerDeviceChange')<sup>9+</sup> 3032 3033on(type: 'p2pPeerDeviceChange', callback: Callback<WifiP2pDevice[]>): void 3034 3035Subscribes to P2P peer device status changes. When the service exits, call off(type: 'p2pPeerDeviceChange', callback?: Callback<WifiP2pDevice[]>) to unregister the callback registered. 3036 3037**Required permissions**: 3038 3039API version 10 and later: ohos.permission.GET_WIFI_INFO 3040 3041**System capability**: SystemCapability.Communication.WiFi.P2P 3042 3043**Parameters** 3044 3045| **Name**| **Type**| **Mandatory**| **Description**| 3046| -------- | -------- | -------- | -------- | 3047| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 3048| 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.| 3049 3050**Error codes** 3051 3052For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3053 3054| **ID**| **Error Message**| 3055| -------- | ---------------------------- | 3056| 201 | Permission denied. | 3057| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3058| 801 | Capability not supported. | 3059| 2801000 | Operation failed. | 3060 3061## wifiManager.off('p2pPeerDeviceChange')<sup>9+</sup> 3062 3063off(type: 'p2pPeerDeviceChange', callback?: Callback<WifiP2pDevice[]>): void 3064 3065Unsubscribes from P2P peer device state changes. 3066 3067**System capability**: SystemCapability.Communication.WiFi.P2P 3068 3069**Parameters** 3070 3071| **Name**| **Type**| **Mandatory**| **Description**| 3072| -------- | -------- | -------- | -------- | 3073| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 3074| 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.| 3075 3076**Error codes** 3077 3078For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3079 3080| **ID**| **Error Message**| 3081| -------- | ---------------------------- | 3082| 201<sup>10+</sup> | Permission denied. | 3083| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3084| 801 | Capability not supported. | 3085| 2801000 | Operation failed. | 3086 3087**Example** 3088```ts 3089 import { wifiManager } from '@kit.ConnectivityKit'; 3090 3091 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 3092 console.info("Receive p2p peer device change event: " + result); 3093 } 3094 3095 // Register an event. 3096 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 3097 3098 // Unregister an event. 3099 wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 3100``` 3101 3102## wifiManager.on('p2pPersistentGroupChange')<sup>9+</sup> 3103 3104on(type: 'p2pPersistentGroupChange', callback: Callback<void>): void 3105 3106Subscribes to P2P persistent group changes. When the service exits, call off(type: 'p2pPersistentGroupChange', callback?: Callback<void>) to unregister the callback registered. 3107 3108**Required permissions**: ohos.permission.GET_WIFI_INFO 3109 3110**System capability**: SystemCapability.Communication.WiFi.P2P 3111 3112**Parameters** 3113 3114 | **Name**| **Type**| **Mandatory**| **Description**| 3115 | -------- | -------- | -------- | -------- | 3116 | type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 3117 | callback | Callback<void> | Yes| Callback used to return the WLAN state.| 3118 3119**Error codes** 3120 3121For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3122 3123| **ID**| **Error Message**| 3124| -------- | ---------------------------- | 3125| 201 | Permission denied. | 3126| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3127| 801 | Capability not supported. | 3128| 2801000 | Operation failed. | 3129 3130## wifiManager.off('p2pPersistentGroupChange')<sup>9+</sup> 3131 3132off(type: 'p2pPersistentGroupChange', callback?: Callback<void>): void 3133 3134Unsubscribes from P2P persistent group state changes. 3135 3136**Required permissions**: ohos.permission.GET_WIFI_INFO 3137 3138**System capability**: SystemCapability.Communication.WiFi.P2P 3139 3140**Parameters** 3141 3142| **Name**| **Type**| **Mandatory**| **Description**| 3143| -------- | -------- | -------- | -------- | 3144| type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 3145| callback | Callback<void> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 3146 3147**Error codes** 3148 3149For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3150 3151| **ID**| **Error Message**| 3152| -------- | ---------------------------- | 3153| 201 | Permission denied. | 3154| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3155| 801 | Capability not supported. | 3156| 2801000 | Operation failed. | 3157 3158**Example** 3159```ts 3160 import { wifiManager } from '@kit.ConnectivityKit'; 3161 3162 let recvP2pPersistentGroupChangeFunc = (result:void) => { 3163 console.info("Receive p2p persistent group change event: " + result); 3164 } 3165 3166 // Register an event. 3167 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 3168 3169 // Unregister an event. 3170 wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 3171``` 3172 3173## wifiManager.on('p2pDiscoveryChange')<sup>9+</sup> 3174 3175on(type: 'p2pDiscoveryChange', callback: Callback<number>): void 3176 3177Subscribes to P2P device discovery changes. When the service exits, call off(type: 'p2pDiscoveryChange', callback?: Callback<number>) to unregister the callback registered. 3178 3179**Required permissions**: ohos.permission.GET_WIFI_INFO 3180 3181**System capability**: SystemCapability.Communication.WiFi.P2P 3182 3183**Parameters** 3184 3185 | **Name**| **Type**| **Mandatory**| **Description**| 3186 | -------- | -------- | -------- | -------- | 3187 | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 3188 | callback | Callback<number> | Yes| Callback used to return the P2P device discovery change.| 3189 3190**P2P discovered device states** 3191 3192| **Value**| **Description**| 3193| -------- | -------- | 3194| 0 | Initial state.| 3195| 1 | Discovered.| 3196 3197**Error codes** 3198 3199For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3200 3201| **ID**| **Error Message**| 3202| -------- | ---------------------------- | 3203| 201 | Permission denied. | 3204| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3205| 801 | Capability not supported. | 3206| 2801000 | Operation failed. | 3207 3208## wifiManager.off('p2pDiscoveryChange')<sup>9+</sup> 3209 3210off(type: 'p2pDiscoveryChange', callback?: Callback<number>): void 3211 3212Unsubscribes from P2P device discovery state changes. 3213 3214**Required permissions**: ohos.permission.GET_WIFI_INFO 3215 3216**System capability**: SystemCapability.Communication.WiFi.P2P 3217 3218**Parameters** 3219 3220 | **Name**| **Type**| **Mandatory**| **Description**| 3221 | -------- | -------- | -------- | -------- | 3222 | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 3223 | callback | Callback<number> | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.| 3224 3225**Error codes** 3226 3227For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 3228 3229| **ID**| **Error Message**| 3230| -------- | ---------------------------- | 3231| 201 | Permission denied. | 3232| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 3233| 801 | Capability not supported. | 3234| 2801000 | Operation failed. | 3235 3236**Example** 3237```ts 3238 import { wifiManager } from '@kit.ConnectivityKit'; 3239 3240 let recvP2pDiscoveryChangeFunc = (result:number) => { 3241 console.info("Receive p2p discovery change event: " + result); 3242 } 3243 3244 // Register an event. 3245 wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 3246 3247 // Unregister an event. 3248 wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 3249``` 3250