1# @ohos.wifiManager (WLAN) 2The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with devices over WLAN. 3 4> **NOTE** 5> 6> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 7 8 9## Modules to Import 10 11```ts 12import wifiManager from '@ohos.wifiManager'; 13``` 14 15## wifiManager.enableWifi<sup>9+</sup> 16 17enableWifi(): void 18 19Enables WLAN. This API is an asynchronous interface. The **wifiStateChange** callback must be registered and listened for. 20 21**System API**: This is a system API. 22 23**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 24 25**System capability**: SystemCapability.Communication.WiFi.STA 26 27**Error codes** 28 29For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 30 31| **ID**| **Error Message**| 32| -------- | -------- | 33| 2501000 | Operation failed.| 34| 2501003 | Failed to enable Wi-Fi.| 35 36**Example** 37 38```ts 39 import wifiManager from '@ohos.wifiManager'; 40 41 try { 42 wifiManager.enableWifi(); 43 }catch(error){ 44 console.error("failed:" + JSON.stringify(error)); 45 } 46``` 47 48## wifiManager.disableWifi<sup>9+</sup> 49 50disableWifi(): void 51 52Disables WLAN. This API is an asynchronous interface. The **wifiStateChange** callback must be registered and listened for. 53 54**System API**: This is a system API. 55 56**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 57 58**System capability**: SystemCapability.Communication.WiFi.STA 59 60**Error codes** 61 62For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 63 64| **ID**| **Error Message**| 65| -------- | -------- | 66| 2501000 | Operation failed.| 67| 2501004 | Failed to disable Wi-Fi.| 68 69**Example** 70 71```ts 72 import wifiManager from '@ohos.wifiManager'; 73 74 try { 75 wifiManager.disableWifi(); 76 }catch(error){ 77 console.error("failed:" + JSON.stringify(error)); 78 } 79``` 80 81## wifiManager.isWifiActive<sup>9+</sup> 82 83isWifiActive(): boolean 84 85Checks whether WLAN is enabled. 86 87**Required permissions**: ohos.permission.GET_WIFI_INFO 88 89**System capability**: SystemCapability.Communication.WiFi.STA 90 91**Return value** 92 93| **Type**| **Description**| 94| -------- | -------- | 95| boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| 96 97**Error codes** 98 99For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 100 101| **ID**| **Error Message**| 102| -------- | -------- | 103| 2501000 | Operation failed.| 104 105**Example** 106 107```ts 108 import wifiManager from '@ohos.wifiManager'; 109 110 try { 111 let isWifiActive = wifiManager.isWifiActive(); 112 console.info("isWifiActive:" + isWifiActive); 113 }catch(error){ 114 console.error("failed:" + JSON.stringify(error)); 115 } 116``` 117 118## wifiManager.scan<sup>9+</sup> 119 120scan(): void 121 122Starts a scan for WLAN. 123 124**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 125 126**System capability**: SystemCapability.Communication.WiFi.STA 127 128**Error codes** 129 130For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 131 132| **ID**| **Error Message**| 133| -------- | -------- | 134| 2501000 | Operation failed.| 135 136**Example** 137 138```ts 139 import wifiManager from '@ohos.wifiManager'; 140 141 try { 142 wifiManager.scan(); 143 }catch(error){ 144 console.error("failed:" + JSON.stringify(error)); 145 } 146``` 147 148## wifiManager.startScan<sup>10+</sup> 149 150startScan(): void 151 152**System API**: This is a system API. 153 154Starts a scan for WLAN. 155 156**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 157 158**System capability**: SystemCapability.Communication.WiFi.STA 159 160**Error codes** 161 162For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 163 164| **ID**| **Error Message**| 165| -------- | -------- | 166| 2501000 | Operation failed.| 167 168**Example** 169 170```ts 171 import wifiManager from '@ohos.wifiManager'; 172 173 try { 174 wifiManager.startScan(); 175 }catch(error){ 176 console.error("failed:" + JSON.stringify(error)); 177 } 178``` 179## wifiManager.getScanResults<sup>9+</sup> 180 181getScanResults(): Promise<Array<WifiScanInfo>> 182 183Obtains the scan result. This API uses a promise to return the result. 184 185**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 186 187**System capability**: SystemCapability.Communication.WiFi.STA 188 189**Return value** 190 191| **Type**| **Description**| 192| -------- | -------- | 193| Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | Promise used to return the hotspots detected.| 194 195**Error codes** 196 197For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 198 199| **ID**| **Error Message**| 200| -------- | -------- | 201| 2501000 | Operation failed.| 202 203## wifiManager.getScanResults<sup>9+</sup> 204 205getScanResults(callback: AsyncCallback<Array<WifiScanInfo>>): void 206 207Obtains the scan result. This API uses an asynchronous callback to return the result. 208 209**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 210 211**System capability**: SystemCapability.Communication.WiFi.STA 212 213**Parameters** 214| **Name**| **Type**| **Mandatory**| **Description**| 215| -------- | -------- | -------- | -------- | 216| callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked 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.| 217| Array<[WifiScanInfo](#wifiscaninfo)> | Hotspots detected.| 218 219**Error codes** 220 221For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 222 223| **ID**| **Error Message**| 224| -------- | -------- | 225| 2501000 | Operation failed.| 226 227**Example** 228```ts 229 import wifiManager from '@ohos.wifiManager'; 230 231 wifiManager.getScanResults((err, result) => { 232 if (err) { 233 console.error("get scan info error"); 234 return; 235 } 236 237 let len = result.length; 238 console.log("wifi received scan info: " + len); 239 for (let i = 0; i < len; ++i) { 240 console.info("ssid: " + result[i].ssid); 241 console.info("bssid: " + result[i].bssid); 242 console.info("capabilities: " + result[i].capabilities); 243 console.info("securityType: " + result[i].securityType); 244 console.info("rssi: " + result[i].rssi); 245 console.info("band: " + result[i].band); 246 console.info("frequency: " + result[i].frequency); 247 console.info("channelWidth: " + result[i].channelWidth); 248 console.info("timestamp: " + result[i].timestamp); 249 } 250 }); 251 252 wifiManager.getScanResults().then(result => { 253 let len = result.length; 254 console.log("wifi received scan info: " + len); 255 for (let i = 0; i < len; ++i) { 256 console.info("ssid: " + result[i].ssid); 257 console.info("bssid: " + result[i].bssid); 258 console.info("capabilities: " + result[i].capabilities); 259 console.info("securityType: " + result[i].securityType); 260 console.info("rssi: " + result[i].rssi); 261 console.info("band: " + result[i].band); 262 console.info("frequency: " + result[i].frequency); 263 console.info("channelWidth: " + result[i].channelWidth); 264 console.info("timestamp: " + result[i].timestamp); 265 } 266 }); 267``` 268 269## wifiManager.getScanResultsSync<sup>9+</sup> 270 271getScanResultsSync(): Array<[WifiScanInfo](#wifiscaninfo)> 272 273Obtains the scan result. This API returns the result synchronously. 274 275**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION)) 276 277**System capability**: SystemCapability.Communication.WiFi.STA 278 279**Return value** 280 281| **Type**| **Description**| 282| -------- | -------- | 283| Array<[WifiScanInfo](#wifiscaninfo)> | Scan result obtained.| 284 285**Error codes** 286 287For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 288 289| **ID**| **Error Message**| 290| -------- | -------- | 291| 2501000 | Operation failed.| 292 293**Example** 294 295```ts 296 import wifiManager from '@ohos.wifiManager'; 297 298 try { 299 let scanInfoList = wifiManager.getScanResultsSync(); 300 console.info("scanInfoList:" + JSON.stringify(scanInfoList)); 301 let len = scanInfoList.length; 302 console.log("wifi received scan info: " + len); 303 if(len > 0){ 304 for (let i = 0; i < len; ++i) { 305 console.info("ssid: " + scanInfoList[i].ssid); 306 console.info("bssid: " + scanInfoList[i].bssid); 307 console.info("capabilities: " + scanInfoList[i].capabilities); 308 console.info("securityType: " + scanInfoList[i].securityType); 309 console.info("rssi: " + scanInfoList[i].rssi); 310 console.info("band: " + scanInfoList[i].band); 311 console.info("frequency: " + scanInfoList[i].frequency); 312 console.info("channelWidth: " + scanInfoList[i].channelWidth); 313 console.info("timestamp: " + scanInfoList[i].timestamp); 314 } 315 } 316 }catch(error){ 317 console.error("failed:" + JSON.stringify(error)); 318 } 319 320``` 321 322## wifiManager.getScanInfoList<sup>10+</sup> 323 324getScanInfoList(): Array<WifiScanInfo>; 325 326Obtains the scanning result. 327 328**Required permissions**: ohos.permission.GET_WIFI_INFO 329 330**System capability**: SystemCapability.Communication.WiFi.STA 331 332**Return value** 333 334| **Type**| **Description**| 335| -------- | -------- | 336| Array<[WifiScanInfo](#wifiscaninfo)> | Hotspots detected. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **bssid** in the return value is a real device address; otherwise, **bssid** is a random device address.| 337 338**Error codes** 339 340For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 341 342| **ID**| **Error Message**| 343| -------- | -------- | 344| 2501000 | Operation failed.| 345 346**Example** 347 348```ts 349 import wifiManager from '@ohos.wifiManager'; 350 351 try { 352 let scanInfoList = wifiManager.getScanInfoList(); 353 console.info("scanInfoList:" + JSON.stringify(scanInfoList)); 354 let len = scanInfoList.length; 355 console.log("wifi received scan info: " + len); 356 if(len > 0){ 357 for (let i = 0; i < len; ++i) { 358 console.info("ssid: " + scanInfoList[i].ssid); 359 console.info("bssid: " + scanInfoList[i].bssid); 360 console.info("capabilities: " + scanInfoList[i].capabilities); 361 console.info("securityType: " + scanInfoList[i].securityType); 362 console.info("rssi: " + scanInfoList[i].rssi); 363 console.info("band: " + scanInfoList[i].band); 364 console.info("frequency: " + scanInfoList[i].frequency); 365 console.info("channelWidth: " + scanInfoList[i].channelWidth); 366 console.info("timestamp: " + scanInfoList[i].timestamp); 367 } 368 } 369 }catch(error){ 370 console.error("failed:" + JSON.stringify(error)); 371 } 372 373``` 374 375## WifiScanInfo<sup>9+</sup> 376 377Represents WLAN hotspot information. 378 379**System capability**: SystemCapability.Communication.WiFi.STA 380 381 382| **Name**| **Type**| **Readable**| **Writable**| **Description**| 383| -------- | -------- | -------- | -------- | -------- | 384| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format.| 385| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot.| 386| bssidType<sup>10+</sup>| DeviceAddressType | Yes| No| BSSID type of the hotspot.| 387| capabilities | string | Yes| No| Hotspot capabilities.| 388| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| WLAN security type.| 389| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.| 390| band | number | Yes| No| Frequency band of the WLAN access point (AP).| 391| frequency | number | Yes| No| Frequency of the WLAN AP.| 392| channelWidth | number | Yes| No| Channel width of the WLAN AP.| 393| centerFrequency0 | number | Yes| No| Center frequency of the hotspot.| 394| 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.| 395| infoElems | Array<[WifiInfoElem](#wifiinfoelem9)> | Yes| No| Information elements.| 396| timestamp | number | Yes| No| Timestamp.| 397 398## DeviceAddressType <sup>10+</sup> 399 400Enumerates the Wi-Fi device address (MAC/BISSID) types. 401 402**System capability**: SystemCapability.Communication.WiFi.Core 403 404| **Name**| **Value**| **Description**| 405| -------- | -------- | -------- | 406| RANDOM_DEVICE_ADDRESS | 0 | Random device address.| 407| REAL_DEVICE_ADDRESS | 1 | Read device address.| 408 409## WifiSecurityType<sup>9+</sup> 410 411Enumerates the WLAN security types. 412 413**System capability**: SystemCapability.Communication.WiFi.Core 414 415 416| **Name**| **Value**| **Description**| 417| -------- | -------- | -------- | 418| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.| 419| WIFI_SEC_TYPE_OPEN | 1 | Open security type.| 420| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP).| 421| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK).| 422| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).| 423| WIFI_SEC_TYPE_EAP<sup>9+</sup> | 5 | Extensible Authentication protocol (EAP).| 424| WIFI_SEC_TYPE_EAP_SUITE_B<sup>9+</sup> | 6 | Suite B 192-bit encryption.| 425| WIFI_SEC_TYPE_OWE<sup>9+</sup> | 7 | Opportunistic Wireless Encryption (OWE).| 426| WIFI_SEC_TYPE_WAPI_CERT<sup>9+</sup> | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).| 427| WIFI_SEC_TYPE_WAPI_PSK<sup>9+</sup> | 9 | WAPI-PSK.| 428 429 430## WifiBandType<sup>10+</sup> 431 432Enumerates the Wi-Fi band types. 433 434**System capability**: SystemCapability.Communication.WiFi.STA 435 436| **Name**| **Value**| **Description**| 437| -------- | -------- | -------- | 438| WIFI_BAND_NONE | 0 | Invalid band type| 439| WIFI_BAND_2G | 1 | 2.4 GHz| 440| WIFI_BAND_5G | 2 | 5 GHz| 441| WIFI_BAND_6G | 3 | 6 GHz| 442| WIFI_BAND_60G | 4 | 60 GHz| 443 444## WifiStandard<sup>10+</sup> 445 446Enumerates the Wi-Fi standards. 447 448**System capability**: SystemCapability.Communication.WiFi.STA 449 450| **Name**| **Value**| **Description**| 451| -------- | -------- | -------- | 452| WIFI_STANDARD_UNDEFINED | 0 | Invalid Wi-Fi standard| 453| WIFI_STANDARD_11A | 1 | 802.11a| 454| WIFI_STANDARD_11B | 2 | 802.11b| 455| WIFI_STANDARD_11G | 3 | 802.11g| 456| WIFI_STANDARD_11N | 4 | 802.11n| 457| WIFI_STANDARD_11AC | 5 | 802.11ac| 458| WIFI_STANDARD_11AX | 6 | 802.11ax| 459| WIFI_STANDARD_11AD | 7 | 802.11ad| 460 461## WifiInfoElem<sup>9+</sup> 462 463Represents a WLAN information element. 464 465**System capability**: SystemCapability.Communication.WiFi.STA 466 467 468| **Name**| **Type**| **Readable**| **Writable**| **Description**| 469| -------- | -------- | -------- | -------- | -------- | 470| eid | number | Yes| No| ID of the information element.| 471| content | Uint8Array | Yes| No| Content of the information element.| 472 473 474## WifiChannelWidth<sup>9+</sup> 475 476Enumerates the WLAN channel widths. 477 478**System capability**: SystemCapability.Communication.WiFi.STA 479 480 481| **Name**| **Value**| **Description**| 482| -------- | -------- | -------- | 483| WIDTH_20MHZ | 0 | 20 MHz| 484| WIDTH_40MHZ | 1 | 40 MHz| 485| WIDTH_80MHZ | 2 | 80 MHz| 486| WIDTH_160MHZ | 3 | 160 MHz| 487| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>| 488| WIDTH_INVALID | 5 | Invalid value| 489 490## wifiManager.setScanAlwaysAllowed<sup>10+</sup> 491 492setScanAlwaysAllowed(isScanAlwaysAllowed: boolean): void 493 494Sets whether scan is always allowed. 495 496**System API**: This is a system API. 497 498**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 499 500**System capability**: SystemCapability.Communication.WiFi.STA 501 502**Parameters** 503 504| **Name**| **Type**| **Mandatory**| **Description**| 505| -------- | -------- | -------- | -------- | 506| isScanAlwaysAllowed | boolean | Yes| Whether scan is always allowed.| 507 508**Error codes** 509 510For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 511 512| **ID**| **Error Message**| 513| -------- | -------- | 514| 2501000 | Operation failed.| 515 516```ts 517 import wifiManager from '@ohos.wifiManager'; 518 519 try { 520 let isScanAlwaysAllowed = true; 521 wifiManager.setScanAlwaysAllowed(isScanAlwaysAllowed); 522 }catch(error){ 523 console.error("failed:" + JSON.stringify(error)); 524 } 525``` 526 527## wifiManager.getScanAlwaysAllowed<sup>10+</sup> 528 529getScanAlwaysAllowed(): boolean 530 531Obtains whether scan is always allowed. 532 533**System API**: This is a system API. 534 535**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 536 537**System capability**: SystemCapability.Communication.WiFi.STA 538 539**Return value** 540 541| **Type**| **Description**| 542| -------- | -------- | 543| boolean| Whether scan is always allowed. The value **true** means scan is allowed; the value **false** means the opposite.| 544 545**Error codes** 546 547For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 548 549| **ID**| **Error Message**| 550| -------- | -------- | 551| 2501000 | Operation failed.| 552 553**Example** 554 555```ts 556 import wifiManager from '@ohos.wifiManager'; 557 558 try { 559 let isScanAlwaysAllowed = wifiManager.getScanAlwaysAllowed(); 560 console.info("isScanAlwaysAllowed:" + isScanAlwaysAllowed); 561 }catch(error){ 562 console.error("failed:" + JSON.stringify(error)); 563 } 564``` 565 566## wifiManager.addDeviceConfig<sup>9+</sup> 567 568addDeviceConfig(config: WifiDeviceConfig): Promise<number> 569 570Adds network configuration. This API uses a promise to return the result. 571 572**System API**: This is a system API. 573 574**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 575 576**System capability**: SystemCapability.Communication.WiFi.STA 577 578**Parameters** 579 580| **Name**| **Type**| **Mandatory**| **Description**| 581| -------- | -------- | -------- | -------- | 582| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 583 584**Return value** 585 586| **Type**| **Description**| 587| -------- | -------- | 588| Promise<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.| 589 590**Error codes** 591 592For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 593 594| **ID**| **Error Message**| 595| -------- | -------- | 596| 2501000 | Operation failed.| 597 598**Example** 599 600```ts 601 import wifiManager from '@ohos.wifiManager'; 602 603 try { 604 let config:wifiManager.WifiDeviceConfig = { 605 ssid : "****", 606 preSharedKey : "****", 607 securityType : 0 608 } 609 wifiManager.addDeviceConfig(config).then(result => { 610 console.info("result:" + JSON.stringify(result)); 611 }); 612 }catch(error){ 613 console.error("failed:" + JSON.stringify(error)); 614 } 615``` 616 617## WifiDeviceConfig<sup>9+</sup> 618 619Represents the WLAN configuration. 620 621**System capability**: SystemCapability.Communication.WiFi.STA 622 623 624| **Name**| **Type**| **Readable**| **Writable**| **Description**| 625| -------- | -------- | -------- | -------- | -------- | 626| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| 627| bssid | string | Yes| No| BSSID of the hotspot.| 628| bssidType<sup>10+</sup> | DeviceAddressType | Yes| No| BSSID type of the hotspot.| 629| preSharedKey | string | Yes| No| PSK of the hotspot.| 630| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.| 631| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| 632| creatorUid | number | Yes| No| ID of the creator.<br>**System API**: This is a system API.| 633| disableReason | number | Yes| No| Reason for disabling WLAN.<br>**System API**: This is a system API.| 634| netId | number | Yes| No| Network ID.<br>**System API**: This is a system API.| 635| randomMacType | number | Yes| No| Type of the MAC address. <br>The value **0** indicates random MAC address, and **1** indicates device MAC address.<br>**System API**: This is a system API.| 636| randomMacAddr | string | Yes| No| MAC address.<br>**System API**: This is a system API.| 637| ipType | [IpType](#iptype9) | Yes| No| IP address type.<br>**System API**: This is a system API.| 638| staticIp | [IpConfig](#ipconfig9) | Yes| No| Static IP address information.<br>**System API**: This is a system API.| 639| eapConfig<sup>10+</sup> | [WifiEapConfig](#wifieapconfig10) | Yes| No| EAP configuration.| 640| proxyConfig<sup>10+</sup> | WifiProxyConfig | Yes| No| Proxy configuration.<br>**System API**: This is a system API.| 641 642## IpType<sup>9+</sup> 643 644Enumerates the IP address types. 645 646**System API**: This is a system API. 647 648**System capability**: SystemCapability.Communication.WiFi.STA 649 650 651| Name| Value| Description| 652| -------- | -------- | -------- | 653| STATIC | 0 | Static IP address.| 654| DHCP | 1 | IP address allocated by DHCP.| 655| UNKNOWN | 2 | Not specified.| 656 657 658## IpConfig<sup>9+</sup> 659 660Represents IP configuration information. 661 662**System API**: This is a system API. 663 664**System capability**: SystemCapability.Communication.WiFi.STA 665 666| **Name**| **Type**| **Readable**| **Writable**| **Description**| 667| -------- | -------- | -------- | -------- | -------- | 668| ipAddress | number | Yes| No| IP address.| 669| gateway | number | Yes| No| Gateway.| 670| prefixLength | number | Yes| No| Subnet mask.| 671| dnsServers | number[] | Yes| No| Domain name server (DNS) information.| 672| domains | Array<string> | Yes| No| Domain information.| 673 674 675## WifiEapConfig<sup>10+</sup> 676 677Represents EAP configuration information. 678 679**System capability**: SystemCapability.Communication.WiFi.STA 680 681| **Name**| **Type**| **Readable**| **Writable**| **Description**| 682| -------- | -------- | -------- | -------- | -------- | 683| eapMethod | [EapMethod](#eapmethod10) | Yes| No| EAP authentication method.| 684| phase2Method | [Phase2Method](#phase2method10) | Yes| No| Phase 2 authentication method.| 685| identity | string | Yes| No| Identity Information.| 686| anonymousIdentity | string | Yes| No| Anonymous identity.| 687| password | string | Yes| No| Password.| 688| caCertAlias | string | Yes| No| CA certificate alias.| 689| caPath | string | Yes| No| CA certificate path.| 690| clientCertAlias | string | Yes| No| Client certificate alias.| 691| certEntry | Uint8Array | Yes| Yes| CA certificate content.| 692| certPassword | string | Yes| Yes| CA certificate password.| 693| altSubjectMatch | string | Yes| No| A string to match the alternate subject.| 694| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.| 695| realm | string | Yes| No| Realm for the passpoint credential.| 696| plmn | string | Yes| No| Public land mobile network (PLMN) of the passpoint credential provider.| 697| eapSubId | number | Yes| No| Sub-ID of the SIM card.| 698 699 700## EapMethod<sup>10+</sup> 701 702Enumerates the EAP authentication methods. 703 704**System capability**: SystemCapability.Communication.WiFi.STA 705 706| Name| Value| Description| 707| -------- | -------- | -------- | 708| EAP_NONE | 0 | Not specified.| 709| EAP_PEAP | 1 | PEAP.| 710| EAP_TLS | 2 | TLS.| 711| EAP_TTLS | 3 | TTLS.| 712| EAP_PWD | 4 | Password.| 713| EAP_SIM | 5 | SIM.| 714| EAP_AKA | 6 | AKA.| 715| EAP_AKA_PRIME | 7 | AKA Prime.| 716| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.| 717 718 719## Phase2Method<sup>10+</sup> 720 721Enumerates the Phase 2 authentication methods. 722 723**System capability**: SystemCapability.Communication.WiFi.STA 724 725| Name| Value| Description| 726| -------- | -------- | -------- | 727| PHASE2_NONE | 0 | Not specified.| 728| PHASE2_PAP | 1 | PAP.| 729| PHASE2_MSCHAP | 2 | MS-CHAP.| 730| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.| 731| PHASE2_GTC | 4 | GTC .| 732| PHASE2_SIM | 5 | SIM.| 733| PHASE2_AKA | 6 | AKA.| 734| PHASE2_AKA_PRIME | 7 | AKA Prime.| 735 736 737## WifiProxyConfig <sup>10+</sup> 738 739Represents the Wi-Fi proxy configuration. 740 741**System API**: This is a system API. 742 743**System capability**: SystemCapability.Communication.WiFi.STA 744 745| **Name**| **Type**| **Readable**| **Writable**| **Description**| 746| -------- | -------- | -------- | -------- | -------- | 747| proxyMethod | ProxyMethod | Yes| No| Proxy method.| 748| pacWebAddress | string | Yes| No| PAC web address of the proxy automatically configured.| 749| serverHostName | string | Yes| No| Server host name of the proxy manually configured.| 750| serverPort | string | Yes| No| Server port of the proxy manually configured.| 751| exclusionObjects | string | Yes| No| Excluded objects of the manually configured proxy. Multiple objects are separated by commas (,).| 752 753## ProxyMethod<sup>10+</sup> 754 755Enumerates the Wi-Fi proxy methods. 756 757**System API**: This is a system API. 758 759**System capability**: SystemCapability.Communication.WiFi.STA 760 761| Name| Value| Description| 762| -------- | -------- | -------- | 763| METHOD_NONE | 0 | No proxy.| 764| METHOD_AUTO | 1 | Use an automatically configured proxy.| 765| METHOD_MANUAL | 2 | Use a manually configured proxy.| 766 767## wifiManager.addDeviceConfig<sup>9+</sup> 768 769addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 770 771Adds network configuration. This API uses an asynchronous callback to return the result. 772 773**System API**: This is a system API. 774 775**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 776 777**System capability**: SystemCapability.Communication.WiFi.STA 778 779**Parameters** 780 781| **Name**| **Type**| **Mandatory**| **Description**| 782| -------- | -------- | -------- | -------- | 783| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 784| callback | AsyncCallback<number> | Yes| Callback invoked 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.| 785 786**Error codes** 787 788For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 789 790| **ID**| **Error Message**| 791| -------- | -------- | 792| 2501000 | Operation failed.| 793 794**Example** 795 796```ts 797 import wifiManager from '@ohos.wifiManager'; 798 799 try { 800 let config:wifiManager.WifiDeviceConfig = { 801 ssid : "****", 802 preSharedKey : "****", 803 securityType : 0 804 } 805 wifiManager.addDeviceConfig(config,(error,result) => { 806 console.info("result:" + JSON.stringify(result)); 807 }); 808 }catch(error){ 809 console.error("failed:" + JSON.stringify(error)); 810 } 811``` 812 813## wifiManager.addCandidateConfig<sup>9+</sup> 814 815addCandidateConfig(config: WifiDeviceConfig): Promise<number> 816 817Adds the configuration of a candidate network. This API uses a promise to return the result. 818 819**Required permissions**: ohos.permission.SET_WIFI_INFO 820 821**System capability**: SystemCapability.Communication.WiFi.STA 822 823**Parameters** 824 825| **Name**| **Type**| **Mandatory**| **Description**| 826| -------- | -------- | -------- | -------- | 827| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 828 829**Return value** 830 831| **Type**| **Description**| 832| -------- | -------- | 833| Promise<number> | Promise used to return the network configuration ID.| 834 835**Error codes** 836 837For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 838 839| **ID**| **Error Message**| 840| -------- | -------- | 841| 2501000 | Operation failed.| 842 843**Example** 844`````ts 845 import wifiManager from '@ohos.wifiManager'; 846 847 try { 848 let config:wifiManager.WifiDeviceConfig = { 849 ssid : "****", 850 preSharedKey : "****", 851 securityType : 0 852 } 853 wifiManager.addCandidateConfig(config).then(result => { 854 console.info("result:" + JSON.stringify(result)); 855 }); 856 }catch(error){ 857 console.error("failed:" + JSON.stringify(error)); 858 } 859````` 860 861## wifiManager.addCandidateConfig<sup>9+</sup> 862 863addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 864 865Adds the configuration of a candidate network. This API uses an asynchronous callback to return the result. 866 867**Required permissions**: ohos.permission.SET_WIFI_INFO 868 869**System capability**: SystemCapability.Communication.WiFi.STA 870 871**Parameters** 872 873| **Name**| **Type**| **Mandatory**| **Description**| 874| -------- | -------- | -------- | -------- | 875| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 876| callback | AsyncCallback<number> | Yes| Callback invoked 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.| 877 878**Error codes** 879 880For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 881 882| **ID**| **Error Message**| 883| -------- | -------- | 884| 2501000 | Operation failed.| 885 886**Example** 887`````ts 888 import wifiManager from '@ohos.wifiManager'; 889 890 try { 891 let config:wifiManager.WifiDeviceConfig = { 892 ssid : "****", 893 preSharedKey : "****", 894 securityType : 0 895 } 896 wifiManager.addCandidateConfig(config,(error,result) => { 897 console.info("result:" + JSON.stringify(result)); 898 }); 899 }catch(error){ 900 console.error("failed:" + JSON.stringify(error)); 901 } 902````` 903 904## wifiManager.removeCandidateConfig<sup>9+</sup> 905 906removeCandidateConfig(networkId: number): Promise<void> 907 908Removes the configuration of a candidate network. This API uses a promise to return the result. 909 910**Required permissions**: ohos.permission.SET_WIFI_INFO 911 912**System capability**: SystemCapability.Communication.WiFi.STA 913 914**Parameters** 915 916| **Name**| **Type**| **Mandatory**| **Description**| 917| -------- | -------- | -------- | -------- | 918| networkId | number | Yes| ID of the network configuration to remove.| 919 920**Return value** 921 922| **Type**| **Description**| 923| -------- | -------- | 924| Promise<void> | Promise used to return the result.| 925 926**Error codes** 927 928For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 929 930| **ID**| **Error Message**| 931| -------- | -------- | 932| 2501000 | Operation failed.| 933 934**Example** 935 936```ts 937 import wifiManager from '@ohos.wifiManager'; 938 939 try { 940 let networkId = 0; 941 wifiManager.removeCandidateConfig(networkId).then(result => { 942 console.info("result:" + JSON.stringify(result)); 943 }); 944 }catch(error){ 945 console.error("failed:" + JSON.stringify(error)); 946 } 947``` 948 949## wifiManager.removeCandidateConfig<sup>9+</sup> 950 951removeCandidateConfig(networkId: number, callback: AsyncCallback<void>): void 952 953Removes the configuration of a candidate network. This API uses an asynchronous callback to return the result. 954 955**Required permissions**: ohos.permission.SET_WIFI_INFO 956 957**System capability**: SystemCapability.Communication.WiFi.STA 958 959**Parameters** 960 961| **Name**| **Type**| **Mandatory**| **Description**| 962| -------- | -------- | -------- | -------- | 963| networkId | number | Yes| ID of the network configuration to remove.| 964| callback | AsyncCallback<void> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0**. If **err** is not **0**, an error has occurred.| 965 966**Error codes** 967 968For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 969 970| **ID**| **Error Message**| 971| -------- | -------- | 972| 2501000 | Operation failed.| 973 974**Example** 975```ts 976 import wifiManager from '@ohos.wifiManager'; 977 978 try { 979 let networkId = 0; 980 wifiManager.removeCandidateConfig(networkId,(error,result) => { 981 console.info("result:" + JSON.stringify(result)); 982 }); 983 }catch(error){ 984 console.error("failed:" + JSON.stringify(error)); 985 } 986``` 987 988## wifiManager.getCandidateConfigs<sup>9+</sup> 989 990getCandidateConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig)> 991 992Obtains candidate network configuration. 993 994**Required permissions**: 995 996API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 997 998API version 10 and later : ohos.permission.GET_WIFI_INFO 999 1000**System capability**: SystemCapability.Communication.WiFi.STA 1001 1002**Return value** 1003 1004| **Type**| **Description**| 1005| -------- | -------- | 1006| Array<[WifiDeviceConfig](#wifideviceconfig)> | Candidate network configuration obtained.| 1007 1008**Error codes** 1009 1010For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1011 1012| **ID**| **Error Message**| 1013| -------- | -------- | 1014| 2501000 | Operation failed.| 1015 1016**Example** 1017 1018`````ts 1019 import wifiManager from '@ohos.wifiManager'; 1020 1021 try { 1022 let configs = wifiManager.getCandidateConfigs(); 1023 console.info("configs:" + JSON.stringify(configs)); 1024 let len = configs.length; 1025 console.log("result len: " + len); 1026 if(len > 0){ 1027 for (let i = 0; i < len; ++i) { 1028 console.info("ssid: " + configs[i].ssid); 1029 console.info("bssid: " + configs[i].bssid); 1030 } 1031 } 1032 }catch(error){ 1033 console.error("failed:" + JSON.stringify(error)); 1034 } 1035 1036````` 1037 1038## wifiManager.connectToCandidateConfig<sup>9+</sup> 1039 1040connectToCandidateConfig(networkId: number): void 1041 1042Connects to a candidate network added by the application. If the device is already connected to a hotspot, disconnect it from the hotspot first. 1043 1044**Required permissions**: ohos.permission.SET_WIFI_INFO 1045 1046**System capability**: SystemCapability.Communication.WiFi.STA 1047 1048**Parameters** 1049 1050| **Name**| **Type**| **Mandatory**| **Description**| 1051| -------- | -------- | -------- | -------- | 1052| networkId | number | Yes| ID of the candidate network configuration.| 1053 1054**Error codes** 1055 1056For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1057 1058| **ID**| **Error Message**| 1059| -------- | -------- | 1060| 2501000 | Operation failed.| 1061| 2501001 | Wifi is closed.| 1062 1063**Example** 1064```ts 1065 import wifiManager from '@ohos.wifiManager'; 1066 1067 try { 1068 let networkId = 0; 1069 let ret = wifiManager.connectToCandidateConfig(networkId); 1070 console.info("result:" + ret); 1071 }catch(error){ 1072 console.error("failed:" + JSON.stringify(error)); 1073 } 1074 1075``` 1076 1077## wifiManager.connectToNetwork<sup>9+</sup> 1078 1079connectToNetwork(networkId: number): void 1080 1081Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first. 1082 1083**System API**: This is a system API. 1084 1085**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1086 1087**System capability**: SystemCapability.Communication.WiFi.STA 1088 1089**Parameters** 1090 1091| **Name**| **Type**| **Mandatory**| **Description**| 1092| -------- | -------- | -------- | -------- | 1093| networkId | number | Yes| Network configuration ID.| 1094 1095**Error codes** 1096 1097For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1098 1099| **ID**| **Error Message**| 1100| -------- | -------- | 1101| 2501000 | Operation failed.| 1102| 2501001 | Wifi is closed.| 1103 1104**Example** 1105 1106```ts 1107 import wifiManager from '@ohos.wifiManager'; 1108 1109 try { 1110 let networkId = 0; 1111 wifiManager.connectToNetwork(networkId); 1112 }catch(error){ 1113 console.error("failed:" + JSON.stringify(error)); 1114 } 1115``` 1116 1117## wifiManager.connectToDevice<sup>9+</sup> 1118 1119connectToDevice(config: WifiDeviceConfig): void 1120 1121Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first. 1122 1123**System API**: This is a system API. 1124 1125**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1126 1127**System capability**: 1128 SystemCapability.Communication.WiFi.STA 1129 1130**Parameters** 1131 1132| **Name**| **Type**| **Mandatory**| **Description**| 1133| -------- | -------- | -------- | -------- | 1134| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| Configuration of the WLAN to connect. The default **bssidType** is random device address.| 1135 1136**Error codes** 1137 1138For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1139 1140| **ID**| **Error Message**| 1141| -------- | -------- | 1142| 2501000 | Operation failed.| 1143| 2501001 | Wifi is closed.| 1144 1145**Example** 1146```ts 1147 import wifiManager from '@ohos.wifiManager'; 1148 1149 try { 1150 let config:wifiManager.WifiDeviceConfig = { 1151 ssid : "****", 1152 preSharedKey : "****", 1153 securityType : 3 1154 } 1155 wifiManager.connectToDevice(config); 1156 1157 }catch(error){ 1158 console.error("failed:" + JSON.stringify(error)); 1159 } 1160``` 1161 1162## wifiManager.disconnect<sup>9+</sup> 1163 1164disconnect(): void 1165 1166Disconnects the network. 1167 1168**System API**: This is a system API. 1169 1170**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1171 1172**System capability**: 1173 SystemCapability.Communication.WiFi.STA 1174 1175**Error codes** 1176 1177For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1178 1179| **ID**| **Error Message**| 1180| -------- | -------- | 1181| 2501000 | Operation failed.| 1182 1183**Example** 1184```ts 1185 import wifiManager from '@ohos.wifiManager'; 1186 1187 try { 1188 wifiManager.disconnect(); 1189 }catch(error){ 1190 console.error("failed:" + JSON.stringify(error)); 1191 } 1192``` 1193 1194## wifiManager.getSignalLevel<sup>9+</sup> 1195 1196getSignalLevel(rssi: number, band: number): number 1197 1198Obtains the WLAN signal level. 1199 1200**Required permissions**: ohos.permission.GET_WIFI_INFO 1201 1202**System capability**: SystemCapability.Communication.WiFi.STA 1203 1204**Parameters** 1205 1206| **Name**| **Type**| **Mandatory**| **Description**| 1207| -------- | -------- | -------- | -------- | 1208| rssi | number | Yes| RSSI of the hotspot, in dBm.| 1209| band | number | Yes| Frequency band of the WLAN AP.| 1210 1211**Return value** 1212 1213| **Type**| **Description**| 1214| -------- | -------- | 1215| number | Signal level obtained. The value range is [0, 4].| 1216 1217**Error codes** 1218 1219For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1220 1221| **ID**| **Error Message**| 1222| -------- | -------- | 1223| 2501000 | Operation failed.| 1224 1225**Example** 1226```ts 1227 import wifiManager from '@ohos.wifiManager'; 1228 1229 try { 1230 let rssi = 0; 1231 let band = 0; 1232 let level = wifiManager.getSignalLevel(rssi,band); 1233 console.info("level:" + JSON.stringify(level)); 1234 }catch(error){ 1235 console.error("failed:" + JSON.stringify(error)); 1236 } 1237 1238``` 1239 1240## wifiManager.getLinkedInfo<sup>9+</sup> 1241 1242getLinkedInfo(): Promise<WifiLinkedInfo> 1243 1244Obtains WLAN connection information. This API uses a promise to return the result. 1245 1246**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_LOCAL_MAC (if **macAddress** needs to be obtained; otherwise, **macAddress** is an empty string.) 1247 1248**System capability**: SystemCapability.Communication.WiFi.STA 1249 1250**Return value** 1251 1252| Type| Description| 1253| -------- | -------- | 1254| Promise<[WifiLinkedInfo](#wifilinkedinfo)> | Promise used to return the WLAN connection information obtained.| 1255 1256**Error codes** 1257 1258For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1259 1260| **ID**| **Error Message**| 1261| -------- | -------- | 1262| 2501000 | Operation failed.| 1263| 2501001 | Wifi is closed.| 1264 1265## wifiManager.getLinkedInfo<sup>9+</sup> 1266 1267getLinkedInfo(callback: AsyncCallback<WifiLinkedInfo>): void 1268 1269Obtains WLAN connection information. This API uses an asynchronous callback to return the result. 1270 1271**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_LOCAL_MAC (if **macAddress** needs to be obtained; otherwise, **macAddress** is an empty string.) 1272 1273**System capability**: SystemCapability.Communication.WiFi.STA 1274 1275**Parameters** 1276 1277| Name| Type| Mandatory| Description| 1278| -------- | -------- | -------- | -------- | 1279| callback | AsyncCallback<[WifiLinkedInfo](#wifilinkedinfo)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.| 1280 1281**Error codes** 1282 1283For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1284 1285| **ID**| **Error Message**| 1286| -------- | -------- | 1287| 2501000 | Operation failed.| 1288| 2501001 | Wifi is closed.| 1289 1290**Example** 1291```ts 1292 import wifiManager from '@ohos.wifiManager'; 1293 1294 wifiManager.getLinkedInfo((err, data) => { 1295 if (err) { 1296 console.error("get linked info error"); 1297 return; 1298 } 1299 console.info("get wifi linked info: " + JSON.stringify(data)); 1300 }); 1301 1302 wifiManager.getLinkedInfo().then(data => { 1303 console.info("get wifi linked info: " + JSON.stringify(data)); 1304 }).catch((error:number) => { 1305 console.info("get linked info error"); 1306 }); 1307``` 1308 1309 1310## WifiLinkedInfo<sup>9+</sup> 1311 1312Represents the WLAN connection information. 1313 1314**System capability**: SystemCapability.Communication.WiFi.STA 1315 1316| Name| Type| Readable| Writable| Description| 1317| -------- | -------- | -------- | -------- | -------- | 1318| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| 1319| bssid | string | Yes| No| BSSID of the hotspot.| 1320| networkId | number | Yes| No| Network configuration ID.<br>**System API**: This is a system API.| 1321| rssi | number | Yes| No| RSSI of the hotspot, in dBm.| 1322| band | number | Yes| No| Band of the WLAN AP.| 1323| linkSpeed | number | Yes| No| Uplink speed of the WLAN AP.| 1324| rxLinkSpeed<sup>10+</sup> | number | Yes| No| Downlink speed of the WLAN AP.| 1325| maxSupportedTxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.| 1326| maxSupportedRxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.| 1327| frequency | number | Yes| No| Frequency of the WLAN AP.| 1328| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.| 1329| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.| 1330| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br>**System API**: This is a system API.| 1331| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br>**System API**: This is a system API.| 1332| macType | number | Yes| No| MAC address type. <br>The value **0** indicates random MAC address, and **1** indicates device MAC address.| 1333| macAddress | string | Yes| No| MAC address of the device.| 1334| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.| 1335| suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br>**System API**: This is a system API.| 1336| connState | [ConnState](#connstate) | Yes| No| WLAN connection state.| 1337| channelWidth<sup>10+</sup> | [WifiChannelWidth](#wifichannelwidth) | Yes| No| Channel bandwidth of the connected hotspot.| 1338| wifiStandard<sup>10+</sup> | [WifiStandard](#wifistandard) | Yes| No| Wi-Fi standard used by the connected hotspot.| 1339 1340## ConnState<sup>9+</sup> 1341 1342Enumerates the WLAN connection states. 1343 1344**System capability**: SystemCapability.Communication.WiFi.STA 1345 1346| Name| Value| Description| 1347| -------- | -------- | -------- | 1348| SCANNING | 0 | The device is scanning for available APs.| 1349| CONNECTING | 1 | A WLAN connection is being established.| 1350| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.| 1351| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.| 1352| CONNECTED | 4 | A WLAN connection is established.| 1353| DISCONNECTING | 5 | The WLAN connection is being disconnected.| 1354| DISCONNECTED | 6 | The WLAN connection is disconnected.| 1355| UNKNOWN | 7 | Failed to set up the WLAN connection.| 1356 1357 1358## SuppState<sup>9+</sup> 1359 1360Enumerates the supplicant states. 1361 1362**System API**: This is a system API. 1363 1364**System capability**: SystemCapability.Communication.WiFi.STA 1365 1366| Name| Value| Description| 1367| -------- | -------- | -------- | 1368| DISCONNECTED | 0 | The supplicant is disconnected from the AP.| 1369| INTERFACE_DISABLED | 1 | The network interface is disabled.| 1370| INACTIVE | 2 | The supplicant is inactive.| 1371| SCANNING | 3 | The supplicant is scanning for a WLAN connection.| 1372| AUTHENTICATING | 4 | The supplicant is being authenticated.| 1373| ASSOCIATING | 5 | The supplicant is being associated with an AP.| 1374| ASSOCIATED | 6 | The supplicant is associated with an AP.| 1375| FOUR_WAY_HANDSHAKE | 7 | A four-way handshake is being performed for the supplicant.| 1376| GROUP_HANDSHAKE | 8 | A group handshake is being performed for the supplicant.| 1377| COMPLETED | 9 | The authentication is complete.| 1378| UNINITIALIZED | 10 | The supplicant failed to set up the connection.| 1379| INVALID | 11 | Invalid value.| 1380 1381## wifiManager.isConnected<sup>9+</sup> 1382 1383isConnected(): boolean 1384 1385Checks whether the WLAN is connected. 1386 1387**Required permissions**: ohos.permission.GET_WIFI_INFO 1388 1389**System capability**: SystemCapability.Communication.WiFi.STA 1390 1391**Return value** 1392 1393| **Type**| **Description**| 1394| -------- | -------- | 1395| boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| 1396 1397**Error codes** 1398 1399For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1400 1401| **ID**| **Error Message**| 1402| -------- | -------- | 1403| 2501000 | Operation failed.| 1404 1405**Example** 1406```ts 1407 import wifiManager from '@ohos.wifiManager'; 1408 1409 try { 1410 let ret = wifiManager.isConnected(); 1411 console.info("isConnected:" + ret); 1412 }catch(error){ 1413 console.error("failed:" + JSON.stringify(error)); 1414 } 1415 1416``` 1417 1418## wifiManager.getSupportedFeatures<sup>9+</sup> 1419 1420getSupportedFeatures(): number 1421 1422Obtains the features supported by this device. 1423 1424**System API**: This is a system API. 1425 1426**Required permissions**: ohos.permission.GET_WIFI_INFO 1427 1428**System capability**: SystemCapability.Communication.WiFi.Core 1429 1430**Return value** 1431 1432| **Type**| **Description**| 1433| -------- | -------- | 1434| number | Feature value. | 1435 1436**Feature IDs** 1437 1438| Value| Description| 1439| -------- | -------- | 1440| 0x0001 | WLAN infrastructure mode| 1441| 0x0002 | 5 GHz feature| 1442| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature| 1443| 0x0008 | Wi-Fi Direct| 1444| 0x0010 | SoftAP| 1445| 0x0040 | Wi-Fi Aware| 1446| 0x8000 | WLAN AP/STA concurrency| 1447| 0x8000000 | WPA3 Personal (WPA-3 SAE)| 1448| 0x10000000 | WPA3-Enterprise Suite B | 1449| 0x20000000 | Enhanced open feature| 1450 1451**Error codes** 1452 1453For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1454 1455| **ID**| **Error Message**| 1456| -------- | -------- | 1457| 2401000 | Operation failed.| 1458 1459**Example** 1460```ts 1461 import wifiManager from '@ohos.wifiManager'; 1462 1463 try { 1464 let ret = wifiManager.getSupportedFeatures(); 1465 console.info("supportedFeatures:" + ret); 1466 }catch(error){ 1467 console.error("failed:" + JSON.stringify(error)); 1468 } 1469 1470``` 1471 1472## wifiManager.isFeatureSupported<sup>9+</sup> 1473 1474isFeatureSupported(featureId: number): boolean 1475 1476Checks whether the device supports the specified WLAN feature. 1477 1478**Required permissions**: ohos.permission.GET_WIFI_INFO 1479 1480**System capability**: SystemCapability.Communication.WiFi.Core 1481 1482**Parameters** 1483 1484 1485| **Name**| **Type**| Mandatory| **Description**| 1486| -------- | -------- | -------- | -------- | 1487| featureId | number | Yes| Feature ID.| 1488 1489**Return value** 1490 1491| **Type**| **Description**| 1492| -------- | -------- | 1493| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1494 1495**Error codes** 1496 1497For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1498 1499| **ID**| **Error Message**| 1500| -------- | -------- | 1501| 2401000 | Operation failed.| 1502 1503**Example** 1504```ts 1505 import wifiManager from '@ohos.wifiManager'; 1506 1507 try { 1508 let featureId = 0; 1509 let ret = wifiManager.isFeatureSupported(featureId); 1510 console.info("isFeatureSupported:" + ret); 1511 }catch(error){ 1512 console.error("failed:" + JSON.stringify(error)); 1513 } 1514 1515``` 1516 1517## wifiManager.getDeviceMacAddress<sup>9+</sup> 1518 1519getDeviceMacAddress(): string[] 1520 1521Obtains the device MAC address. 1522 1523**System API**: This is a system API. 1524 1525**Required permissions**: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications) 1526 1527**System capability**: SystemCapability.Communication.WiFi.STA 1528 1529**Return value** 1530 1531| **Type**| **Description**| 1532| -------- | -------- | 1533| string[] | MAC address obtained.| 1534 1535**Error codes** 1536 1537For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1538 1539| **ID**| **Error Message**| 1540| -------- | -------- | 1541| 2501000 | Operation failed.| 1542| 2501001 | wifi is closed.| 1543 1544**Example** 1545```ts 1546 import wifiManager from '@ohos.wifiManager'; 1547 1548 try { 1549 let ret = wifiManager.getDeviceMacAddress(); 1550 console.info("deviceMacAddress:" + JSON.stringify(ret)); 1551 }catch(error){ 1552 console.error("failed:" + JSON.stringify(error)); 1553 } 1554 1555``` 1556 1557## wifiManager.getIpInfo<sup>9+</sup> 1558 1559getIpInfo(): IpInfo 1560 1561Obtains IP information. 1562 1563**Required permissions**: ohos.permission.GET_WIFI_INFO 1564 1565**System capability**: SystemCapability.Communication.WiFi.STA 1566 1567**Return value** 1568 1569| **Type**| **Description**| 1570| -------- | -------- | 1571| [IpInfo](#ipinfo9) | IP information obtained.| 1572 1573**Error codes** 1574 1575For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1576 1577| **ID**| **Error Message**| 1578| -------- | -------- | 1579| 2501000 | Operation failed.| 1580 1581**Example** 1582```ts 1583 import wifiManager from '@ohos.wifiManager'; 1584 1585 try { 1586 let info = wifiManager.getIpInfo(); 1587 console.info("info:" + JSON.stringify(info)); 1588 }catch(error){ 1589 console.error("failed:" + JSON.stringify(error)); 1590 } 1591``` 1592 1593## IpInfo<sup>9+</sup> 1594 1595Represents IP information. 1596 1597**System capability**: SystemCapability.Communication.WiFi.STA 1598 1599| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1600| -------- | -------- | -------- | -------- | -------- | 1601| ipAddress | number | Yes| No| IP address.| 1602| gateway | number | Yes| No| Gateway.| 1603| netmask | number | Yes| No| Subnet mask.| 1604| primaryDns | number | Yes| No| IP address of the preferred DNS server.| 1605| secondDns | number | Yes| No| IP address of the alternate DNS server.| 1606| serverIp | number | Yes| No| IP address of the DHCP server.| 1607| leaseDuration | number | Yes| No| Lease duration of the IP address.| 1608 1609 1610## wifiManager.getIpv6Info<sup>10+</sup> 1611 1612getIpv6Info(): Ipv6Info 1613 1614Obtains IP information. 1615 1616**Required permissions**: ohos.permission.GET_WIFI_INFO 1617 1618**System capability**: SystemCapability.Communication.WiFi.STA 1619 1620**Return value** 1621 1622| **Type**| **Description**| 1623| -------- | -------- | 1624| Ipv6Info | IPv6 information obtained.| 1625 1626**Error codes** 1627 1628For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1629 1630| **ID**| **Error Message**| 1631| -------- | -------- | 1632| 2501000 | Operation failed.| 1633 1634**Example** 1635```ts 1636 import wifiManager from '@ohos.wifiManager'; 1637 1638 try { 1639 let info = wifiManager.getIpv6Info(); 1640 console.info("info:" + JSON.stringify(info)); 1641 }catch(error){ 1642 console.error("failed:" + JSON.stringify(error)); 1643 } 1644``` 1645## Ipv6Info <sup>10+</sup> 1646 1647Represents the IPv6 information. 1648 1649**System capability**: SystemCapability.Communication.WiFi.STA 1650 1651| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1652| -------- | -------- | -------- | -------- | -------- | 1653| linkIpv6Address | string | Yes| No| IPv6 address of the link.| 1654| globalIpv6Address | string | Yes| No| Global IPv6 address.| 1655| randomGlobalIpv6Address | number | Yes| No| Random global IPv6 address.| 1656| gateway | string | Yes| No| Gateway IP address.| 1657| netmask | string | Yes| No| Subnet mask.| 1658| primaryDNS | string | Yes| No| IPv6 address of the preferred DNS server.| 1659| secondDNS | string | Yes| No| IPv6 address of the alternate DNS server.| 1660 1661 1662## wifiManager.getCountryCode<sup>9+</sup> 1663 1664getCountryCode(): string 1665 1666Obtains the country code. 1667 1668**Required permissions**: ohos.permission.GET_WIFI_INFO 1669 1670**System capability**: SystemCapability.Communication.WiFi.Core 1671 1672**Return value** 1673 1674| **Type**| **Description**| 1675| -------- | -------- | 1676| string | Country code obtained.| 1677 1678**Error codes** 1679 1680For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1681 1682| **ID**| **Error Message**| 1683| -------- | -------- | 1684| 2401000 | Operation failed.| 1685 1686**Example** 1687```ts 1688 import wifiManager from '@ohos.wifiManager'; 1689 1690 try { 1691 let code = wifiManager.getCountryCode(); 1692 console.info("code:" + code); 1693 }catch(error){ 1694 console.error("failed:" + JSON.stringify(error)); 1695 } 1696``` 1697 1698## wifiManager.reassociate<sup>9+</sup> 1699 1700reassociate(): void 1701 1702Re-associates with the network. 1703 1704**System API**: This is a system API. 1705 1706**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1707 1708**System capability**: SystemCapability.Communication.WiFi.STA 1709 1710**Error codes** 1711 1712For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1713 1714| **ID**| **Error Message**| 1715| -------- | -------- | 1716| 2501000 | Operation failed.| 1717| 2501001 | Wifi is closed.| 1718 1719**Example** 1720```ts 1721 import wifiManager from '@ohos.wifiManager'; 1722 1723 try { 1724 wifiManager.reassociate(); 1725 }catch(error){ 1726 console.error("failed:" + JSON.stringify(error)); 1727 } 1728``` 1729 1730## wifiManager.reconnect<sup>9+</sup> 1731 1732reconnect(): void 1733 1734Reconnects to the network. 1735 1736**System API**: This is a system API. 1737 1738**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1739 1740**System capability**: SystemCapability.Communication.WiFi.STA 1741 1742**Error codes** 1743 1744For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1745 1746| **ID**| **Error Message**| 1747| -------- | -------- | 1748| 2501000 | Operation failed.| 1749| 2501001 | Wifi is closed.| 1750 1751**Example** 1752```ts 1753 import wifiManager from '@ohos.wifiManager'; 1754 1755 try { 1756 wifiManager.reconnect(); 1757 }catch(error){ 1758 console.error("failed:" + JSON.stringify(error)); 1759 } 1760``` 1761 1762## wifiManager.getDeviceConfigs<sup>9+</sup> 1763 1764getDeviceConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig)> 1765 1766Obtains network configuration. 1767 1768**System API**: This is a system API. 1769 1770**Required permissions**: 1771 1772API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.GET_WIFI_CONFIG 1773 1774API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1775 1776**System capability**: SystemCapability.Communication.WiFi.STA 1777 1778**Return value** 1779 1780| **Type**| **Description**| 1781| -------- | -------- | 1782| Array<[WifiDeviceConfig](#wifideviceconfig)> | Array of network configuration obtained.| 1783 1784**Error codes** 1785 1786For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1787 1788| **ID**| **Error Message**| 1789| -------- | -------- | 1790| 2501000 | Operation failed.| 1791 1792**Example** 1793```ts 1794 import wifiManager from '@ohos.wifiManager'; 1795 1796 try { 1797 let configs = wifiManager.getDeviceConfigs(); 1798 console.info("configs:" + JSON.stringify(configs)); 1799 }catch(error){ 1800 console.error("failed:" + JSON.stringify(error)); 1801 } 1802``` 1803 1804## wifiManager.updateNetwork<sup>9+</sup> 1805 1806updateNetwork(config: WifiDeviceConfig): number 1807 1808Updates network configuration. 1809 1810**System API**: This is a system API. 1811 1812**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 1813 1814**System capability**: SystemCapability.Communication.WiFi.STA 1815 1816**Parameters** 1817 1818| **Name**| **Type**| **Mandatory**| **Description**| 1819| -------- | -------- | -------- | -------- | 1820| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.| 1821 1822**Return value** 1823 1824| **Type**| **Description**| 1825| -------- | -------- | 1826| number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| 1827 1828**Error codes** 1829 1830For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1831 1832| **ID**| **Error Message**| 1833| -------- | -------- | 1834| 2501000 | Operation failed.| 1835 1836**Example** 1837```ts 1838 import wifiManager from '@ohos.wifiManager'; 1839 1840 try { 1841 let config:wifiManager.WifiDeviceConfig = { 1842 ssid : "****", 1843 preSharedKey : "****", 1844 securityType : 3 1845 } 1846 let ret = wifiManager.updateNetwork(config); 1847 console.info("ret:" + ret); 1848 }catch(error){ 1849 console.error("failed:" + JSON.stringify(error)); 1850 } 1851``` 1852 1853## wifiManager.disableNetwork<sup>9+</sup> 1854 1855disableNetwork(netId: number): void 1856 1857Disables network configuration. 1858 1859**System API**: This is a system API. 1860 1861**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1862 1863**System capability**: SystemCapability.Communication.WiFi.STA 1864 1865**Parameters** 1866 1867| **Name**| **Type**| **Mandatory**| **Description**| 1868| -------- | -------- | -------- | -------- | 1869| netId | number | Yes| ID of the network configuration to disable.| 1870 1871**Error codes** 1872 1873For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1874 1875| **ID**| **Error Message**| 1876| -------- | -------- | 1877| 2501000 | Operation failed.| 1878 1879**Example** 1880```ts 1881 import wifiManager from '@ohos.wifiManager'; 1882 1883 try { 1884 let netId = 0; 1885 wifiManager.disableNetwork(netId); 1886 }catch(error){ 1887 console.error("failed:" + JSON.stringify(error)); 1888 } 1889``` 1890 1891## wifiManager.removeAllNetwork<sup>9+</sup> 1892 1893removeAllNetwork(): void 1894 1895Removes the configuration of all networks. 1896 1897**System API**: This is a system API. 1898 1899**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1900 1901**System capability**: SystemCapability.Communication.WiFi.STA 1902 1903**Error codes** 1904 1905For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1906 1907| **ID**| **Error Message**| 1908| -------- | -------- | 1909| 2501000 | Operation failed.| 1910 1911**Example** 1912```ts 1913 import wifiManager from '@ohos.wifiManager'; 1914 1915 try { 1916 wifiManager.removeAllNetwork(); 1917 }catch(error){ 1918 console.error("failed:" + JSON.stringify(error)); 1919 } 1920``` 1921 1922## wifiManager.removeDevice<sup>9+</sup> 1923 1924removeDevice(id: number): void 1925 1926Removes the specified network configuration. 1927 1928**System API**: This is a system API. 1929 1930**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1931 1932**System capability**: SystemCapability.Communication.WiFi.STA 1933 1934**Parameters** 1935 1936| **Name**| **Type**| **Mandatory**| **Description**| 1937| -------- | -------- | -------- | -------- | 1938| id | number | Yes| ID of the network configuration to remove.| 1939 1940**Error codes** 1941 1942For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1943 1944| **ID**| **Error Message**| 1945| -------- | -------- | 1946| 2501000 | Operation failed.| 1947 1948**Example** 1949```ts 1950 import wifiManager from '@ohos.wifiManager'; 1951 1952 try { 1953 let id = 0; 1954 wifiManager.removeDevice(id); 1955 }catch(error){ 1956 console.error("failed:" + JSON.stringify(error)); 1957 } 1958``` 1959 1960## wifiManager.isBandTypeSupported<sup>10+</sup> 1961 1962isBandTypeSupported(bandType: WifiBandType): boolean 1963 1964Checks whether the current frequency band is supported. 1965 1966**Required permissions**: ohos.permission.GET_WIFI_INFO 1967 1968**System capability**: SystemCapability.Communication.WiFi.STA 1969 1970**Parameters** 1971 1972| **Name**| **Type**| **Mandatory**| **Description**| 1973| -------- | -------- | -------- | -------- | 1974| bandType | WifiBandType | Yes| Wi-Fi band type.| 1975 1976**Return value** 1977 1978| **Type**| **Description**| 1979| -------- | -------- | 1980| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| 1981 1982**Error codes** 1983 1984For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 1985 1986| **ID**| **Error Message**| 1987| -------- | -------- | 1988| 2501000 | Operation failed.| 1989 1990**Example** 1991```ts 1992 import wifiManager from '@ohos.wifiManager'; 1993 1994 try { 1995 let type = 0; 1996 let isBandTypeSupported = wifiManager.isBandTypeSupported(type); 1997 console.info("isBandTypeSupported:" + isBandTypeSupported); 1998 }catch(error){ 1999 console.error("failed:" + JSON.stringify(error)); 2000 } 2001``` 2002 2003## wifiManager.get5GChannelList<sup>10+</sup> 2004 2005get5GChannelList(): Array<number> 2006 2007Obtains the list of 5 GHz channels supported by this device. 2008 2009**System API**: This is a system API. 2010 2011**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2012 2013**System capability**: SystemCapability.Communication.WiFi.STA 2014 2015**Return value** 2016 2017| **Type**| **Description**| 2018| -------- | -------- | 2019| Array<number> | List of 5 GHz channels supported by the device.| 2020 2021**Error codes** 2022 2023For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2024 2025| **ID**| **Error Message**| 2026| -------- | -------- | 2027| 2501000 | Operation failed.| 2028 2029**Example** 2030```ts 2031 import wifiManager from '@ohos.wifiManager'; 2032 2033 try { 2034 let channelList = wifiManager.get5GChannelList(); 2035 console.info("channelList:" + JSON.stringify(channelList)); 2036 }catch(error){ 2037 console.error("failed:" + JSON.stringify(error)); 2038 } 2039``` 2040## wifiManager.getDisconnectedReason<sup>10+</sup> 2041 2042getDisconnectedReason(): DisconnectedReason 2043 2044Obtains the reason of the latest disconnection. 2045 2046**System API**: This is a system API. 2047 2048**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2049 2050**System capability**: SystemCapability.Communication.WiFi.STA 2051 2052**Error codes** 2053 2054For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2055 2056| **ID**| **Error Message**| 2057| -------- | -------- | 2058| 2501000 | Operation failed.| 2059 2060**Return value** 2061 2062| **Type**| **Description**| 2063| -------- | -------- | 2064| DisconnectedReason | Returns the reason of the latest disconnection obtained.| 2065 2066**Example** 2067```ts 2068 import wifiManager from '@ohos.wifiManager'; 2069 2070 try { 2071 let disconnectedReason = wifiManager.getDisconnectedReason(); 2072 console.info("disconnectedReason:" + disconnectedReason); 2073 }catch(error){ 2074 console.error("failed:" + JSON.stringify(error)); 2075 } 2076``` 2077 2078## DisconnectedReason <sup>10+</sup> 2079 2080Enumerates the Wi-Fi disconnection reasons. 2081 2082**System API**: This is a system API. 2083 2084**System capability**: SystemCapability.Communication.WiFi.STA 2085 2086| Name| Value| Description| 2087| -------- | -------- | -------- | 2088| DISC_REASON_DEFAULT | 0 | Default reason.| 2089| DISC_REASON_WRONG_PWD | 1 | Incorrect password.| 2090| DISC_REASON_CONNECTION_FULL | 2 | The number of connections to the router has reached the limit.| 2091 2092## wifiManager.enableHotspot<sup>9+</sup> 2093 2094enableHotspot(): void 2095 2096Enables this hotspot. This API is an asynchronous interface. The **hotspotStateChange** callback must be registered and listened for. 2097 2098**System API**: This is a system API. 2099 2100**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 2101 2102**System capability**: SystemCapability.Communication.WiFi.AP.Core 2103 2104**Error codes** 2105 2106For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2107 2108| **ID**| **Error Message**| 2109| -------- | -------- | 2110| 2601000 | Operation failed.| 2111 2112**Example** 2113```ts 2114 import wifiManager from '@ohos.wifiManager'; 2115 2116 try { 2117 wifiManager.enableHotspot(); 2118 }catch(error){ 2119 console.error("failed:" + JSON.stringify(error)); 2120 } 2121``` 2122 2123## wifiManager.disableHotspot<sup>9+</sup> 2124 2125disableHotspot(): void 2126 2127Disables this hotspot. This API is an asynchronous interface. The **hotspotStateChange** callback must be registered and listened for. 2128 2129**System API**: This is a system API. 2130 2131**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 2132 2133**System capability**: SystemCapability.Communication.WiFi.AP.Core 2134 2135**Error codes** 2136 2137For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2138 2139| **ID**| **Error Message**| 2140| -------- | -------- | 2141| 2601000 | Operation failed.| 2142 2143**Example** 2144```ts 2145 import wifiManager from '@ohos.wifiManager'; 2146 2147 try { 2148 wifiManager.disableHotspot(); 2149 }catch(error){ 2150 console.error("failed:" + JSON.stringify(error)); 2151 } 2152``` 2153 2154## wifiManager.isHotspotDualBandSupported<sup>9+</sup> 2155 2156isHotspotDualBandSupported(): boolean 2157 2158Checks whether the hotspot supports dual band. 2159 2160**System API**: This is a system API. 2161 2162**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 2163 2164**System capability**: SystemCapability.Communication.WiFi.AP.Core 2165 2166**Return value** 2167 2168| **Type**| **Description**| 2169| -------- | -------- | 2170| boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.| 2171 2172**Error codes** 2173 2174For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2175 2176| **ID**| **Error Message**| 2177| -------- | -------- | 2178| 2601000 | Operation failed.| 2179 2180**Example** 2181```ts 2182 import wifiManager from '@ohos.wifiManager'; 2183 2184 try { 2185 let ret = wifiManager.isHotspotDualBandSupported(); 2186 console.info("result:" + ret); 2187 }catch(error){ 2188 console.error("failed:" + JSON.stringify(error)); 2189 } 2190``` 2191 2192## wifiManager.isHotspotActive<sup>9+</sup> 2193 2194isHotspotActive(): boolean 2195 2196Checks whether this hotspot is active. 2197 2198**System API**: This is a system API. 2199 2200**Required permissions**: ohos.permission.GET_WIFI_INFO 2201 2202**System capability**: SystemCapability.Communication.WiFi.AP.Core 2203 2204**Return value** 2205 2206| **Type**| **Description**| 2207| -------- | -------- | 2208| boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| 2209 2210**Error codes** 2211 2212For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2213 2214| **ID**| **Error Message**| 2215| -------- | -------- | 2216| 2601000 | Operation failed.| 2217 2218**Example** 2219```ts 2220 import wifiManager from '@ohos.wifiManager'; 2221 2222 try { 2223 let ret = wifiManager.isHotspotActive(); 2224 console.info("result:" + ret); 2225 }catch(error){ 2226 console.error("failed:" + JSON.stringify(error)); 2227 } 2228``` 2229 2230## wifiManager.setHotspotConfig<sup>9+</sup> 2231 2232setHotspotConfig(config: HotspotConfig): void 2233 2234Sets hotspot configuration. 2235 2236**System API**: This is a system API. 2237 2238**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2239 2240**System capability**: SystemCapability.Communication.WiFi.AP.Core 2241 2242**Parameters** 2243 2244| **Name**| **Type**| **Mandatory**| **Description**| 2245| -------- | -------- | -------- | -------- | 2246| config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| 2247 2248**Error codes** 2249 2250For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2251 2252| **ID**| **Error Message**| 2253| -------- | -------- | 2254| 2601000 | Operation failed.| 2255 2256**Example** 2257```ts 2258 import wifiManager from '@ohos.wifiManager'; 2259 2260 try { 2261 let config:wifiManager.HotspotConfig = { 2262 ssid: "****", 2263 securityType: 3, 2264 band: 0, 2265 channel: 0, 2266 preSharedKey: "****", 2267 maxConn: 0 2268 } 2269 let ret = wifiManager.setHotspotConfig(config); 2270 console.info("result:" + ret); 2271 }catch(error){ 2272 console.error("failed:" + JSON.stringify(error)); 2273 } 2274``` 2275 2276## HotspotConfig<sup>9+</sup> 2277 2278Represents the hotspot configuration. 2279 2280**System API**: This is a system API. 2281 2282**System capability**: SystemCapability.Communication.WiFi.AP.Core 2283 2284| **Name**| **Type**| **Readable**| **Writable**| **Description**| 2285| -------- | -------- | -------- | -------- | -------- | 2286| ssid | string | Yes| Yes| SSID of the hotspot, in UTF-8 format.| 2287| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| Yes| Security type.| 2288| band | number | Yes| Yes| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.| 2289| channel<sup>10+</sup> | number | Yes| Yes| Hotspot channel (2.4 GHz: 1 to 14; 5 GHz: 7 to 196; Dual-band: not supported currently) | 2290| preSharedKey | string | Yes| Yes| PSK of the hotspot.| 2291| maxConn | number | Yes| Yes| Maximum number of connections allowed.| 2292 2293## wifiManager.getHotspotConfig<sup>9+</sup> 2294 2295getHotspotConfig(): HotspotConfig 2296 2297Obtains hotspot configuration. 2298 2299**System API**: This is a system API. 2300 2301**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2302 2303**System capability**: SystemCapability.Communication.WiFi.AP.Core 2304 2305**Return value** 2306 2307| **Type**| **Description**| 2308| -------- | -------- | 2309| [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| 2310 2311**Error codes** 2312 2313For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2314 2315| **ID**| **Error Message**| 2316| -------- | -------- | 2317| 2601000 | Operation failed.| 2318 2319**Example** 2320```ts 2321 import wifiManager from '@ohos.wifiManager'; 2322 2323 try { 2324 let config = wifiManager.getHotspotConfig(); 2325 console.info("result:" + JSON.stringify(config)); 2326 }catch(error){ 2327 console.error("failed:" + JSON.stringify(error)); 2328 } 2329``` 2330 2331## wifiManager.getStations<sup>9+</sup> 2332 2333getStations(): Array<[StationInfo](#stationinfo9)> 2334 2335Obtains information about the connected stations. 2336 2337**System API**: This is a system API. 2338 2339**Required permissions**: 2340 2341API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only) 2342 2343API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only) 2344 2345**System capability**: SystemCapability.Communication.WiFi.AP.Core 2346 2347**Return value** 2348 2349| **Type**| **Description**| 2350| -------- | -------- | 2351| Array<[StationInfo](#stationinfo9)> | Connected stations obtained. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **macAddress** in the return value is a real MAC address; otherwise, **macAddress** is a random MAC address.| 2352 2353**Error codes** 2354 2355For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2356 2357| **ID**| **Error Message**| 2358| -------- | -------- | 2359| 2601000 | Operation failed.| 2360 2361**Example** 2362```ts 2363 import wifiManager from '@ohos.wifiManager'; 2364 2365 try { 2366 let stations = wifiManager.getStations(); 2367 console.info("result:" + JSON.stringify(stations)); 2368 }catch(error){ 2369 console.error("failed:" + JSON.stringify(error)); 2370 } 2371``` 2372 2373## StationInfo<sup>9+</sup> 2374 2375Represents the station information. 2376 2377**System API**: This is a system API. 2378 2379**System capability**: SystemCapability.Communication.WiFi.AP.Core 2380 2381| **Name**| **Type**| **Readable**| **Writable**| **Description**| 2382| -------- | -------- | -------- | -------- | -------- | 2383| name | string | Yes| No| Device name.| 2384| macAddress | string | Yes| No| MAC address.| 2385| macAddressType<sup>10+</sup> | DeviceAddressType | Yes| No| MAC address type.| 2386| ipAddress | string | Yes| No| IP address.| 2387 2388 2389## wifiManager.getP2pLinkedInfo<sup>9+</sup> 2390 2391getP2pLinkedInfo(): Promise<WifiP2pLinkedInfo> 2392 2393Obtains P2P link information. This API uses a promise to return the result. 2394 2395**Required permissions**: ohos.permission.GET_WIFI_INFO 2396 2397**System capability**: SystemCapability.Communication.WiFi.P2P 2398 2399**Return value** 2400 2401| Type| Description| 2402| -------- | -------- | 2403| Promise<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Promise used to return the P2P link information obtained.| 2404 2405**Error codes** 2406 2407For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2408 2409| **ID**| **Error Message**| 2410| -------- | -------- | 2411| 2801000 | Operation failed.| 2412 2413**Example** 2414```ts 2415 import wifiManager from '@ohos.wifiManager'; 2416 2417 wifiManager.getP2pLinkedInfo((err, data) => { 2418 if (err) { 2419 console.error("get p2p linked info error"); 2420 return; 2421 } 2422 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 2423 }); 2424 2425 wifiManager.getP2pLinkedInfo().then(data => { 2426 console.info("get wifi p2p linked info: " + JSON.stringify(data)); 2427 }); 2428``` 2429 2430 2431## WifiP2pLinkedInfo<sup>9+</sup> 2432 2433Represents the P2P link information. 2434 2435**System capability**: SystemCapability.Communication.WiFi.P2P 2436 2437| Name| Type| Readable| Writable| Description| 2438| -------- | -------- | -------- | -------- | -------- | 2439| connectState | [P2pConnectState](#p2pconnectstate9) | Yes| No| P2P connection state.| 2440| isGroupOwner | boolean | Yes| No| Whether the device is the group owner.| 2441| groupOwnerAddr | string | Yes| No| MAC address of the group. 2442 2443 2444## P2pConnectState<sup>9+</sup> 2445 2446Enumerates the P2P connection states. 2447 2448**System capability**: SystemCapability.Communication.WiFi.P2P 2449 2450| Name| Value| Description| 2451| -------- | -------- | -------- | 2452| DISCONNECTED | 0 | Disconnected.| 2453| CONNECTED | 1 | Connected.| 2454 2455 2456## wifiManager.getP2pLinkedInfo<sup>9+</sup> 2457 2458getP2pLinkedInfo(callback: AsyncCallback<WifiP2pLinkedInfo>): void 2459 2460Obtains P2P link information. This API uses an asynchronous callback to return the result. 2461 2462**Required permissions**: ohos.permission.GET_WIFI_INFO 2463 2464**System capability**: SystemCapability.Communication.WiFi.P2P 2465 2466**Parameters** 2467 2468| Name| Type| Mandatory| Description| 2469| -------- | -------- | -------- | -------- | 2470| callback | AsyncCallback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.| 2471 2472**Error codes** 2473 2474For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2475 2476| **ID**| **Error Message**| 2477| -------- | -------- | 2478| 2801000 | Operation failed.| 2479 2480## wifiManager.getCurrentGroup<sup>9+</sup> 2481 2482getCurrentGroup(): Promise<WifiP2pGroupInfo> 2483 2484Obtains the current P2P group information. This API uses a promise to return the result. 2485 2486**Required permissions**: 2487 2488API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2489 2490API version 10 and later : ohos.permission.GET_WIFI_INFO 2491 2492**System capability**: SystemCapability.Communication.WiFi.P2P 2493 2494**Return value** 2495 2496| Type| Description| 2497| -------- | -------- | 2498| Promise<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Promise used to return the P2P group information obtained. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 2499 2500**Error codes** 2501 2502For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2503 2504| **ID**| **Error Message**| 2505| -------- | -------- | 2506| 2801000 | Operation failed.| 2507 2508## wifiManager.getCurrentGroup<sup>9+</sup> 2509 2510getCurrentGroup(callback: AsyncCallback<WifiP2pGroupInfo>): void 2511 2512Obtains the current P2P group information. This API uses an asynchronous callback to return the result. 2513 2514**Required permissions**: 2515 2516API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2517 2518API version 10 and later : ohos.permission.GET_WIFI_INFO 2519 2520**System capability**: SystemCapability.Communication.WiFi.P2P 2521 2522**Parameters** 2523 2524| Name| Type| Mandatory| Description| 2525| -------- | -------- | -------- | -------- | 2526| callback | AsyncCallback<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 2527 2528**Error codes** 2529 2530For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2531 2532| **ID**| **Error Message**| 2533| -------- | -------- | 2534| 2801000 | Operation failed.| 2535 2536**Example** 2537```ts 2538 import wifiManager from '@ohos.wifiManager'; 2539 2540 wifiManager.getCurrentGroup((err, data) => { 2541 if (err) { 2542 console.error("get current P2P group error"); 2543 return; 2544 } 2545 console.info("get current P2P group: " + JSON.stringify(data)); 2546 }); 2547 2548 wifiManager.getCurrentGroup().then(data => { 2549 console.info("get current P2P group: " + JSON.stringify(data)); 2550 }); 2551``` 2552 2553## wifiManager.getP2pPeerDevices<sup>9+</sup> 2554 2555getP2pPeerDevices(): Promise<WifiP2pDevice[]> 2556 2557Obtains the peer device list in the P2P connection. This API uses a promise to return the result. 2558 2559**Required permissions**: 2560 2561API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2562 2563API version 10 and later : ohos.permission.GET_WIFI_INFO 2564 2565**System capability**: SystemCapability.Communication.WiFi.P2P 2566 2567**Return value** 2568 2569| Type| Description| 2570| -------- | -------- | 2571| Promise<[WifiP2pDevice[]](#wifip2pdevice9)> | Promise used to return the peer device list. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 2572 2573**Error codes** 2574 2575For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2576 2577| **ID**| **Error Message**| 2578| -------- | -------- | 2579| 2801000 | Operation failed.| 2580 2581## wifiManager.getP2pPeerDevices<sup>9+</sup> 2582 2583getP2pPeerDevices(callback: AsyncCallback<WifiP2pDevice[]>): void 2584 2585Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result. 2586 2587**Required permissions**: 2588 2589API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2590 2591API version 10 and later : ohos.permission.GET_WIFI_INFO 2592 2593**System capability**: SystemCapability.Communication.WiFi.P2P 2594 2595**Parameters** 2596 2597| Name| Type| Mandatory| Description| 2598| -------- | -------- | -------- | -------- | 2599| callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 2600 2601**Error codes** 2602 2603For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2604 2605| **ID**| **Error Message**| 2606| -------- | -------- | 2607| 2801000 | Operation failed.| 2608 2609**Example** 2610```ts 2611 import wifiManager from '@ohos.wifiManager'; 2612 2613 wifiManager.getP2pPeerDevices((err, data) => { 2614 if (err) { 2615 console.error("get P2P peer devices error"); 2616 return; 2617 } 2618 console.info("get P2P peer devices: " + JSON.stringify(data)); 2619 }); 2620 2621 wifiManager.getP2pPeerDevices().then(data => { 2622 console.info("get P2P peer devices: " + JSON.stringify(data)); 2623 }); 2624``` 2625 2626## WifiP2pDevice<sup>9+</sup> 2627 2628Represents the P2P device information. 2629 2630**System capability**: SystemCapability.Communication.WiFi.P2P 2631 2632| Name| Type| Readable| Writable| Description| 2633| -------- | -------- | -------- | -------- | -------- | 2634| deviceName | string | Yes| No| Device name.| 2635| deviceAddress | string | Yes| No| MAC address of the device.| 2636| deviceAddressType<sup>10+</sup> | DeviceAddressType | Yes| No| MAC address type of the device.| 2637| primaryDeviceType | string | Yes| No| Type of the primary device.| 2638| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus9) | Yes| No| Device status.| 2639| groupCapabilities | number | Yes| No| Group capabilities.| 2640 2641 2642## P2pDeviceStatus<sup>9+</sup> 2643 2644Enumerates the P2P device states. 2645 2646**System capability**: SystemCapability.Communication.WiFi.P2P 2647 2648| Name| Value| Description| 2649| -------- | -------- | -------- | 2650| CONNECTED | 0 | Connected.| 2651| INVITED | 1 | Invited.| 2652| FAILED | 2 | Failed.| 2653| AVAILABLE | 3 | Available.| 2654| UNAVAILABLE | 4 | Unavailable.| 2655 2656 2657## wifiManager.getP2pLocalDevice<sup>9+</sup> 2658 2659getP2pLocalDevice(): Promise<WifiP2pDevice> 2660 2661Obtains the local device information in the P2P connection. This API uses a promise to return the result. 2662 2663**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2664 2665**System capability**: SystemCapability.Communication.WiFi.P2P 2666 2667**Return value** 2668 2669| Type| Description| 2670| -------- | -------- | 2671| Promise<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.| 2672 2673**Error codes** 2674 2675For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2676 2677| **ID**| **Error Message**| 2678| -------- | -------- | 2679| 2801000 | Operation failed.| 2680 2681## wifiManager.getP2pLocalDevice<sup>9+</sup> 2682 2683getP2pLocalDevice(callback: AsyncCallback<WifiP2pDevice>): void 2684 2685Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result. 2686 2687**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 2688 2689**System capability**: SystemCapability.Communication.WiFi.P2P 2690 2691**Parameters** 2692 2693| Name| Type| Mandatory| Description| 2694| -------- | -------- | -------- | -------- | 2695| callback | AsyncCallback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If **err** is not **0**, an error has occurred.| 2696 2697**Error codes** 2698 2699| **ID**| **Error Message**| 2700| -------- | -------- | 2701| 2801000 | Operation failed.| 2702 2703**Example** 2704```ts 2705 import wifiManager from '@ohos.wifiManager'; 2706 2707 wifiManager.getP2pLocalDevice((err, data) => { 2708 if (err) { 2709 console.error("get P2P local device error"); 2710 return; 2711 } 2712 console.info("get P2P local device: " + JSON.stringify(data)); 2713 }); 2714 2715 wifiManager.getP2pLocalDevice().then(data => { 2716 console.info("get P2P local device: " + JSON.stringify(data)); 2717 }); 2718``` 2719 2720## wifiManager.createGroup<sup>9+</sup> 2721 2722createGroup(config: WifiP2PConfig): void 2723 2724Creates a P2P group. 2725 2726**Required permissions**: ohos.permission.GET_WIFI_INFO 2727 2728**System capability**: SystemCapability.Communication.WiFi.P2P 2729 2730**Parameters** 2731 2732| **Name**| **Type**| Mandatory| **Description**| 2733| -------- | -------- | -------- | -------- | 2734| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration. The default **DeviceAddressType** is random device address.| 2735 2736**Error codes** 2737 2738For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2739 2740| **ID**| **Error Message**| 2741| -------- | -------- | 2742| 2801000 | Operation failed.| 2743 2744**Example** 2745```ts 2746 import wifiManager from '@ohos.wifiManager'; 2747 2748 try { 2749 let config:wifiManager.WifiP2PConfig = { 2750 deviceAddress: "****", 2751 netId: 0, 2752 passphrase: "*****", 2753 groupName: "****", 2754 goBand: 0 2755 } 2756 wifiManager.createGroup(config); 2757 2758 }catch(error){ 2759 console.error("failed:" + JSON.stringify(error)); 2760 } 2761``` 2762 2763## WifiP2PConfig<sup>9+</sup> 2764 2765Represents P2P group configuration. 2766 2767**System capability**: SystemCapability.Communication.WiFi.P2P 2768 2769| Name| Type| Readable| Writable| Description| 2770| -------- | -------- | -------- | -------- | -------- | 2771| deviceAddress | string | Yes| No| Device address.| 2772| deviceAddressType<sup>10+</sup>| DeviceAddressType | Yes| No| Device address type.| 2773| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.| 2774| passphrase | string | Yes| No| Passphrase of the group.| 2775| groupName | string | Yes| No| Name of the group.| 2776| goBand | [GroupOwnerBand](#groupownerband9) | Yes| No| Frequency band of the group.| 2777 2778 2779## GroupOwnerBand<sup>9+</sup> 2780 2781Enumerates the P2P group frequency bands. 2782 2783**System capability**: SystemCapability.Communication.WiFi.P2P 2784 2785| Name| Value| Description| 2786| -------- | -------- | -------- | 2787| GO_BAND_AUTO | 0 | Auto.| 2788| GO_BAND_2GHZ | 1 | 2 GHz.| 2789| GO_BAND_5GHZ | 2 | 5 GHz.| 2790 2791 2792## wifiManager.removeGroup<sup>9+</sup> 2793 2794removeGroup(): void 2795 2796Removes this P2P group. 2797 2798**Required permissions**: ohos.permission.GET_WIFI_INFO 2799 2800**System capability**: SystemCapability.Communication.WiFi.P2P 2801 2802**Error codes** 2803 2804For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2805 2806| **ID**| **Error Message**| 2807| -------- | -------- | 2808| 2801000 | Operation failed.| 2809 2810**Example** 2811```ts 2812 import wifiManager from '@ohos.wifiManager'; 2813 2814 try { 2815 wifiManager.removeGroup(); 2816 }catch(error){ 2817 console.error("failed:" + JSON.stringify(error)); 2818 } 2819``` 2820 2821## wifiManager.p2pConnect<sup>9+</sup> 2822 2823p2pConnect(config: WifiP2PConfig): void 2824 2825Sets up a P2P connection. 2826 2827**Required permissions**: 2828 2829API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2830 2831API version 10 and later : ohos.permission.GET_WIFI_INFO 2832 2833**System capability**: SystemCapability.Communication.WiFi.P2P 2834 2835**Parameters** 2836 2837| **Name**| **Type**| Mandatory| **Description**| 2838| -------- | -------- | -------- | -------- | 2839| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration. The default **DeviceAddressType** is random device address.| 2840 2841**Error codes** 2842 2843For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2844 2845| **ID**| **Error Message**| 2846| -------- | -------- | 2847| 2801000 | Operation failed.| 2848 2849**Example** 2850```ts 2851 import wifiManager from '@ohos.wifiManager'; 2852 2853 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 2854 console.info("p2p connection change receive event: " + JSON.stringify(result)); 2855 wifiManager.getP2pLinkedInfo((err, data) => { 2856 if (err) { 2857 console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err)); 2858 return; 2859 } 2860 console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); 2861 }); 2862 } 2863 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 2864 2865 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 2866 console.info("p2p device change receive event: " + JSON.stringify(result)); 2867 } 2868 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 2869 2870 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 2871 console.info("p2p peer device change receive event: " + JSON.stringify(result)); 2872 wifiManager.getP2pPeerDevices((err, data) => { 2873 if (err) { 2874 console.error('failed to get peer devices: ' + JSON.stringify(err)); 2875 return; 2876 } 2877 console.info("get peer devices: " + JSON.stringify(data)); 2878 let len = data.length; 2879 for (let i = 0; i < len; ++i) { 2880 if (data[i].deviceName === "my_test_device") { 2881 console.info("p2p connect to test device: " + data[i].deviceAddress); 2882 let config:wifiManager.WifiP2PConfig = { 2883 deviceAddress:data[i].deviceAddress, 2884 netId:-2, 2885 passphrase:"", 2886 groupName:"", 2887 goBand:0, 2888 } 2889 wifiManager.p2pConnect(config); 2890 } 2891 } 2892 }); 2893 } 2894 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 2895 2896 let recvP2pPersistentGroupChangeFunc = () => { 2897 console.info("p2p persistent group change receive event"); 2898 2899 wifiManager.getCurrentGroup((err, data) => { 2900 if (err) { 2901 console.error('failed to get current group: ' + JSON.stringify(err)); 2902 return; 2903 } 2904 console.info("get current group: " + JSON.stringify(data)); 2905 }); 2906 } 2907 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 2908 2909 setTimeout(() => {wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); 2910 setTimeout(() => {wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); 2911 setTimeout(() => {wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); 2912 setTimeout(() => {wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); 2913 console.info("start discover devices -> " + wifiManager.startDiscoverDevices()); 2914``` 2915 2916## wifiManager.p2pCancelConnect<sup>9+</sup> 2917 2918p2pCancelConnect(): void 2919 2920Cancels this P2P connection. 2921 2922**Required permissions**: ohos.permission.GET_WIFI_INFO 2923 2924**System capability**: SystemCapability.Communication.WiFi.P2P 2925 2926**Error codes** 2927 2928For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2929 2930| **ID**| **Error Message**| 2931| -------- | -------- | 2932| 2801000 | Operation failed.| 2933 2934**Example** 2935```ts 2936 import wifiManager from '@ohos.wifiManager'; 2937 2938 try { 2939 wifiManager.p2pCancelConnect(); 2940 }catch(error){ 2941 console.error("failed:" + JSON.stringify(error)); 2942 } 2943``` 2944 2945## wifiManager.startDiscoverDevices<sup>9+</sup> 2946 2947startDiscoverDevices(): void 2948 2949Starts to discover devices. 2950 2951**Required permissions**: 2952 2953API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 2954 2955API version 10 and later : ohos.permission.GET_WIFI_INFO 2956 2957**System capability**: SystemCapability.Communication.WiFi.P2P 2958 2959**Error codes** 2960 2961For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2962 2963| **ID**| **Error Message**| 2964| -------- | -------- | 2965| 2801000 | Operation failed.| 2966 2967**Example** 2968```ts 2969 import wifiManager from '@ohos.wifiManager'; 2970 2971 try { 2972 wifiManager.startDiscoverDevices(); 2973 }catch(error){ 2974 console.error("failed:" + JSON.stringify(error)); 2975 } 2976``` 2977 2978## wifiManager.stopDiscoverDevices<sup>9+</sup> 2979 2980stopDiscoverDevices(): void 2981 2982Stops discovering devices. 2983 2984**Required permissions**: ohos.permission.GET_WIFI_INFO 2985 2986**System capability**: SystemCapability.Communication.WiFi.P2P 2987 2988**Error codes** 2989 2990For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 2991 2992| **ID**| **Error Message**| 2993| -------- | -------- | 2994| 2801000 | Operation failed.| 2995 2996**Example** 2997```ts 2998 import wifiManager from '@ohos.wifiManager'; 2999 3000 try { 3001 wifiManager.stopDiscoverDevices(); 3002 }catch(error){ 3003 console.error("failed:" + JSON.stringify(error)); 3004 } 3005``` 3006 3007## wifiManager.deletePersistentGroup<sup>9+</sup> 3008 3009deletePersistentGroup(netId: number): void 3010 3011Deletes a persistent group. 3012 3013**System API**: This is a system API. 3014 3015**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 3016 3017**System capability**: SystemCapability.Communication.WiFi.P2P 3018 3019**Parameters** 3020 3021 3022| **Name**| **Type**| Mandatory| **Description**| 3023| -------- | -------- | -------- | -------- | 3024| netId | number | Yes| ID of the group to delete.| 3025 3026**Error codes** 3027 3028For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3029 3030| **ID**| **Error Message**| 3031| -------- | -------- | 3032| 2801000 | Operation failed.| 3033 3034**Example** 3035```ts 3036 import wifiManager from '@ohos.wifiManager'; 3037 3038 try { 3039 let netId = 0; 3040 wifiManager.deletePersistentGroup(netId); 3041 }catch(error){ 3042 console.error("failed:" + JSON.stringify(error)); 3043 } 3044``` 3045 3046## wifiManager.getP2pGroups<sup>9+</sup> 3047 3048getP2pGroups(): Promise<Array<WifiP2pGroupInfo>> 3049 3050Obtains information about all P2P groups. This API uses a promise to return the result. 3051 3052**System API**: This is a system API. 3053 3054**Required permissions**: 3055 3056API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 3057 3058API version 10 and later : ohos.permission.GET_WIFI_INFO 3059 3060**System capability**: SystemCapability.Communication.WiFi.P2P 3061 3062**Return value** 3063 3064| Type| Description| 3065| -------- | -------- | 3066| Promise< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> > | Promise used to return the group information obtained. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 3067 3068**Error codes** 3069 3070For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3071 3072| **ID**| **Error Message**| 3073| -------- | -------- | 3074| 2801000 | Operation failed.| 3075 3076**Example** 3077```ts 3078 import wifiManager from '@ohos.wifiManager'; 3079 3080 wifiManager.getP2pGroups((err, data) => { 3081 if (err) { 3082 console.error("get P2P groups error"); 3083 return; 3084 } 3085 console.info("get P2P groups: " + JSON.stringify(data)); 3086 }); 3087 3088 wifiManager.getP2pGroups().then(data => { 3089 console.info("get P2P groups: " + JSON.stringify(data)); 3090 }); 3091 3092``` 3093 3094## WifiP2pGroupInfo<sup>9+</sup> 3095 3096Represents the P2P group information. 3097 3098**System capability**: SystemCapability.Communication.WiFi.P2P 3099 3100| Name| Type| Readable| Writable| Description| 3101| -------- | -------- | -------- | -------- | -------- | 3102| isP2pGo | boolean | Yes| No| Whether the device is the group owner.| 3103| ownerInfo | [WifiP2pDevice](#wifip2pdevice9) | Yes| No| Device information of the group.| 3104| passphrase | string | Yes| No| Passphrase of the group.| 3105| interface | string | Yes| No| Interface name.| 3106| groupName | string | Yes| No| Group name.| 3107| networkId | number | Yes| No| Network ID.| 3108| frequency | number | Yes| No| Frequency of the group.| 3109| clientDevices | [WifiP2pDevice[]](#wifip2pdevice9) | Yes| No| List of connected devices.| 3110| goIpAddress | string | Yes| No| IP address of the group.| 3111 3112 3113## wifiManager.getP2pGroups<sup>9+</sup> 3114 3115getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void 3116 3117Obtains information about all P2P groups. This API uses an asynchronous callback to return the result. 3118 3119**System API**: This is a system API. 3120 3121**Required permissions**: 3122 3123API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 3124 3125API version 10 and later : ohos.permission.GET_WIFI_INFO 3126 3127**System capability**: SystemCapability.Communication.WiFi.P2P 3128 3129**Parameters** 3130 3131| Name| Type| Mandatory| Description| 3132| -------- | -------- | -------- | -------- | 3133| callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 3134 3135**Error codes** 3136 3137For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3138 3139| **ID**| **Error Message**| 3140| -------- | -------- | 3141| 2801000 | Operation failed.| 3142 3143## wifiManager.setDeviceName<sup>9+</sup> 3144 3145setDeviceName(devName: string): void 3146 3147Sets the device name. 3148 3149**System API**: This is a system API. 3150 3151**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 3152 3153**System capability**: SystemCapability.Communication.WiFi.P2P 3154 3155**Parameters** 3156 3157| **Name**| **Type**| **Mandatory**| **Description**| 3158| -------- | -------- | -------- | -------- | 3159| devName | string | Yes| Device name to set.| 3160 3161**Error codes** 3162 3163For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3164 3165| **ID**| **Error Message**| 3166| -------- | -------- | 3167| 2801000 | Operation failed.| 3168 3169**Example** 3170```ts 3171 import wifiManager from '@ohos.wifiManager'; 3172 3173 try { 3174 let name = "****"; 3175 wifiManager.setDeviceName(name); 3176 }catch(error){ 3177 console.error("failed:" + JSON.stringify(error)); 3178 } 3179``` 3180 3181## wifiManager.on('wifiStateChange')<sup>9+</sup> 3182 3183on(type: "wifiStateChange", callback: Callback<number>): void 3184 3185Subscribes to WLAN state changes. 3186 3187**Required permissions**: ohos.permission.GET_WIFI_INFO 3188 3189**System capability**: SystemCapability.Communication.WiFi.STA 3190 3191**Parameters** 3192 3193| **Name**| **Type**| **Mandatory**| **Description**| 3194| -------- | -------- | -------- | -------- | 3195| type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 3196| callback | Callback<number> | Yes| Callback invoked to return the WLAN state.| 3197 3198**Error codes** 3199 3200For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3201 3202| **ID**| **Error Message**| 3203| -------- | -------- | 3204| 2501000 | Operation failed.| 3205 3206**WLAN states** 3207 3208| **Value**| **Description**| 3209| -------- | -------- | 3210| 0 | Deactivated| 3211| 1 | Activated| 3212| 2 | Activating| 3213| 3 | Deactivating| 3214 3215 3216## wifiManager.off('wifiStateChange')<sup>9+</sup> 3217 3218off(type: "wifiStateChange", callback?: Callback<number>): void 3219 3220Unsubscribes from WLAN state changes. 3221 3222**Required permissions**: ohos.permission.GET_WIFI_INFO 3223 3224**System capability**: SystemCapability.Communication.WiFi.STA 3225 3226**Parameters** 3227 3228| **Name**| **Type**| **Mandatory**| **Description**| 3229| -------- | -------- | -------- | -------- | 3230| type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.| 3231| callback | Callback<number> | No| Callback for the WLAN state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3232 3233**Error codes** 3234 3235For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3236 3237| **ID**| **Error Message**| 3238| -------- | -------- | 3239| 2501000 | Operation failed.| 3240 3241**Example** 3242```ts 3243 import wifiManager from '@ohos.wifiManager'; 3244 3245 let recvPowerNotifyFunc = (result:number) => { 3246 console.info("Receive power state change event: " + result); 3247 } 3248 3249 // Register an event. 3250 wifiManager.on("wifiStateChange", recvPowerNotifyFunc); 3251 3252 // Unregister an event. 3253 wifiManager.off("wifiStateChange", recvPowerNotifyFunc); 3254``` 3255 3256 3257## wifiManager.on('wifiConnectionChange')<sup>9+</sup> 3258 3259on(type: "wifiConnectionChange", callback: Callback<number>): void 3260 3261Subscribes to WLAN connection state changes. 3262 3263**Required permissions**: ohos.permission.GET_WIFI_INFO 3264 3265**System capability**: SystemCapability.Communication.WiFi.STA 3266 3267**Parameters** 3268 3269| **Name**| **Type**| **Mandatory**| **Description**| 3270| -------- | -------- | -------- | -------- | 3271| type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 3272| callback | Callback<number> | Yes| Callback invoked to return the WLAN connection state.| 3273 3274**WLAN connection states** 3275 3276| **Value**| **Description**| 3277| -------- | -------- | 3278| 0 | Disconnected.| 3279| 1 | Connected.| 3280 3281**Error codes** 3282 3283For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3284 3285| **ID**| **Error Message**| 3286| -------- | -------- | 3287| 2501000 | Operation failed.| 3288 3289## wifiManager.off('wifiConnectionChange')<sup>9+</sup> 3290 3291off(type: "wifiConnectionChange", callback?: Callback<number>): void 3292 3293Unsubscribes from WLAN connection state changes. 3294 3295**Required permissions**: ohos.permission.GET_WIFI_INFO 3296 3297**System capability**: SystemCapability.Communication.WiFi.STA 3298 3299**Parameters** 3300 3301| **Name**| **Type**| **Mandatory**| **Description**| 3302| -------- | -------- | -------- | -------- | 3303| type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.| 3304| callback | Callback<number> | No| Callback for the WLAN connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3305 3306**Error codes** 3307 3308For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3309 3310| **ID**| **Error Message**| 3311| -------- | -------- | 3312| 2501000 | Operation failed.| 3313 3314**Example** 3315```ts 3316 import wifiManager from '@ohos.wifiManager'; 3317 3318 let recvWifiConnectionChangeFunc = (result:number) => { 3319 console.info("Receive wifi connection change event: " + result); 3320 } 3321 3322 // Register an event. 3323 wifiManager.on("wifiConnectionChange", recvWifiConnectionChangeFunc); 3324 3325 // Unregister an event. 3326 wifiManager.off("wifiConnectionChange", recvWifiConnectionChangeFunc); 3327``` 3328 3329## wifiManager.on('wifiScanStateChange')<sup>9+</sup> 3330 3331on(type: "wifiScanStateChange", callback: Callback<number>): void 3332 3333Subscribes to WLAN scan state changes. 3334 3335**Required permissions**: ohos.permission.GET_WIFI_INFO 3336 3337**System capability**: SystemCapability.Communication.WiFi.STA 3338 3339**Parameters** 3340 3341| **Name**| **Type**| **Mandatory**| **Description**| 3342| -------- | -------- | -------- | -------- | 3343| type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 3344| callback | Callback<number> | Yes| Callback invoked to return the WLAN scan state.| 3345 3346**WLAN scan states** 3347 3348| **Value**| **Description**| 3349| -------- | -------- | 3350| 0 | Scan failed.| 3351| 1 | Scan successful.| 3352 3353**Error codes** 3354 3355For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3356 3357| **ID**| **Error Message**| 3358| -------- | -------- | 3359| 2501000 | Operation failed.| 3360 3361## wifiManager.off('wifiScanStateChange')<sup>9+</sup> 3362 3363off(type: "wifiScanStateChange", callback?: Callback<number>): void 3364 3365Unsubscribes from WLAN scan state changes. 3366 3367**Required permissions**: ohos.permission.GET_WIFI_INFO 3368 3369**System capability**: SystemCapability.Communication.WiFi.STA 3370 3371**Parameters** 3372 3373| **Name**| **Type**| **Mandatory**| **Description**| 3374| -------- | -------- | -------- | -------- | 3375| type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.| 3376| callback | Callback<number> | No| Callback for the WLAN scan state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3377 3378**Error codes** 3379 3380For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3381 3382| **ID**| **Error Message**| 3383| -------- | -------- | 3384| 2501000 | Operation failed.| 3385 3386**Example** 3387```ts 3388 import wifiManager from '@ohos.wifiManager'; 3389 3390 let recvWifiScanStateChangeFunc = (result:number) => { 3391 console.info("Receive Wifi scan state change event: " + result); 3392 } 3393 3394 // Register an event. 3395 wifiManager.on("wifiScanStateChange", recvWifiScanStateChangeFunc); 3396 3397 // Unregister an event. 3398 wifiManager.off("wifiScanStateChange", recvWifiScanStateChangeFunc); 3399``` 3400 3401## wifiManager.on('wifiRssiChange')<sup>9+</sup> 3402 3403on(type: "wifiRssiChange", callback: Callback<number>): void 3404 3405Subscribes to RSSI changes. 3406 3407**Required permissions**: ohos.permission.GET_WIFI_INFO 3408 3409**System capability**: SystemCapability.Communication.WiFi.STA 3410 3411**Parameters** 3412 3413| **Name**| **Type**| **Mandatory**| **Description**| 3414| -------- | -------- | -------- | -------- | 3415| type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 3416| callback | Callback<number> | Yes| Callback invoked to return the RSSI, in dBm.| 3417 3418**Error codes** 3419 3420For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3421 3422| **ID**| **Error Message**| 3423| -------- | -------- | 3424| 2501000 | Operation failed.| 3425 3426## wifiManager.off('wifiRssiChange')<sup>9+</sup> 3427 3428off(type: "wifiRssiChange", callback?: Callback<number>): void 3429 3430Unsubscribes from RSSI changes. 3431 3432**Required permissions**: ohos.permission.GET_WIFI_INFO 3433 3434**System capability**: SystemCapability.Communication.WiFi.STA 3435 3436**Parameters** 3437 3438| **Name**| **Type**| **Mandatory**| **Description**| 3439| -------- | -------- | -------- | -------- | 3440| type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.| 3441| callback | Callback<number> | No| Callback for the RSSI change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3442 3443**Error codes** 3444 3445For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3446 3447| **ID**| **Error Message**| 3448| -------- | -------- | 3449| 2501000 | Operation failed.| 3450 3451**Example** 3452```ts 3453 import wifiManager from '@ohos.wifiManager'; 3454 3455 let recvWifiRssiChangeFunc = (result:number) => { 3456 console.info("Receive wifi rssi change event: " + result); 3457 } 3458 3459 // Register an event. 3460 wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc); 3461 3462 // Unregister an event. 3463 wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc); 3464``` 3465 ## wifiManager.on('streamChange')<sup>9+</sup> 3466 3467on(type: "streamChange", callback: Callback<number>): void 3468 3469Subscribes to Wi-Fi stream changes. This API is not supported in the current version, and error code 801 will be thrown. 3470 3471**System API**: This is a system API. 3472 3473**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION 3474 3475**System capability**: SystemCapability.Communication.WiFi.STA 3476 3477**Parameters** 3478 3479| **Name**| **Type**| **Mandatory**| **Description**| 3480| -------- | -------- | -------- | -------- | 3481| type | string | Yes| Event type, which has a fixed value of **streamChange**.| 3482| callback | Callback<number> | Yes| Callback invoked to return the stream change, which can be any of the following values:<br>- **0**: No stream.<br>- **1**: Downward.<br>- **2**: Upward.<br>- **3**: Bidirectional.| 3483 3484**Error codes** 3485 3486For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3487 3488| **ID**| **Error Message**| 3489| -------- | -------- | 3490| 2501000 | Operation failed.| 3491 3492## wifiManager.off('streamChange')<sup>9+</sup> 3493 3494off(type: "streamChange", callback?: Callback<number>): void 3495 3496Unsubscribes from Wi-Fi stream changes. This API is not supported in the current version, and error code 801 will be thrown. 3497 3498**System API**: This is a system API. 3499 3500**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION 3501 3502**System capability**: SystemCapability.Communication.WiFi.STA 3503 3504**Parameters** 3505 3506| **Name**| **Type**| **Mandatory**| **Description**| 3507| -------- | -------- | -------- | -------- | 3508| type | string | Yes| Event type, which has a fixed value of **streamChange**.| 3509| callback | Callback<number> | No| Callback for the stream change, which can be any of the following values:<br>- **0**: No stream.<br>- **1**: Downward.<br>- **2**: Upward.<br>- **3**: Bidirectional.| 3510 3511**Error codes** 3512 3513For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3514 3515| **ID**| **Error Message**| 3516| -------- | -------- | 3517| 2501000 | Operation failed.| 3518 3519**Example** 3520```ts 3521import wifi from '@ohos.wifi'; 3522 3523let recvStreamChangeFunc = (result:number) => { 3524 console.info("Receive stream change event: " + result); 3525} 3526 3527// Register an event. 3528wifi.on("streamChange", recvStreamChangeFunc); 3529 3530// Unregister an event. 3531wifi.off("streamChange", recvStreamChangeFunc); 3532 3533``` 3534## wifiManager.on('deviceConfigChange')<sup>9+</sup> 3535 3536on(type: "deviceConfigChange", callback: Callback<number>): void 3537 3538Subscribes to Wi-Fi device configuration changes. 3539 3540**System API**: This is a system API. 3541 3542**Required permissions**: ohos.permission.GET_WIFI_INFO 3543 3544**System capability**: SystemCapability.Communication.WiFi.STA 3545 3546**Parameters** 3547 3548| **Name**| **Type**| **Mandatory**| **Description**| 3549| -------- | -------- | -------- | -------- | 3550| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.| 3551| callback | Callback<number> | Yes| Callback invoked to return the device configuration change, which can be any of the following values:<br>- **0**: device configuration added.<br>- **1**: device configuration changed.<br>- **2**: device configuration deleted.| 3552 3553**Error codes** 3554 3555For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3556 3557| **ID**| **Error Message**| 3558| -------- | -------- | 3559| 2501000 | Operation failed.| 3560 3561## wifiManager.off('deviceConfigChange')<sup>9+</sup> 3562 3563off(type: "deviceConfigChange", callback?: Callback<number>): void 3564 3565Unsubscribes from Wi-Fi device configuration changes. 3566 3567**System API**: This is a system API. 3568 3569**Required permissions**: ohos.permission.GET_WIFI_INFO 3570 3571**System capability**: SystemCapability.Communication.WiFi.STA 3572 3573**Parameters** 3574 3575| **Name**| **Type**| **Mandatory**| **Description**| 3576| -------- | -------- | -------- | -------- | 3577| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.| 3578| callback | Callback<number> | No| Callback for the device configuration change, which can be any of the following values:<br>- **0**: device configuration added.<br>- **1**: device configuration changed.<br>- **2**: device configuration deleted.| 3579 3580**Error codes** 3581 3582For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3583 3584| **ID**| **Error Message**| 3585| -------- | -------- | 3586| 2501000 | Operation failed.| 3587 3588**Example** 3589```ts 3590import wifi from '@ohos.wifiManager'; 3591 3592let recvDeviceConfigChangeFunc = (result:number) => { 3593 console.info("Receive device config change event: " + result); 3594} 3595 3596// Register an event. 3597wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc); 3598 3599// Unregister an event. 3600wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc); 3601 3602``` 3603 3604## wifiManager.on('hotspotStateChange')<sup>9+</sup> 3605 3606on(type: "hotspotStateChange", callback: Callback<number>): void 3607 3608Subscribes to hotspot state changes. 3609 3610**Required permissions**: ohos.permission.GET_WIFI_INFO 3611 3612**System capability**: SystemCapability.Communication.WiFi.AP.Core 3613 3614**Parameters** 3615 3616| **Name**| **Type**| **Mandatory**| **Description**| 3617| -------- | -------- | -------- | -------- | 3618| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 3619| callback | Callback<number> | Yes| Callback invoked to return the hotspot state.| 3620 3621**Hotspot states** 3622 3623| **Value**| **Description**| 3624| -------- | -------- | 3625| 0 | Deactivated| 3626| 1 | Activated| 3627| 2 | Activating| 3628| 3 | Deactivating| 3629 3630**Error codes** 3631 3632For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3633 3634| **ID**| **Error Message**| 3635| -------- | -------- | 3636| 2601000 | Operation failed.| 3637 3638## wifiManager.off('hotspotStateChange')<sup>9+</sup> 3639 3640off(type: "hotspotStateChange", callback?: Callback<number>): void 3641 3642Unsubscribes from hotspot state changes. 3643 3644**Required permissions**: ohos.permission.GET_WIFI_INFO 3645 3646**System capability**: SystemCapability.Communication.WiFi.AP.Core 3647 3648**Parameters** 3649 3650| **Name**| **Type**| **Mandatory**| **Description**| 3651| -------- | -------- | -------- | -------- | 3652| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.| 3653| callback | Callback<number> | No| Callback for the hotspot state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3654 3655**Error codes** 3656 3657For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3658 3659| **ID**| **Error Message**| 3660| -------- | -------- | 3661| 2601000 | Operation failed.| 3662 3663**Example** 3664```ts 3665 import wifiManager from '@ohos.wifiManager'; 3666 3667 let recvHotspotStateChangeFunc = (result:number) => { 3668 console.info("Receive hotspot state change event: " + result); 3669 } 3670 3671 // Register an event. 3672 wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc); 3673 3674 // Unregister an event. 3675 wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc); 3676``` 3677 3678## wifiManager.on('hotspotStaJoin')<sup>9+</sup> 3679 3680on(type: "hotspotStaJoin", callback: Callback<StationInfo>): void 3681 3682Subscribes to the connection of an STA to a Wi-Fi hotspot. 3683 3684**System API**: This is a system API. 3685 3686**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 3687 3688**System capability**: SystemCapability.Communication.WiFi.AP.Core 3689 3690**Parameters** 3691 3692| **Name**| **Type**| **Mandatory**| **Description**| 3693| -------- | -------- | -------- | -------- | 3694| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.| 3695| callback | Callback<StationInfo> | Yes| Callback invoked immediately after an STA is connected to a Wi-Fi hotspot.| 3696 3697**Error codes** 3698 3699For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3700 3701| **ID**| **Error Message**| 3702| -------- | -------- | 3703| 2601000 | Operation failed.| 3704 3705## wifiManager.off('hotspotStaJoin')<sup>9+</sup> 3706 3707off(type: "hotspotStaJoin", callback?: Callback<StationInfo>): void 3708 3709Unsubscribes from the connection of an STA to a Wi-Fi hotspot. 3710 3711**System API**: This is a system API. 3712 3713**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 3714 3715**System capability**: SystemCapability.Communication.WiFi.AP.Core 3716 3717**Parameters** 3718 3719| **Name**| **Type**| **Mandatory**| **Description**| 3720| -------- | -------- | -------- | -------- | 3721| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.| 3722| callback | Callback<StationInfo> | No| Callback for the connection of an STA to a Wi-Fi hotspot.| 3723 3724**Error codes** 3725 3726For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3727 3728| **ID**| **Error Message**| 3729| -------- | -------- | 3730| 2601000 | Operation failed.| 3731 3732**Example** 3733```ts 3734import wifiManager from '@ohos.wifiManager'; 3735 3736let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => { 3737 console.info("Receive hotspot sta join event: " + result); 3738} 3739 3740// Register an event. 3741wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc); 3742 3743// Unregister an event. 3744wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc); 3745 3746``` 3747 3748## wifiManager.on('hotspotStaLeave')<sup>9+</sup> 3749 3750on(type: "hotspotStaLeave", callback: Callback<StationInfo>): void 3751 3752Subscribes to the disconnection of an STA from a Wi-Fi hotspot. 3753 3754**System API**: This is a system API. 3755 3756**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 3757 3758**System capability**: SystemCapability.Communication.WiFi.AP.Core 3759 3760**Parameters** 3761 3762| **Name**| **Type**| **Mandatory**| **Description**| 3763| -------- | -------- | -------- | -------- | 3764| type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.| 3765| callback | Callback<StationInf]> | Yes| Callback invoked immediately after an STA is disconnected from a Wi-Fi hotspot.| 3766 3767**Error codes** 3768 3769For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3770 3771| **ID**| **Error Message**| 3772| -------- | -------- | 3773| 2601000 | Operation failed.| 3774 3775## wifiManager.off('hotspotStaLeave')<sup>9+</sup> 3776 3777off(type: "hotspotStaLeave", callback?: Callback<StationInfo>): void 3778 3779Unsubscribes from the disconnection of an STA from a Wi-Fi hotspot. 3780 3781**System API**: This is a system API. 3782 3783**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 3784 3785**System capability**: SystemCapability.Communication.WiFi.AP.Core 3786 3787**Parameters** 3788 3789| **Name**| **Type**| **Mandatory**| **Description**| 3790| -------- | -------- | -------- | -------- | 3791| type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.| 3792| callback | Callback<StationInf]> | No| Callback for the disconnection of an STA from a Wi-Fi hotspot.| 3793 3794**Error codes** 3795 3796For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3797 3798| **ID**| **Error Message**| 3799| -------- | -------- | 3800| 2601000 | Operation failed.| 3801 3802**Example** 3803```ts 3804import wifiManager from '@ohos.wifiManager'; 3805 3806let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => { 3807 console.info("Receive hotspot sta leave event: " + result); 3808} 3809 3810// Register an event. 3811wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc); 3812 3813// Unregister an event. 3814wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc); 3815 3816``` 3817 3818## wifiManager.on('p2pStateChange')<sup>9+</sup> 3819 3820on(type: "p2pStateChange", callback: Callback<number>): void 3821 3822Subscribes to P2P state changes. 3823 3824**Required permissions**: ohos.permission.GET_WIFI_INFO 3825 3826**System capability**: SystemCapability.Communication.WiFi.P2P 3827 3828**Parameters** 3829 3830| **Name**| **Type**| **Mandatory**| **Description**| 3831| -------- | -------- | -------- | -------- | 3832| type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 3833| callback | Callback<number> | Yes| Callback invoked to return the P2P state change.| 3834 3835**P2P states** 3836 3837| **Value**| **Description**| 3838| -------- | -------- | 3839| 1 | Available| 3840| 2 | Opening| 3841| 3 | Opened| 3842| 4 | Closing| 3843| 5 | Closed| 3844 3845**Error codes** 3846 3847For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3848 3849| **ID**| **Error Message**| 3850| -------- | -------- | 3851| 2801000 | Operation failed.| 3852 3853## wifiManager.off('p2pStateChange')<sup>9+</sup> 3854 3855off(type: "p2pStateChange", callback?: Callback<number>): void 3856 3857Unsubscribes from P2P state changes. 3858 3859**Required permissions**: ohos.permission.GET_WIFI_INFO 3860 3861**System capability**: SystemCapability.Communication.WiFi.P2P 3862 3863**Parameters** 3864 3865| **Name**| **Type**| **Mandatory**| **Description**| 3866| -------- | -------- | -------- | -------- | 3867| type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.| 3868| callback | Callback<number> | No| Callback for the P2P state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3869 3870**Error codes** 3871 3872For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3873 3874| **ID**| **Error Message**| 3875| -------- | -------- | 3876| 2801000 | Operation failed.| 3877 3878**Example** 3879```ts 3880 import wifiManager from '@ohos.wifiManager'; 3881 3882 let recvP2pStateChangeFunc = (result:number) => { 3883 console.info("Receive p2p state change event: " + result); 3884 } 3885 3886 // Register an event. 3887 wifiManager.on("p2pStateChange", recvP2pStateChangeFunc); 3888 3889 // Unregister an event. 3890 wifiManager.off("p2pStateChange", recvP2pStateChangeFunc); 3891``` 3892 3893## wifiManager.on('p2pConnectionChange')<sup>9+</sup> 3894 3895on(type: "p2pConnectionChange", callback: Callback<WifiP2pLinkedInfo>): void 3896 3897Subscribes to P2P connection state changes. 3898 3899**Required permissions**: ohos.permission.GET_WIFI_INFO 3900 3901**System capability**: SystemCapability.Communication.WiFi.P2P 3902 3903**Parameters** 3904 3905| **Name**| **Type**| **Mandatory**| **Description**| 3906| -------- | -------- | -------- | -------- | 3907| type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 3908| callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | Yes| Callback invoked to return the P2P connection state change.| 3909 3910**Error codes** 3911 3912For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3913 3914| **ID**| **Error Message**| 3915| -------- | -------- | 3916| 2801000 | Operation failed.| 3917 3918## wifiManager.off('p2pConnectionChange')<sup>9+</sup> 3919 3920off(type: "p2pConnectionChange", callback?: Callback<WifiP2pLinkedInfo>): void 3921 3922Unsubscribes from P2P connection state changes. 3923 3924**Required permissions**: ohos.permission.GET_WIFI_INFO 3925 3926**System capability**: SystemCapability.Communication.WiFi.P2P 3927 3928**Parameters** 3929 3930| **Name**| **Type**| **Mandatory**| **Description**| 3931| -------- | -------- | -------- | -------- | 3932| type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.| 3933| callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | No| Callback for the P2P connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 3934 3935**Error codes** 3936 3937For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3938 3939| **ID**| **Error Message**| 3940| -------- | -------- | 3941| 2801000 | Operation failed.| 3942 3943**Example** 3944```ts 3945 import wifiManager from '@ohos.wifiManager'; 3946 3947 let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => { 3948 console.info("Receive p2p connection change event: " + result); 3949 } 3950 3951 // Register an event. 3952 wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc); 3953 3954 // Unregister an event. 3955 wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc); 3956``` 3957 3958## wifiManager.on('p2pDeviceChange')<sup>9+</sup> 3959 3960on(type: "p2pDeviceChange", callback: Callback<WifiP2pDevice>): void 3961 3962Subscribes to P2P device state changes. 3963 3964**Required permissions**: 3965 3966API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 3967 3968API version 10 and later : ohos.permission.GET_WIFI_INFO 3969 3970**System capability**: SystemCapability.Communication.WiFi.P2P 3971 3972**Parameters** 3973 3974| **Name**| **Type**| **Mandatory**| **Description**| 3975| -------- | -------- | -------- | -------- | 3976| type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 3977| callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | Yes| Callback invoked to return the device state change.| 3978 3979**Error codes** 3980 3981For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 3982 3983| **ID**| **Error Message**| 3984| -------- | -------- | 3985| 2801000 | Operation failed.| 3986 3987## wifiManager.off('p2pDeviceChange')<sup>9+</sup> 3988 3989off(type: "p2pDeviceChange", callback?: Callback<WifiP2pDevice>): void 3990 3991Unsubscribes from P2P device state changes. 3992 3993**Required permissions**: 3994 3995API version 9: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 3996 3997API version 10 and later: No permission is required. 3998 3999**System capability**: SystemCapability.Communication.WiFi.P2P 4000 4001**Parameters** 4002 4003| **Name**| **Type**| **Mandatory**| **Description**| 4004| -------- | -------- | -------- | -------- | 4005| type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.| 4006| callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | No| Callback for the P2P device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 4007 4008**Error codes** 4009 4010For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4011 4012| **ID**| **Error Message**| 4013| -------- | -------- | 4014| 2801000 | Operation failed.| 4015 4016**Example** 4017```ts 4018 import wifiManager from '@ohos.wifiManager'; 4019 4020 let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => { 4021 console.info("Receive p2p device change event: " + result); 4022 } 4023 4024 // Register an event. 4025 wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc); 4026 4027 // Unregister an event. 4028 wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc); 4029``` 4030 4031## wifiManager.on('p2pPeerDeviceChange')<sup>9+</sup> 4032 4033on(type: "p2pPeerDeviceChange", callback: Callback<WifiP2pDevice[]>): void 4034 4035Subscribes to P2P peer device state changes. 4036 4037**Required permissions**: 4038 4039API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 4040 4041API version 10 and later : ohos.permission.GET_WIFI_INFO 4042 4043**System capability**: SystemCapability.Communication.WiFi.P2P 4044 4045**Parameters** 4046 4047| **Name**| **Type**| **Mandatory**| **Description**| 4048| -------- | -------- | -------- | -------- | 4049| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 4050| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | Yes| Callback invoked to return the P2P peer device state change. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 4051 4052**Error codes** 4053 4054For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4055 4056| **ID**| **Error Message**| 4057| -------- | -------- | 4058| 2801000 | Operation failed.| 4059 4060## wifiManager.off('p2pPeerDeviceChange')<sup>9+</sup> 4061 4062off(type: "p2pPeerDeviceChange", callback?: Callback<WifiP2pDevice[]>): void 4063 4064Unsubscribes from P2P peer device state changes. 4065 4066**Required permissions**: 4067 4068API version 9: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 4069 4070API version 10 and later: No permission is required. 4071 4072**System capability**: SystemCapability.Communication.WiFi.P2P 4073 4074**Parameters** 4075 4076| **Name**| **Type**| **Mandatory**| **Description**| 4077| -------- | -------- | -------- | -------- | 4078| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.| 4079| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | No| Callback for the P2P peer device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered. If the application has the **ohos.permission.GET_WIFI_PEERS_MAC** permission, **deviceAddress** in the return value is a real device address; otherwise, **deviceAddress** is a random device address.| 4080 4081**Error codes** 4082 4083For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4084 4085| **ID**| **Error Message**| 4086| -------- | -------- | 4087| 2801000 | Operation failed.| 4088 4089**Example** 4090```ts 4091 import wifiManager from '@ohos.wifiManager'; 4092 4093 let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => { 4094 console.info("Receive p2p peer device change event: " + result); 4095 } 4096 4097 // Register an event. 4098 wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 4099 4100 // Unregister an event. 4101 wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); 4102``` 4103 4104## wifiManager.on('p2pPersistentGroupChange')<sup>9</sup> 4105 4106on(type: "p2pPersistentGroupChange", callback: Callback<void>): void 4107 4108Subscribes to P2P persistent group state changes. 4109 4110**Required permissions**: ohos.permission.GET_WIFI_INFO 4111 4112**System capability**: SystemCapability.Communication.WiFi.P2P 4113 4114**Parameters** 4115 4116| **Name**| **Type**| **Mandatory**| **Description**| 4117| -------- | -------- | -------- | -------- | 4118| type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 4119| callback | Callback<void> | Yes| Callback invoked to return the P2P persistent group state change.| 4120 4121**Error codes** 4122 4123For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4124 4125| **ID**| **Error Message**| 4126| -------- | -------- | 4127| 2801000 | Operation failed.| 4128 4129## wifiManager.off('p2pPersistentGroupChange')<sup>9</sup> 4130 4131off(type: "p2pPersistentGroupChange", callback?: Callback<void>): void 4132 4133Unsubscribes from P2P persistent group state changes. 4134 4135**Required permissions**: ohos.permission.GET_WIFI_INFO 4136 4137**System capability**: SystemCapability.Communication.WiFi.P2P 4138 4139**Parameters** 4140 4141| **Name**| **Type**| **Mandatory**| **Description**| 4142| -------- | -------- | -------- | -------- | 4143| type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.| 4144| callback | Callback<void> | No| Callback for the P2P persistent group state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 4145 4146**Error codes** 4147 4148For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4149 4150| **ID**| **Error Message**| 4151| -------- | -------- | 4152| 2801000 | Operation failed.| 4153 4154**Example** 4155```ts 4156 import wifiManager from '@ohos.wifiManager'; 4157 4158 let recvP2pPersistentGroupChangeFunc = (result:void) => { 4159 console.info("Receive p2p persistent group change event: " + result); 4160 } 4161 4162 // Register an event. 4163 wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 4164 4165 // Unregister an event. 4166 wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); 4167``` 4168 4169## wifiManager.on('p2pDiscoveryChange')<sup>9+</sup> 4170 4171on(type: "p2pDiscoveryChange", callback: Callback<number>): void 4172 4173Subscribes to P2P device discovery state changes. 4174 4175**Required permissions**: ohos.permission.GET_WIFI_INFO 4176 4177**System capability**: SystemCapability.Communication.WiFi.P2P 4178 4179**Parameters** 4180 4181| **Name**| **Type**| **Mandatory**| **Description**| 4182| -------- | -------- | -------- | -------- | 4183| type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 4184| callback | Callback<number> | Yes| Callback invoked to return the P2P device discovery state change.| 4185 4186**P2P discovered device states** 4187 4188| **Value**| **Description**| 4189| -------- | -------- | 4190| 0 | Initial state.| 4191| 1 | Discovered.| 4192 4193**Error codes** 4194 4195For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4196 4197| **ID**| **Error Message**| 4198| -------- | -------- | 4199| 2801000 | Operation failed.| 4200 4201## wifiManager.off('p2pDiscoveryChange')<sup>9+</sup> 4202 4203off(type: "p2pDiscoveryChange", callback?: Callback<number>): void 4204 4205Unsubscribes from P2P device discovery state changes. 4206 4207**Required permissions**: ohos.permission.GET_WIFI_INFO 4208 4209**System capability**: SystemCapability.Communication.WiFi.P2P 4210 4211**Parameters** 4212 4213| **Name**| **Type**| **Mandatory**| **Description**| 4214| -------- | -------- | -------- | -------- | 4215| type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.| 4216| callback | Callback<number> | No| Callback for the P2P device discovery state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| 4217 4218**Error codes** 4219 4220For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). 4221 4222| **ID**| **Error Message**| 4223| -------- | -------- | 4224| 2801000 | Operation failed.| 4225 4226**Example** 4227```ts 4228 import wifiManager from '@ohos.wifiManager'; 4229 4230 let recvP2pDiscoveryChangeFunc = (result:number) => { 4231 console.info("Receive p2p discovery change event: " + result); 4232 } 4233 4234 // Register an event. 4235 wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 4236 4237 // Unregister an event. 4238 wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc); 4239``` 4240