1# @ohos.wifiManager (WLAN) (System API) 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> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.wifiManager (WLAN)](js-apis-wifiManager.md). 8 9## Modules to Import 10 11```ts 12import { wifiManager } from '@kit.ConnectivityKit'; 13``` 14 15## wifiManager.enableWifi<sup>9+</sup> 16 17enableWifi(): void 18 19Enables WLAN. This is an asynchronous API. You need to register a callback for the **wifiStateChange** event to check whether WLAN is successfully enabled. 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](errorcode-wifi.md). 30 31| **ID**| **Error Message**| 32| -------- | -------- | 33| 201 | Permission denied. | 34| 202 | System API is not allowed called by Non-system application. | 35| 801 | Capability not supported. | 36| 2501000 | Operation failed.| 37| 2501003 | Operation failed because the service is being closed. | 38 39**Example** 40 41```ts 42 import { wifiManager } from '@kit.ConnectivityKit'; 43 44 try { 45 wifiManager.enableWifi(); 46 }catch(error){ 47 console.error("failed:" + JSON.stringify(error)); 48 } 49``` 50 51## wifiManager.disableWifi<sup>9+</sup> 52 53disableWifi(): void 54 55Disables WLAN. This is an asynchronous API. You need to register a callback for the **wifiStateChange** event to check whether WLAN is successfully disabled. 56 57**System API**: This is a system API. 58 59**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 60 61**System capability**: SystemCapability.Communication.WiFi.STA 62 63**Error codes** 64 65For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 66 67| **ID**| **Error Message**| 68| -------- | -------- | 69| 201 | Permission denied. | 70| 202 | System API is not allowed called by Non-system application. | 71| 801 | Capability not supported. | 72| 2501000 | Operation failed.| 73| 2501004 | Operation failed because the service is being opened. | 74 75**Example** 76 77```ts 78 import { wifiManager } from '@kit.ConnectivityKit'; 79 80 try { 81 wifiManager.disableWifi(); 82 }catch(error){ 83 console.error("failed:" + JSON.stringify(error)); 84 } 85``` 86 87## wifiManager.enableSemiWifi<sup>12+</sup> 88 89enableSemiWifi(): void 90 91Enables WLAN partially, that is, enables P2P and Huawei Magneto Link (HML) while disabling STA. You need to register a callback for the **wifiStateChange** event to return the operation result. 92 93**System API**: This is a system API. 94 95**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 96 97**System capability**: SystemCapability.Communication.WiFi.STA 98 99**Error codes** 100 101For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 102 103| **ID**| **Error Message**| 104| -------- | -------- | 105| 201 | Permission denied. | 106| 202 | System API is not allowed called by Non-system application. | 107| 801 | Capability not supported. | 108| 2501000 | Operation failed.| 109| 2501004 | Operation failed because the service is being opened. | 110 111**Example** 112 113```ts 114 import { wifiManager } from '@kit.ConnectivityKit'; 115 116 try { 117 wifiManager.enableSemiWifi(); 118 } catch(error) { 119 console.error("failed:" + JSON.stringify(error)); 120 } 121``` 122 123## wifiManager.startScan<sup>10+</sup> 124 125startScan(): void 126 127**System API**: This is a system API. 128 129Starts a scan for WLAN. 130 131**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 132 133**System capability**: SystemCapability.Communication.WiFi.STA 134 135**Error codes** 136 137For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 138 139| **ID**| **Error Message**| 140| -------- | -------- | 141| 201 | Permission denied. | 142| 202 | System API is not allowed called by Non-system application. | 143| 801 | Capability not supported. | 144| 2501000 | Operation failed.| 145 146**Example** 147 148```ts 149 import { wifiManager } from '@kit.ConnectivityKit'; 150 151 try { 152 wifiManager.startScan(); 153 }catch(error){ 154 console.error("failed:" + JSON.stringify(error)); 155 } 156``` 157 158## wifiManager.setScanAlwaysAllowed<sup>10+</sup> 159 160setScanAlwaysAllowed(isScanAlwaysAllowed: boolean): void 161 162Sets whether scan is always allowed. 163 164**System API**: This is a system API. 165 166**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 167 168**System capability**: SystemCapability.Communication.WiFi.STA 169 170**Parameters** 171 172| **Name**| **Type**| **Mandatory**| **Description**| 173| -------- | -------- | -------- | -------- | 174| isScanAlwaysAllowed | boolean | Yes| Whether scan is always allowed.| 175 176**Error codes** 177 178For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 179 180| **ID**| **Error Message**| 181 | -------- | -------- | 182| 201 | Permission denied. | 183| 202 | System API is not allowed called by Non-system application. | 184| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 185| 801 | Capability not supported. | 186| 2501000 | Operation failed.| 187 188```ts 189 import { wifiManager } from '@kit.ConnectivityKit'; 190 191 try { 192 let isScanAlwaysAllowed = true; 193 wifiManager.setScanAlwaysAllowed(isScanAlwaysAllowed); 194 }catch(error){ 195 console.error("failed:" + JSON.stringify(error)); 196 } 197``` 198 199## wifiManager.getScanAlwaysAllowed<sup>10+</sup> 200 201getScanAlwaysAllowed(): boolean 202 203Obtains whether scan is always allowed. 204 205**System API**: This is a system API. 206 207**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 208 209**System capability**: SystemCapability.Communication.WiFi.STA 210 211**Return value** 212 213| **Type**| **Description**| 214| -------- | -------- | 215| boolean| Whether scan is always allowed. The value **true** means scan is allowed; the value **false** means the opposite.| 216 217**Error codes** 218 219For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 220 221| **ID**| **Error Message**| 222| -------- | -------- | 223| 201 | Permission denied. | 224| 202 | System API is not allowed called by Non-system application. | 225| 801 | Capability not supported. | 226| 2501000 | Operation failed.| 227 228**Example** 229 230```ts 231 import { wifiManager } from '@kit.ConnectivityKit'; 232 233 try { 234 let isScanAlwaysAllowed = wifiManager.getScanAlwaysAllowed(); 235 console.info("isScanAlwaysAllowed:" + isScanAlwaysAllowed); 236 }catch(error){ 237 console.error("failed:" + JSON.stringify(error)); 238 } 239``` 240 241## wifiManager.addDeviceConfig<sup>9+</sup> 242 243addDeviceConfig(config: WifiDeviceConfig): Promise<number> 244 245Adds network configuration. This API uses a promise to return the result. 246 247**System API**: This is a system API. 248 249**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 250 251**System capability**: SystemCapability.Communication.WiFi.STA 252 253**Parameters** 254 255| **Name**| **Type**| **Mandatory**| **Description**| 256| -------- | -------- | -------- | -------- | 257| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 258 259**Return value** 260 261 | **Type**| **Description**| 262 | -------- | -------- | 263 | Promise<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.| 264 265**Error codes** 266 267For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 268 269| **ID**| **Error Message**| 270| -------- | -------- | 271| 201 | Permission denied. | 272| 202 | System API is not allowed called by Non-system application. | 273| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 274| 801 | Capability not supported. | 275| 2501000 | Operation failed.| 276| 2501001 | Wi-Fi STA disabled. | 277 278**Example** 279 280```ts 281 import { wifiManager } from '@kit.ConnectivityKit'; 282 283 try { 284 let config:wifiManager.WifiDeviceConfig = { 285 ssid : "****", 286 preSharedKey : "****", 287 securityType : 0 288 } 289 wifiManager.addDeviceConfig(config).then(result => { 290 console.info("result:" + JSON.stringify(result)); 291 }).catch((err:number) => { 292 console.error("failed:" + JSON.stringify(err)); 293 }); 294 }catch(error){ 295 console.error("failed:" + JSON.stringify(error)); 296 } 297``` 298 299## WifiDeviceConfig<sup>9+</sup> 300 301Represents the WLAN configuration. 302 303**System capability**: SystemCapability.Communication.WiFi.STA 304 305 306| **Name**| **Type**| **Readable**| **Writable**| **Description**| 307| -------- | -------- | -------- | -------- | -------- | 308| creatorUid | number | Yes| No| ID of the creator.<br> **System API**: This is a system API.| 309| disableReason | number | Yes| No| Reason for disabling WLAN.<br> **System API**: This is a system API.| 310| netId | number | Yes| No| Network ID.<br> **System API**: This is a system API.| 311| randomMacType | number | Yes| No| MAC address type. <br>The value **0** indicates random MAC address, and **1** indicates device MAC address.<br> **System API**: This is a system API.| 312| randomMacAddr | string | Yes| No| MAC address.<br> **System API**: This is a system API.| 313| ipType | [IpType](#iptype9) | Yes| No| IP address type.<br> **System API**: This is a system API.| 314| staticIp | [IpConfig](#ipconfig9) | Yes| No| Static IP address information.<br> **System API**: This is a system API.| 315| proxyConfig<sup>10+</sup> | [WifiProxyConfig](#wifiproxyconfig10) | Yes| No| Proxy configuration.<br> **System API**: This is a system API.| 316| configStatus<sup>12+</sup> | number | Yes| No| Status indicating whether the current network can be selected.<br> **System API**: This is a system API.| 317 318## IpType<sup>9+</sup> 319 320Enumerates the IP address types. 321 322**System API**: This is a system API. 323 324**System capability**: SystemCapability.Communication.WiFi.STA 325 326 327| Name| Value| Description| 328| -------- | -------- | -------- | 329| STATIC | 0 | Static IP address.| 330| DHCP | 1 | IP address allocated by DHCP.| 331| UNKNOWN | 2 | Not specified.| 332 333 334## IpConfig<sup>9+</sup> 335 336Represents IP configuration information. 337 338**System API**: This is a system API. 339 340**System capability**: SystemCapability.Communication.WiFi.STA 341 342| **Name**| **Type**| **Readable**| **Writable**| **Description**| 343| -------- | -------- | -------- | -------- | -------- | 344| ipAddress | number | Yes| No| IP address.| 345| gateway | number | Yes| No| Gateway.| 346| prefixLength | number | Yes| No| Subnet mask.| 347| dnsServers | number[] | Yes| No| Domain name server (DNS) information.| 348| domains | Array<string> | Yes| No| Domain information.| 349 350 351## WifiProxyConfig<sup>10+</sup> 352 353Represents the Wi-Fi proxy configuration. 354 355**System API**: This is a system API. 356 357**System capability**: SystemCapability.Communication.WiFi.STA 358 359| **Name**| **Type**| **Readable**| **Writable**| **Description**| 360| -------- | -------- | -------- | -------- | -------- | 361| proxyMethod | ProxyMethod | Yes| No| Proxy method.| 362| pacWebAddress | string | Yes| No| PAC web address of the proxy automatically configured.| 363| serverHostName | string | Yes| No| Server host name of the proxy manually configured.| 364| serverPort | number | Yes| No| Server port of the proxy manually configured.| 365| exclusionObjects | string | Yes| No| Excluded objects of the manually configured proxy. Multiple objects are separated by commas (,).| 366 367## ProxyMethod<sup>10+</sup> 368 369Enumerates the Wi-Fi proxy methods. 370 371**System API**: This is a system API. 372 373**System capability**: SystemCapability.Communication.WiFi.STA 374 375| Name| Value| Description| 376| -------- | -------- | -------- | 377| METHOD_NONE | 0 | No proxy.| 378| METHOD_AUTO | 1 | Use an automatically configured proxy.| 379| METHOD_MANUAL | 2 | Use a manually configured proxy.| 380 381## wifiManager.addDeviceConfig<sup>9+</sup> 382 383addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 384 385Adds network configuration. This API uses an asynchronous callback to return the result. 386 387**System API**: This is a system API. 388 389**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 390 391**System capability**: SystemCapability.Communication.WiFi.STA 392 393**Parameters** 394 395| **Name**| **Type**| **Mandatory**| **Description**| 396| -------- | -------- | -------- | -------- | 397| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.| 398| callback | AsyncCallback<number> | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If the operation fails, **error** is not **0**.| 399 400**Error codes** 401 402For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 403 404| **ID**| **Error Message**| 405| -------- | -------- | 406| 201 | Permission denied. | 407| 202 | System API is not allowed called by Non-system application. | 408| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 409| 801 | Capability not supported. | 410| 2501000 | Operation failed.| 411| 2501001 | Wi-Fi STA disabled. | 412 413**Example** 414 415```ts 416 import { wifiManager } from '@kit.ConnectivityKit'; 417 418 try { 419 let config:wifiManager.WifiDeviceConfig = { 420 ssid : "****", 421 preSharedKey : "****", 422 securityType : 0 423 } 424 wifiManager.addDeviceConfig(config,(error,result) => { 425 console.info("result:" + JSON.stringify(result)); 426 }); 427 }catch(error){ 428 console.error("failed:" + JSON.stringify(error)); 429 } 430``` 431 432 433## wifiManager.connectToNetwork<sup>9+</sup> 434 435connectToNetwork(networkId: number): void 436 437Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first. 438 439**System API**: This is a system API. 440 441**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 442 443**System capability**: SystemCapability.Communication.WiFi.STA 444 445**Parameters** 446 447 | **Name**| **Type**| **Mandatory**| **Description**| 448 | -------- | -------- | -------- | -------- | 449 | networkId | number | Yes| Network configuration ID.| 450 451**Error codes** 452 453For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 454 455| **ID**| **Error Message**| 456| -------- | -------- | 457| 201 | Permission denied. | 458| 202 | System API is not allowed called by Non-system application. | 459| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 460| 801 | Capability not supported. | 461| 2501000 | Operation failed.| 462| 2501001 | Wi-Fi STA disabled.| 463 464**Example** 465 466```ts 467 import { wifiManager } from '@kit.ConnectivityKit'; 468 469 try { 470 let networkId = 0; 471 wifiManager.connectToNetwork(networkId); 472 }catch(error){ 473 console.error("failed:" + JSON.stringify(error)); 474 } 475``` 476 477## wifiManager.connectToDevice<sup>9+</sup> 478 479connectToDevice(config: WifiDeviceConfig): void 480 481Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first. 482 483**System API**: This is a system API. 484 485**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 486 487**System capability**: 488 SystemCapability.Communication.WiFi.STA 489 490**Parameters** 491 492| **Name**| **Type**| **Mandatory**| **Description**| 493| -------- | -------- | -------- | -------- | 494| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| Configuration of the WLAN to connect. The default **bssidType** is random device address.| 495 496**Error codes** 497 498For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 499 500| **ID**| **Error Message**| 501| -------- | -------- | 502| 201 | Permission denied. | 503| 202 | System API is not allowed called by Non-system application. | 504| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 505| 801 | Capability not supported. | 506| 2501000 | Operation failed.| 507| 2501001 | Wi-Fi STA disabled.| 508 509**Example** 510```ts 511 import { wifiManager } from '@kit.ConnectivityKit'; 512 513 try { 514 let config:wifiManager.WifiDeviceConfig = { 515 ssid : "****", 516 preSharedKey : "****", 517 securityType : 3 518 } 519 wifiManager.connectToDevice(config); 520 521 }catch(error){ 522 console.error("failed:" + JSON.stringify(error)); 523 } 524``` 525 526## wifiManager.disconnect<sup>9+</sup> 527 528disconnect(): void 529 530Disconnects the network. 531 532**System API**: This is a system API. 533 534**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 535 536**System capability**: 537 SystemCapability.Communication.WiFi.STA 538 539**Error codes** 540 541For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 542 543| **ID**| **Error Message**| 544| -------- | -------- | 545| 201 | Permission denied. | 546| 202 | System API is not allowed called by Non-system application. | 547| 801 | Capability not supported. | 548| 2501000 | Operation failed.| 549| 2501001 | Wi-Fi STA disabled. | 550 551**Example** 552```ts 553 import { wifiManager } from '@kit.ConnectivityKit'; 554 555 try { 556 wifiManager.disconnect(); 557 }catch(error){ 558 console.error("failed:" + JSON.stringify(error)); 559 } 560``` 561 562 563## WifiLinkedInfo<sup>9+</sup> 564 565Represents the WLAN connection information. 566 567**System capability**: SystemCapability.Communication.WiFi.STA 568 569| Name| Type| Readable| Writable| Description| 570| -------- | -------- | -------- | -------- | -------- | 571| networkId | number | Yes| No| Network configuration ID.<br> **System API**: This is a system API.| 572| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.| 573| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.| 574| suppState | [SuppState](#suppstate9) | Yes| No| Supplicant state.<br> **System API**: This is a system API.| 575 576 577 578## SuppState<sup>9+</sup> 579 580Enumerates the supplicant states. 581 582**System API**: This is a system API. 583 584**System capability**: SystemCapability.Communication.WiFi.STA 585 586| Name| Value| Description| 587| -------- | -------- | -------- | 588| DISCONNECTED | 0 | The supplicant is disconnected from the AP.| 589| INTERFACE_DISABLED | 1 | The network interface is disabled.| 590| INACTIVE | 2 | The supplicant is inactive.| 591| SCANNING | 3 | The supplicant is scanning for a WLAN connection.| 592| AUTHENTICATING | 4 | The supplicant is being authenticated.| 593| ASSOCIATING | 5 | The supplicant is being associated with an AP.| 594| ASSOCIATED | 6 | The supplicant is associated with an AP.| 595| FOUR_WAY_HANDSHAKE | 7 | A four-way handshake is being performed for the supplicant.| 596| GROUP_HANDSHAKE | 8 | A group handshake is being performed for the supplicant.| 597| COMPLETED | 9 | The authentication is complete.| 598| UNINITIALIZED | 10 | The supplicant failed to set up the connection.| 599| INVALID | 11 | Invalid value.| 600 601 602## wifiManager.getSupportedFeatures<sup>9+</sup> 603 604getSupportedFeatures(): number 605 606Obtains the features supported by this device. 607 608**System API**: This is a system API. 609 610**Required permissions**: ohos.permission.GET_WIFI_INFO 611 612**System capability**: SystemCapability.Communication.WiFi.Core 613 614**Return value** 615 616 | **Type**| **Description**| 617 | -------- | -------- | 618 | number | Feature value. | 619 620**Feature IDs** 621 622| Value| Description| 623| -------- | -------- | 624| 0x0001 | WLAN infrastructure mode| 625| 0x0002 | 5 GHz feature| 626| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature| 627| 0x0008 | Wi-Fi Direct| 628| 0x0010 | SoftAP| 629| 0x0040 | Wi-Fi Aware| 630| 0x8000 | WLAN AP/STA concurrency| 631| 0x8000000 | WPA3 Personal (WPA-3 SAE)| 632| 0x10000000 | WPA3-Enterprise Suite B | 633| 0x20000000 | Enhanced open feature| 634 635**Error codes** 636 637For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 638 639| **ID**| **Error Message**| 640| -------- | -------- | 641| 201 | Permission denied. | 642| 202 | System API is not allowed called by Non-system application. | 643| 801 | Capability not supported. | 644| 2401000 | Operation failed.| 645 646**Example** 647```ts 648 import { wifiManager } from '@kit.ConnectivityKit'; 649 650 try { 651 let ret = wifiManager.getSupportedFeatures(); 652 console.info("supportedFeatures:" + ret); 653 }catch(error){ 654 console.error("failed:" + JSON.stringify(error)); 655 } 656 657``` 658 659 660## wifiManager.getDeviceMacAddress<sup>9+</sup> 661 662getDeviceMacAddress(): string[] 663 664Obtains the device MAC address. 665 666**System API**: This is a system API. 667 668**Required permissions**: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications) 669 670**System capability**: SystemCapability.Communication.WiFi.STA 671 672**Return value** 673 674 | **Type**| **Description**| 675 | -------- | -------- | 676 | string[] | MAC address obtained.| 677 678**Error codes** 679 680For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 681 682| **ID**| **Error Message**| 683| -------- | -------- | 684| 201 | Permission denied. | 685| 202 | System API is not allowed called by Non-system application. | 686| 801 | Capability not supported. | 687| 2501000 | Operation failed.| 688| 2501001 | Wi-Fi STA disabled.| 689 690**Example** 691```ts 692 import { wifiManager } from '@kit.ConnectivityKit'; 693 694 try { 695 let ret = wifiManager.getDeviceMacAddress(); 696 console.info("deviceMacAddress:" + JSON.stringify(ret)); 697 }catch(error){ 698 console.error("failed:" + JSON.stringify(error)); 699 } 700 701``` 702 703## wifiManager.getWifiDetailState<sup>12+</sup> 704 705getWifiDetailState(): WifiDetailState 706 707Obtains the Wi-Fi state. 708 709**System API**: This is a system API. 710 711**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 712 713**System capability**: SystemCapability.Communication.WiFi.STA 714 715**Return value** 716 717 | **Type**| **Description**| 718 | -------- | -------- | 719 | WifiDetailState | Wi-Fi state obtained.| 720 721**Error codes** 722 723For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 724 725| **ID**| **Error Message**| 726| -------- | -------- | 727| 201 | Permission denied. | 728| 202 | System API is not allowed called by Non-system application. | 729| 801 | Capability not supported. | 730| 2501000 | Operation failed.| 731 732**Example** 733```ts 734 import { wifiManager } from '@kit.ConnectivityKit'; 735 736 try { 737 let ret = wifiManager.getWifiDetailState(); 738 console.info("wifiDetailState:" + ret); 739 } catch(error) { 740 console.error("failed:" + JSON.stringify(error)); 741 } 742 743``` 744 745## WifiDetailState<sup>12+</sup> 746 747Enumerates Wi-Fi states. 748 749**System API**: This is a system API. 750 751**System capability**: SystemCapability.Communication.WiFi.STA 752 753| Name| Value| Description| 754| -------- | -------- | -------- | 755| UNKNOWN | -1 | Unidentified.| 756| INACTIVE | 0 | Inactive.| 757| ACTIVATED | 1 | Activated.| 758| ACTIVATING | 2 | Activating.| 759| DEACTIVATING | 3 | Deactivating| 760| SEMI_ACTIVATING | 4 | Partially activating.| 761| SEMI_ACTIVE | 5 | partially activated.| 762 763 764## wifiManager.reassociate<sup>9+</sup> 765 766reassociate(): void 767 768Re-associates with the network. 769 770**System API**: This is a system API. 771 772**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 773 774**System capability**: SystemCapability.Communication.WiFi.STA 775 776**Error codes** 777 778For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 779 780| **ID**| **Error Message**| 781| -------- | -------- | 782| 201 | Permission denied. | 783| 202 | System API is not allowed called by Non-system application. | 784| 801 | Capability not supported. | 785| 2501000 | Operation failed.| 786| 2501001 | Wi-Fi STA disabled.| 787 788**Example** 789```ts 790 import { wifiManager } from '@kit.ConnectivityKit'; 791 792 try { 793 wifiManager.reassociate(); 794 }catch(error){ 795 console.error("failed:" + JSON.stringify(error)); 796 } 797``` 798 799## wifiManager.reconnect<sup>9+</sup> 800 801reconnect(): void 802 803Reconnects to the network. 804 805**System API**: This is a system API. 806 807**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 808 809**System capability**: SystemCapability.Communication.WiFi.STA 810 811**Error codes** 812 813For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 814 815| **ID**| **Error Message**| 816| -------- | -------- | 817| 201 | Permission denied. | 818| 202 | System API is not allowed called by Non-system application. | 819| 801 | Capability not supported. | 820| 2501000 | Operation failed.| 821| 2501001 | Wi-Fi STA disabled.| 822 823**Example** 824```ts 825 import { wifiManager } from '@kit.ConnectivityKit'; 826 827 try { 828 wifiManager.reconnect(); 829 }catch(error){ 830 console.error("failed:" + JSON.stringify(error)); 831 } 832``` 833 834## wifiManager.getDeviceConfigs<sup>9+</sup> 835 836getDeviceConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig9)> 837 838Obtains network configuration. 839 840**System API**: This is a system API. 841 842**Required permissions**: 843 844API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.GET_WIFI_CONFIG 845 846API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 847 848**System capability**: SystemCapability.Communication.WiFi.STA 849 850**Return value** 851 852 | **Type**| **Description**| 853 | -------- | -------- | 854 | Array<[WifiDeviceConfig](#wifideviceconfig9)> | Array of network configuration obtained.| 855 856**Error codes** 857 858For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 859 860| **ID**| **Error Message**| 861| -------- | -------- | 862| 201 | Permission denied. | 863| 202 | System API is not allowed called by Non-system application. | 864| 801 | Capability not supported. | 865| 2501000 | Operation failed.| 866 867**Example** 868```ts 869 import { wifiManager } from '@kit.ConnectivityKit'; 870 871 try { 872 let configs = wifiManager.getDeviceConfigs(); 873 console.info("configs:" + JSON.stringify(configs)); 874 }catch(error){ 875 console.error("failed:" + JSON.stringify(error)); 876 } 877``` 878 879## wifiManager.updateNetwork<sup>9+</sup> 880 881updateNetwork(config: WifiDeviceConfig): number 882 883Updates network configuration. 884 885**System API**: This is a system API. 886 887**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 888 889**System capability**: SystemCapability.Communication.WiFi.STA 890 891**Parameters** 892 893 | **Name**| **Type**| **Mandatory**| **Description**| 894 | -------- | -------- | -------- | -------- | 895 | config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| New WLAN configuration.| 896 897**Return value** 898 899 | **Type**| **Description**| 900 | -------- | -------- | 901 | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| 902 903**Error codes** 904 905For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 906 907| **ID**| **Error Message**| 908| -------- | -------- | 909| 201 | Permission denied. | 910| 202 | System API is not allowed called by Non-system application. | 911| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 912| 801 | Capability not supported. | 913| 2501000 | Operation failed.| 914| 2501001 | Wi-Fi STA disabled. | 915 916**Example** 917```ts 918 import { wifiManager } from '@kit.ConnectivityKit'; 919 920 try { 921 let config:wifiManager.WifiDeviceConfig = { 922 ssid : "****", 923 preSharedKey : "****", 924 securityType : 3 925 } 926 let ret = wifiManager.updateNetwork(config); 927 console.info("ret:" + ret); 928 }catch(error){ 929 console.error("failed:" + JSON.stringify(error)); 930 } 931``` 932 933## wifiManager.disableNetwork<sup>9+</sup> 934 935disableNetwork(netId: number): void 936 937Disables network configuration. 938 939**System API**: This is a system API. 940 941**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 942 943**System capability**: SystemCapability.Communication.WiFi.STA 944 945**Parameters** 946 947 | **Name**| **Type**| **Mandatory**| **Description**| 948 | -------- | -------- | -------- | -------- | 949 | netId | number | Yes| ID of the network configuration to disable.| 950 951**Error codes** 952 953For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 954 955| **ID**| **Error Message**| 956| -------- | -------- | 957| 201 | Permission denied. | 958| 202 | System API is not allowed called by Non-system application. | 959| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 960| 801 | Capability not supported. | 961| 2501000 | Operation failed.| 962| 2501001 | Wi-Fi STA disabled. | 963 964**Example** 965```ts 966 import { wifiManager } from '@kit.ConnectivityKit'; 967 968 try { 969 let netId = 0; 970 wifiManager.disableNetwork(netId); 971 }catch(error){ 972 console.error("failed:" + JSON.stringify(error)); 973 } 974``` 975 976## wifiManager.removeAllNetwork<sup>9+</sup> 977 978removeAllNetwork(): void 979 980Removes the configuration of all networks. 981 982**System API**: This is a system API. 983 984**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 985 986**System capability**: SystemCapability.Communication.WiFi.STA 987 988**Error codes** 989 990For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 991 992| **ID**| **Error Message**| 993| -------- | -------- | 994| 201 | Permission denied. | 995| 202 | System API is not allowed called by Non-system application. | 996| 801 | Capability not supported. | 997| 2501000 | Operation failed.| 998| 2501001 | Wi-Fi STA disabled. | 999 1000**Example** 1001```ts 1002 import { wifiManager } from '@kit.ConnectivityKit'; 1003 1004 try { 1005 wifiManager.removeAllNetwork(); 1006 }catch(error){ 1007 console.error("failed:" + JSON.stringify(error)); 1008 } 1009``` 1010 1011## wifiManager.removeDevice<sup>9+</sup> 1012 1013removeDevice(id: number): void 1014 1015Removes the specified network configuration. 1016 1017**System API**: This is a system API. 1018 1019**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1020 1021**System capability**: SystemCapability.Communication.WiFi.STA 1022 1023**Parameters** 1024 1025 | **Name**| **Type**| **Mandatory**| **Description**| 1026 | -------- | -------- | -------- | -------- | 1027| id | number | Yes| ID of the network configuration to remove.| 1028 1029**Error codes** 1030 1031For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1032 1033| **ID**| **Error Message**| 1034| -------- | -------- | 1035| 201 | Permission denied. | 1036| 202 | System API is not allowed called by Non-system application. | 1037| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1038| 801 | Capability not supported. | 1039| 2501000 | Operation failed.| 1040| 2501001 | Wi-Fi STA disabled. | 1041 1042**Example** 1043```ts 1044 import { wifiManager } from '@kit.ConnectivityKit'; 1045 1046 try { 1047 let id = 0; 1048 wifiManager.removeDevice(id); 1049 }catch(error){ 1050 console.error("failed:" + JSON.stringify(error)); 1051 } 1052``` 1053 1054## wifiManager.get5GChannelList<sup>10+</sup> 1055 1056get5GChannelList(): Array<number> 1057 1058Obtains the list of 5 GHz channels supported by this device. 1059 1060**System API**: This is a system API. 1061 1062**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1063 1064**System capability**: SystemCapability.Communication.WiFi.STA 1065 1066**Return value** 1067 1068 | **Type**| **Description**| 1069 | -------- | -------- | 1070 | Array<number> | List of 5 GHz channels supported by the device.| 1071 1072**Error codes** 1073 1074For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1075 1076| **ID**| **Error Message**| 1077| -------- | -------- | 1078| 201 | Permission denied. | 1079| 202 | System API is not allowed called by Non-system application. | 1080| 801 | Capability not supported. | 1081| 2501000 | Operation failed.| 1082 1083**Example** 1084```ts 1085 import { wifiManager } from '@kit.ConnectivityKit'; 1086 1087 try { 1088 let channelList = wifiManager.get5GChannelList(); 1089 console.info("channelList:" + JSON.stringify(channelList)); 1090 }catch(error){ 1091 console.error("failed:" + JSON.stringify(error)); 1092 } 1093``` 1094## wifiManager.getDisconnectedReason<sup>10+</sup> 1095 1096getDisconnectedReason(): DisconnectedReason 1097 1098Obtains the reason of the latest disconnection. 1099 1100**System API**: This is a system API. 1101 1102**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1103 1104**System capability**: SystemCapability.Communication.WiFi.STA 1105 1106**Error codes** 1107 1108For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1109 1110| **ID**| **Error Message**| 1111| -------- | -------- | 1112| 201 | Permission denied. | 1113| 801 | Capability not supported. | 1114| 2501000 | Operation failed.| 1115 1116**Return value** 1117 1118| **Type**| **Description**| 1119| -------- | -------- | 1120| [DisconnectedReason](#disconnectedreason-10) | Returns the reason of the latest disconnection obtained.| 1121 1122**Example** 1123```ts 1124 import { wifiManager } from '@kit.ConnectivityKit'; 1125 1126 try { 1127 let disconnectedReason = wifiManager.getDisconnectedReason(); 1128 console.info("disconnectedReason:" + disconnectedReason); 1129 }catch(error){ 1130 console.error("failed:" + JSON.stringify(error)); 1131 } 1132``` 1133 1134## DisconnectedReason <sup>10+</sup> 1135 1136Enumerates the Wi-Fi disconnection reasons. 1137 1138**System API**: This is a system API. 1139 1140**System capability**: SystemCapability.Communication.WiFi.STA 1141 1142| Name| Value| Description| 1143| -------- | -------- | -------- | 1144| DISC_REASON_DEFAULT | 0 | Default reason.| 1145| DISC_REASON_WRONG_PWD | 1 | Incorrect password.| 1146| DISC_REASON_CONNECTION_FULL | 2 | The number of connections to the router has reached the limit.| 1147 1148## wifiManager.startPortalCertification<sup>11+</sup> 1149 1150startPortalCertification(): void 1151 1152**System API**: This is a system API. 1153 1154Starts portal certification. 1155 1156**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 1157 1158**System capability**: SystemCapability.Communication.WiFi.STA 1159 1160**Error codes** 1161 1162For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1163 1164| **ID**| **Error Message**| 1165| -------- | -------- | 1166| 201 | Permission denied. | 1167| 202 | System API is not allowed called by Non-system application. | 1168| 801 | Capability not supported. | 1169| 2501000 | Operation failed.| 1170| 2501001 | Wi-Fi STA disabled. | 1171 1172**Example** 1173 1174```ts 1175 import { wifiManager } from '@kit.ConnectivityKit'; 1176 1177 try { 1178 wifiManager.startPortalCertification(); 1179 }catch(error){ 1180 console.error("failed:" + JSON.stringify(error)); 1181 } 1182``` 1183 1184## wifiManager.enableHiLinkHandshake<sup>12+</sup> 1185 1186enableHiLinkHandshake(isHiLinkEnable: boolean, bssid: string, config: WifiDeviceConfig): void 1187 1188**System API**: This is a system API. 1189 1190Enables or disables HiLink. 1191 1192**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 1193 1194**System capability**: SystemCapability.Communication.WiFi.STA 1195 1196**Parameters** 1197 1198| **Name**| **Type**| **Mandatory**| **Description**| 1199| -------- | -------- | -------- | -------- | 1200| isHiLinkEnable | boolean | Yes| Whether to enable hiLink. The value **true** means to enable HiLink; the value **false** means the opposite.| 1201| bssid | string | Yes| MAC address of the hotspot, for example, **00:11:22:33:44:55**.| 1202| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration information. The value of **config.bssid** must be the same as that of the second parameter **bssid**. The default **bssidType** is random device address.| 1203 1204**Error codes** 1205 1206For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1207 1208| **ID**| **Error Message**| 1209| -------- | -------- | 1210| 201 | Permission denied. | 1211| 202 | System API is not allowed called by Non-system application. | 1212| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1213| 801 | Capability not supported. | 1214| 2501000 | Operation failed.| 1215| 2501001 | Wi-Fi STA disabled. | 1216 1217**Example** 1218 1219```ts 1220 import { wifiManager } from '@kit.ConnectivityKit'; 1221 // You can obtain config data by using getScanInfoList, which can be used only when WifiScanInfo.isHiLinkNetwork is true. 1222 let config:wifiManager.WifiDeviceConfig = { 1223 ssid : "****", 1224 preSharedKey : "****", 1225 securityType : 0, 1226 bssid : "38:37:8b:80:bf:cc", 1227 bssidType : 1, 1228 isHiddenSsid : false 1229 } 1230 try { 1231 wifiManager.enableHiLinkHandshake(true, config.bssid, config); 1232 }catch(error){ 1233 console.error("failed:" + JSON.stringify(error)); 1234 } 1235``` 1236 1237## wifiManager.factoryReset<sup>11+</sup> 1238 1239factoryReset(): void 1240 1241**System API**: This is a system API. 1242 1243Resets Wi-Fi configurations. 1244 1245**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG 1246 1247**System capability**: SystemCapability.Communication.WiFi.STA 1248 1249**Error codes** 1250 1251For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1252 1253| **ID**| **Error Message**| 1254| -------- | -------- | 1255| 201 | Permission denied. | 1256| 202 | System API is not allowed called by Non-system application. | 1257| 801 | Capability not supported. | 1258| 2501000 | Operation failed.| 1259 1260**Example** 1261 1262```ts 1263 import { wifiManager } from '@kit.ConnectivityKit'; 1264 1265 try { 1266 wifiManager.factoryReset(); 1267 }catch(error){ 1268 console.error("failed:" + JSON.stringify(error)); 1269 } 1270``` 1271## wifiManager.enableHotspot<sup>9+</sup> 1272 1273enableHotspot(): void 1274 1275Enables this hotspot. This API is an asynchronous interface. The **hotspotStateChange** callback must be registered and listened for. 1276 1277**System API**: This is a system API. 1278 1279**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1280 1281**System capability**: SystemCapability.Communication.WiFi.AP.Core 1282 1283**Error codes** 1284 1285For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1286 1287| **ID**| **Error Message**| 1288| -------- | -------- | 1289| 201 | Permission denied. | 1290| 202 | System API is not allowed called by Non-system application. | 1291| 801 | Capability not supported. | 1292| 2601000 | Operation failed. | 1293 1294**Example** 1295```ts 1296 import { wifiManager } from '@kit.ConnectivityKit'; 1297 1298 try { 1299 wifiManager.enableHotspot(); 1300 }catch(error){ 1301 console.error("failed:" + JSON.stringify(error)); 1302 } 1303``` 1304 1305## wifiManager.disableHotspot<sup>9+</sup> 1306 1307disableHotspot(): void 1308 1309Disables this hotspot. This API is an asynchronous interface. The **hotspotStateChange** callback must be registered and listened for. 1310 1311**System API**: This is a system API. 1312 1313**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1314 1315**System capability**: SystemCapability.Communication.WiFi.AP.Core 1316 1317**Error codes** 1318 1319For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1320 1321| **ID**| **Error Message**| 1322| -------- | -------- | 1323| 201 | Permission denied. | 1324| 202 | System API is not allowed called by Non-system application. | 1325| 801 | Capability not supported. | 1326| 2601000 | Operation failed. | 1327 1328**Example** 1329```ts 1330 import { wifiManager } from '@kit.ConnectivityKit'; 1331 1332 try { 1333 wifiManager.disableHotspot(); 1334 }catch(error){ 1335 console.error("failed:" + JSON.stringify(error)); 1336 } 1337``` 1338 1339## wifiManager.isHotspotDualBandSupported<sup>9+</sup> 1340 1341isHotspotDualBandSupported(): boolean 1342 1343Checks whether the hotspot supports dual band. 1344 1345**System API**: This is a system API. 1346 1347**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1348 1349**System capability**: SystemCapability.Communication.WiFi.AP.Core 1350 1351**Return value** 1352 1353 | **Type**| **Description**| 1354 | -------- | -------- | 1355 | boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.| 1356 1357**Error codes** 1358 1359For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1360 1361| **ID**| **Error Message**| 1362| -------- | -------- | 1363| 201 | Permission denied. | 1364| 202 | System API is not allowed called by Non-system application. | 1365| 801 | Capability not supported. | 1366| 2601000 | Operation failed. | 1367 1368**Example** 1369```ts 1370 import { wifiManager } from '@kit.ConnectivityKit'; 1371 1372 try { 1373 let ret = wifiManager.isHotspotDualBandSupported(); 1374 console.info("result:" + ret); 1375 }catch(error){ 1376 console.error("failed:" + JSON.stringify(error)); 1377 } 1378``` 1379 1380## wifiManager.isHotspotActive<sup>9+</sup> 1381 1382isHotspotActive(): boolean 1383 1384Checks whether this hotspot is active. 1385 1386**System API**: This is a system API. 1387 1388**Required permissions**: ohos.permission.GET_WIFI_INFO 1389 1390**System capability**: SystemCapability.Communication.WiFi.AP.Core 1391 1392**Return value** 1393 1394 | **Type**| **Description**| 1395 | -------- | -------- | 1396 | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| 1397 1398**Error codes** 1399 1400For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1401 1402| **ID**| **Error Message**| 1403| -------- | -------- | 1404| 201 | Permission denied. | 1405| 202 | System API is not allowed called by Non-system application. | 1406| 801 | Capability not supported. | 1407| 2601000 | Operation failed. | 1408 1409**Example** 1410```ts 1411 import { wifiManager } from '@kit.ConnectivityKit'; 1412 1413 try { 1414 let ret = wifiManager.isHotspotActive(); 1415 console.info("result:" + ret); 1416 }catch(error){ 1417 console.error("failed:" + JSON.stringify(error)); 1418 } 1419``` 1420 1421## wifiManager.setHotspotConfig<sup>9+</sup> 1422 1423setHotspotConfig(config: HotspotConfig): void 1424 1425Sets hotspot configuration. 1426 1427**System API**: This is a system API. 1428 1429**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1430 1431**System capability**: SystemCapability.Communication.WiFi.AP.Core 1432 1433**Parameters** 1434 1435 | **Name**| **Type**| **Mandatory**| **Description**| 1436 | -------- | -------- | -------- | -------- | 1437 | config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| 1438 1439**Error codes** 1440 1441For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1442 1443| **ID**| **Error Message**| 1444| -------- | -------- | 1445| 201 | Permission denied. | 1446| 202 | System API is not allowed called by Non-system application. | 1447| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1448| 801 | Capability not supported. | 1449| 2601000 | Operation failed. | 1450 1451**Example** 1452```ts 1453 import { wifiManager } from '@kit.ConnectivityKit'; 1454 1455 try { 1456 let config:wifiManager.HotspotConfig = { 1457 ssid: "****", 1458 securityType: 3, 1459 band: 0, 1460 channel: 0, 1461 preSharedKey: "****", 1462 maxConn: 0 1463 } 1464 let ret = wifiManager.setHotspotConfig(config); 1465 console.info("result:" + ret); 1466 }catch(error){ 1467 console.error("failed:" + JSON.stringify(error)); 1468 } 1469``` 1470 1471## HotspotConfig<sup>9+</sup> 1472 1473Represents the hotspot configuration. 1474 1475**System API**: This is a system API. 1476 1477**System capability**: SystemCapability.Communication.WiFi.AP.Core 1478 1479| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1480| -------- | -------- | -------- | -------- | -------- | 1481| ssid | string | Yes| Yes| SSID of the hotspot, in UTF-8 format.| 1482| securityType | [WifiSecurityType](js-apis-wifiManager.md#wifisecuritytype9)| Yes| Yes| Security type.| 1483| 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.| 1484| channel<sup>10+</sup> | number | Yes| Yes| Hotspot channel (channels 1 to 14 for 2.4 GHz, and channels 7 to 196 for 5 GHz)| 1485| preSharedKey | string | Yes| Yes| PSK of the hotspot.| 1486| maxConn | number | Yes| Yes| Maximum number of connections allowed.| 1487 1488## wifiManager.getHotspotConfig<sup>9+</sup> 1489 1490getHotspotConfig(): HotspotConfig 1491 1492Obtains hotspot configuration. 1493 1494**System API**: This is a system API. 1495 1496**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG 1497 1498**System capability**: SystemCapability.Communication.WiFi.AP.Core 1499 1500**Return value** 1501 1502 | **Type**| **Description**| 1503 | -------- | -------- | 1504 | [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| 1505 1506**Error codes** 1507 1508For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1509 1510| **ID**| **Error Message**| 1511| -------- | -------- | 1512| 201 | Permission denied. | 1513| 202 | System API is not allowed called by Non-system application. | 1514| 801 | Capability not supported. | 1515| 2601000 | Operation failed. | 1516 1517**Example** 1518```ts 1519 import { wifiManager } from '@kit.ConnectivityKit'; 1520 1521 try { 1522 let config = wifiManager.getHotspotConfig(); 1523 console.info("result:" + JSON.stringify(config)); 1524 }catch(error){ 1525 console.error("failed:" + JSON.stringify(error)); 1526 } 1527``` 1528 1529## wifiManager.getStations<sup>9+</sup> 1530 1531getStations(): Array<StationInfo> 1532 1533Obtains information about the connected stations. 1534 1535**System API**: This is a system API. 1536 1537**Required permissions**: 1538 1539API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only) 1540 1541API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only) 1542 1543**System capability**: SystemCapability.Communication.WiFi.AP.Core 1544 1545**Return value** 1546 1547| **Type**| **Description**| 1548| -------- | -------- | 1549| 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.| 1550 1551**Error codes** 1552 1553For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1554 1555| **ID**| **Error Message**| 1556| -------- | -------- | 1557| 201 | Permission denied. | 1558| 202 | System API is not allowed called by Non-system application. | 1559| 801 | Capability not supported. | 1560| 2601000 | Operation failed. | 1561 1562**Example** 1563```ts 1564 import { wifiManager } from '@kit.ConnectivityKit'; 1565 1566 try { 1567 let stations = wifiManager.getStations(); 1568 console.info("result:" + JSON.stringify(stations)); 1569 }catch(error){ 1570 console.error("failed:" + JSON.stringify(error)); 1571 } 1572``` 1573 1574## StationInfo<sup>9+</sup> 1575 1576Represents the station information. 1577 1578**System API**: This is a system API. 1579 1580**System capability**: SystemCapability.Communication.WiFi.AP.Core 1581 1582| **Name**| **Type**| **Readable**| **Writable**| **Description**| 1583| -------- | -------- | -------- | -------- | -------- | 1584| name | string | Yes| No| Device name.| 1585| macAddress | string | Yes| No| MAC address.| 1586| macAddressType<sup>10+</sup> | [DeviceAddressType](js-apis-wifiManager.md#deviceaddresstype10) | Yes| No| MAC address type.| 1587| ipAddress | string | Yes| No| IP address.| 1588 1589## wifiManager.addHotspotBlockList<sup>11+</sup> 1590 1591addHotspotBlockList(stationInfo: StationInfo) 1592 1593Adds a device to the list of blocked devices of the hotspot. Devices in the list cannot access the hotspot. 1594 1595**System API**: This is a system API. 1596 1597**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1598 1599**System capability**: SystemCapability.Communication.WiFi.AP.Core 1600 1601**Parameters** 1602 1603| **Name**| **Type**| **Mandatory**| **Description**| 1604| -------- | -------- | -------- | -------- | 1605| stationInfo | [StationInfo](#stationinfo9) | Yes| Device to add.| 1606 1607**Error codes** 1608 1609For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1610 1611| **ID**| **Error Message**| 1612| -------- | -------- | 1613| 201 | Permission denied. | 1614| 202 | System API is not allowed called by Non-system application. | 1615| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1616| 801 | Capability not supported. | 1617| 2601000 | Operation failed. | 1618 1619**Example** 1620 1621```ts 1622 import { wifiManager } from '@kit.ConnectivityKit'; 1623 1624 try { 1625 let config:wifiManager.StationInfo = { 1626 name : "testSsid", 1627 macAddress : "11:22:33:44:55:66", 1628 ipAddress : "192.168.1.111" 1629 } 1630 // The device can be added to the block list only after the hotspot is enabled. 1631 wifiManager.addHotspotBlockList(config); 1632 }catch(error){ 1633 console.error("failed:" + JSON.stringify(error)); 1634 } 1635``` 1636 1637## wifiManager.delHotspotBlockList<sup>11+</sup> 1638 1639delHotspotBlockList(stationInfo: StationInfo) 1640 1641Delets a device from the list of blocked devices of the hotspot. 1642 1643**System API**: This is a system API. 1644 1645**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1646 1647**System capability**: SystemCapability.Communication.WiFi.AP.Core 1648 1649**Parameters** 1650 1651| **Name**| **Type**| **Mandatory**| **Description**| 1652| -------- | -------- | -------- | -------- | 1653| stationInfo | [StationInfo](#stationinfo9) | Yes| Device to delete.| 1654 1655**Error codes** 1656 1657For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1658 1659| **ID**| **Error Message**| 1660| -------- | -------- | 1661| 201 | Permission denied. | 1662| 202 | System API is not allowed called by Non-system application. | 1663| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1664| 801 | Capability not supported. | 1665| 2601000 | Operation failed. | 1666 1667**Example** 1668 1669```ts 1670 import { wifiManager } from '@kit.ConnectivityKit'; 1671 1672 try { 1673 let config:wifiManager.StationInfo = { 1674 name : "testSsid", 1675 macAddress : "11:22:33:44:55:66", 1676 ipAddress : "192.168.1.111" 1677 } 1678 wifiManager.delHotspotBlockList(config); 1679 }catch(error){ 1680 console.error("failed:" + JSON.stringify(error)); 1681 } 1682``` 1683 1684## wifiManager.getHotspotBlockList<sup>11+</sup> 1685 1686getHotspotBlockList(): Array<StationInfo> 1687 1688Obtains the list of blocked devices of the hotspot. 1689 1690**System API**: This is a system API. 1691 1692**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) 1693 1694**System capability**: SystemCapability.Communication.WiFi.AP.Core 1695 1696**Return value** 1697 1698| **Type**| **Description**| 1699| -------- | -------- | 1700| Array<[StationInfo](#stationinfo9)> | List of blocked devices obtained.| 1701 1702**Error codes** 1703 1704For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1705 1706| **ID**| **Error Message**| 1707 | -------- | -------- | 1708| 201 | Permission denied. | 1709| 202 | System API is not allowed called by Non-system application. | 1710| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. | 1711| 801 | Capability not supported. | 1712| 2601000 | Operation failed. | 1713 1714**Example** 1715 1716```ts 1717 import { wifiManager } from '@kit.ConnectivityKit'; 1718 1719 try { 1720 let data = wifiManager.getHotspotBlockList(); 1721 console.info("result:" + JSON.stringify(data)); 1722 }catch(error){ 1723 console.error("failed:" + JSON.stringify(error)); 1724 } 1725``` 1726 1727## wifiManager.deletePersistentGroup<sup>9+</sup> 1728 1729deletePersistentGroup(netId: number): void 1730 1731Deletes a persistent group. 1732 1733**System API**: This is a system API. 1734 1735**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION 1736 1737**System capability**: SystemCapability.Communication.WiFi.P2P 1738 1739**Parameters** 1740 1741 1742 | **Name**| **Type**| Mandatory| **Description**| 1743 | -------- | -------- | -------- | -------- | 1744 | netId | number | Yes| ID of the group to delete.| 1745 1746**Error codes** 1747 1748For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1749 1750| **ID**| **Error Message**| 1751| -------- | -------- | 1752| 201 | Permission denied. | 1753| 202 | System API is not allowed called by Non-system application. | 1754| 401 | Invalid parameters. Possible causes: 1.Incorrect parameter types. | 1755| 801 | Capability not supported. | 1756| 2801000 | Operation failed. | 1757| 2801001 | Wi-Fi STA disabled. | 1758 1759**Example** 1760```ts 1761 import { wifiManager } from '@kit.ConnectivityKit'; 1762 1763 try { 1764 let netId = 0; 1765 wifiManager.deletePersistentGroup(netId); 1766 }catch(error){ 1767 console.error("failed:" + JSON.stringify(error)); 1768 } 1769``` 1770 1771## wifiManager.getP2pGroups<sup>9+</sup> 1772 1773getP2pGroups(): Promise<Array<WifiP2pGroupInfo>> 1774 1775Obtains information about all P2P groups. This API uses a promise to return the result. 1776 1777**System API**: This is a system API. 1778 1779**Required permissions**: 1780 1781API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1782 1783API version 10 and later : ohos.permission.GET_WIFI_INFO 1784 1785**System capability**: SystemCapability.Communication.WiFi.P2P 1786 1787**Return value** 1788 1789| Type| Description| 1790| -------- | -------- | 1791| Promise< Array<[WifiP2pGroupInfo](js-apis-wifiManager.md#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.| 1792 1793**Error codes** 1794 1795For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1796 1797| **ID**| **Error Message**| 1798| -------- | -------- | 1799| 201 | Permission denied. | 1800| 202 | System API is not allowed called by Non-system application. | 1801| 801 | Capability not supported. | 1802| 2801000 | Operation failed. | 1803 1804**Example** 1805```ts 1806 import { wifiManager } from '@kit.ConnectivityKit'; 1807 1808 wifiManager.getP2pGroups((err, data:wifiManager.WifiP2pGroupInfo) => { 1809 if (err) { 1810 console.error("get P2P groups error"); 1811 return; 1812 } 1813 console.info("get P2P groups: " + JSON.stringify(data)); 1814 }); 1815 1816 wifiManager.getP2pGroups().then(data => { 1817 console.info("get P2P groups: " + JSON.stringify(data)); 1818 }); 1819 1820``` 1821 1822 1823## wifiManager.getP2pGroups<sup>9+</sup> 1824 1825getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void 1826 1827Obtains information about all P2P groups. This API uses an asynchronous callback to return the result. 1828 1829**System API**: This is a system API. 1830 1831**Required permissions**: 1832 1833API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION 1834 1835API version 10 and later : ohos.permission.GET_WIFI_INFO 1836 1837**System capability**: SystemCapability.Communication.WiFi.P2P 1838 1839**Parameters** 1840 1841| Name| Type| Mandatory| Description| 1842| -------- | -------- | -------- | -------- | 1843| callback | AsyncCallback< Array<[WifiP2pGroupInfo](js-apis-wifiManager.md#wifip2pgroupinfo9)>> | Yes| Callback used to return the result. If the operation is successful, **error** is **0** and **data** is the group information obtained. If the operation fails, **error** is not **0**. 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.| 1844 1845**Error codes** 1846 1847For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1848 1849| **ID**| **Error Message**| 1850| -------- | -------- | 1851| 201 | Permission denied. | 1852| 202 | System API is not allowed called by Non-system application. | 1853| 801 | Capability not supported. | 1854| 2801000 | Operation failed. | 1855| 2801001 | Wi-Fi STA disabled. | 1856 1857## wifiManager.setDeviceName<sup>9+</sup> 1858 1859setDeviceName(devName: string): void 1860 1861Sets the device name. 1862 1863**System API**: This is a system API. 1864 1865**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications) 1866 1867**System capability**: SystemCapability.Communication.WiFi.P2P 1868 1869**Parameters** 1870 1871 | **Name**| **Type**| **Mandatory**| **Description**| 1872 | -------- | -------- | -------- | -------- | 1873 | devName | string | Yes| Device name to set.| 1874 1875**Error codes** 1876 1877For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1878 1879| **ID**| **Error Message**| 1880| -------- | -------- | 1881| 201 | Permission denied. | 1882| 202 | System API is not allowed called by Non-system application. | 1883| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1884| 801 | Capability not supported. | 1885| 2801000 | Operation failed. | 1886| 2801001 | Wi-Fi STA disabled. | 1887 1888**Example** 1889```ts 1890 import { wifiManager } from '@kit.ConnectivityKit'; 1891 1892 try { 1893 let name = "****"; 1894 wifiManager.setDeviceName(name); 1895 }catch(error){ 1896 console.error("failed:" + JSON.stringify(error)); 1897 } 1898``` 1899 1900 1901## wifiManager.on('streamChange')<sup>9+</sup> 1902 1903on(type: 'streamChange', callback: Callback<number>): void 1904 1905Subscribes to Wi-Fi stream changes. When the service exits, call off(type: 'streamChange', callback?: Callback<number>) to unregister the callback registered. 1906 1907**System API**: This is a system API. 1908 1909**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION 1910 1911**System capability**: SystemCapability.Communication.WiFi.STA 1912 1913**Parameters** 1914 1915| **Name**| **Type**| **Mandatory**| **Description**| 1916| -------- | -------- | -------- | -------- | 1917| type | string | Yes| Event type, which has a fixed value of **streamChange**.| 1918| callback | Callback<number> | Yes| Callback used to return the Wi-Fi stream change, which can be any of the following values:<br>- **0**: No stream.<br>- **1**: Downward.<br>- **2**: Upward.<br>- **3**: Bidirectional.| 1919 1920**Error codes** 1921 1922For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1923 1924| **ID**| **Error Message**| 1925| -------- | -------- | 1926| 201 | Permission denied. | 1927| 202 | System API is not allowed called by Non-system application. | 1928| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1929| 801 | Capability not supported. | 1930| 2501000 | Operation failed.| 1931 1932## wifiManager.off('streamChange')<sup>9+</sup> 1933 1934off(type: 'streamChange', callback?: Callback<number>): void 1935 1936Unsubscribes from Wi-Fi stream changes. 1937 1938**System API**: This is a system API. 1939 1940**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION 1941 1942**System capability**: SystemCapability.Communication.WiFi.STA 1943 1944**Parameters** 1945 1946| **Name**| **Type**| **Mandatory**| **Description**| 1947| -------- | -------- | -------- | -------- | 1948| type | string | Yes| Event type, which has a fixed value of **streamChange**.| 1949| callback | Callback<number> | No| Callback to unregister. The stream change can be any of the following values:<br>- **0**: No stream.<br>- **1**: Downward.<br>- **2**: Upward.<br>- **3**: Bidirectional.| 1950 1951**Error codes** 1952 1953For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 1954 1955| **ID**| **Error Message**| 1956| -------- | -------- | 1957| 201 | Permission denied. | 1958| 202 | System API is not allowed called by Non-system application. | 1959| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1960| 801 | Capability not supported. | 1961| 2501000 | Operation failed.| 1962 1963**Example** 1964```ts 1965import { wifi } from '@kit.ConnectivityKit'; 1966 1967let recvStreamChangeFunc = (result:number) => { 1968 console.info("Receive stream change event: " + result); 1969} 1970 1971// Register an event. 1972wifi.on("streamChange", recvStreamChangeFunc); 1973 1974// Unregister an event. 1975wifi.off("streamChange", recvStreamChangeFunc); 1976 1977``` 1978## wifiManager.on('deviceConfigChange')<sup>9+</sup> 1979 1980on(type: 'deviceConfigChange', callback: Callback<number>): void 1981 1982Subscribes to Wi-Fi device configuration changes. When the service exits, call off(type: 'deviceConfigChange', callback?: Callback<number>) to unregister the callback registered. 1983 1984**System API**: This is a system API. 1985 1986**Required permissions**: ohos.permission.GET_WIFI_INFO 1987 1988**System capability**: SystemCapability.Communication.WiFi.STA 1989 1990**Parameters** 1991 1992| **Name**| **Type**| **Mandatory**| **Description**| 1993| -------- | -------- | -------- | -------- | 1994| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.| 1995| callback | Callback<number> | Yes| Callback used 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.| 1996 1997**Error codes** 1998 1999For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2000 2001| **ID**| **Error Message**| 2002| -------- | -------- | 2003| 201 | Permission denied. | 2004| 202 | System API is not allowed called by Non-system application. | 2005| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2006| 801 | Capability not supported. | 2007| 2501000 | Operation failed.| 2008 2009## wifiManager.off('deviceConfigChange')<sup>9+</sup> 2010 2011off(type: 'deviceConfigChange', callback?: Callback<number>): void 2012 2013Unsubscribes from Wi-Fi device configuration changes. 2014 2015**System API**: This is a system API. 2016 2017**Required permissions**: ohos.permission.GET_WIFI_INFO 2018 2019**System capability**: SystemCapability.Communication.WiFi.STA 2020 2021**Parameters** 2022 2023| **Name**| **Type**| **Mandatory**| **Description**| 2024| -------- | -------- | -------- | -------- | 2025| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.| 2026| callback | Callback<number> | No| Callback to unregister. The device configuration change can be any of the following values:<br>- **0**: device configuration added.<br>- **1**: device configuration changed.<br>- **2**: device configuration deleted.| 2027 2028**Error codes** 2029 2030For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2031 2032| **ID**| **Error Message**| 2033| -------- | -------- | 2034| 201 | Permission denied. | 2035| 202 | System API is not allowed called by Non-system application. | 2036| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2037| 801 | Capability not supported. | 2038| 2501000 | Operation failed.| 2039 2040**Example** 2041```ts 2042import { wifiManager } from '@kit.ConnectivityKit'; 2043 2044let recvDeviceConfigChangeFunc = (result:number) => { 2045 console.info("Receive device config change event: " + result); 2046} 2047 2048// Register an event. 2049wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc); 2050 2051// Unregister an event. 2052wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc); 2053 2054``` 2055 2056## wifiManager.on('hotspotStaJoin')<sup>9+</sup> 2057 2058on(type: 'hotspotStaJoin', callback: Callback<StationInfo>): void 2059 2060Subscribes to the event of an STA joining a Wi-Fi hotspot. When the service exits, call off(type: 'hotspotStaJoin', callback?: Callback<StationInfo>) to unregister the callback registered. 2061 2062**System API**: This is a system API. 2063 2064**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 2065 2066**System capability**: SystemCapability.Communication.WiFi.AP.Core 2067 2068**Parameters** 2069 2070| **Name**| **Type**| **Mandatory**| **Description**| 2071| -------- | -------- | -------- | -------- | 2072| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.| 2073| callback | Callback<StationInfo> | Yes| Callback used to return the event.| 2074 2075**Error codes** 2076 2077For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2078 2079| **ID**| **Error Message**| 2080| -------- | -------- | 2081| 201 | Permission denied. | 2082| 202 | System API is not allowed called by Non-system application. | 2083| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2084| 801 | Capability not supported. | 2085| 2601000 | Operation failed. | 2086 2087## wifiManager.off('hotspotStaJoin')<sup>9+</sup> 2088 2089off(type: 'hotspotStaJoin', callback?: Callback<StationInfo>): void 2090 2091Unsubscribes from the event of an STA joining a Wi-Fi hotspot. 2092 2093**System API**: This is a system API. 2094 2095**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 2096 2097**System capability**: SystemCapability.Communication.WiFi.AP.Core 2098 2099**Parameters** 2100 2101| **Name**| **Type**| **Mandatory**| **Description**| 2102| -------- | -------- | -------- | -------- | 2103| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.| 2104| callback | Callback<StationInfo> | No| Callback to unregister.| 2105 2106**Error codes** 2107 2108For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2109 2110| **ID**| **Error Message**| 2111| -------- | -------- | 2112| 201 | Permission denied. | 2113| 202 | System API is not allowed called by Non-system application. | 2114| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2115| 801 | Capability not supported. | 2116| 2601000 | Operation failed. | 2117 2118**Example** 2119```ts 2120import { wifiManager } from '@kit.ConnectivityKit'; 2121 2122let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => { 2123 console.info("Receive hotspot sta join event: " + result); 2124} 2125 2126// Register an event. 2127wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc); 2128 2129// Unregister an event. 2130wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc); 2131 2132``` 2133 2134## wifiManager.on('hotspotStaLeave')<sup>9+</sup> 2135 2136on(type: 'hotspotStaLeave', callback: Callback<StationInfo>): void 2137 2138Subscribes to the event of an STA leaving a Wi-Fi hotspot. When the service exits, call off(type: 'hotspotStaLeave', callback?: Callback<StationInfo>) to unregister the callback registered. 2139 2140**System API**: This is a system API. 2141 2142**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 2143 2144**System capability**: SystemCapability.Communication.WiFi.AP.Core 2145 2146**Parameters** 2147 2148 | **Name**| **Type**| **Mandatory**| **Description**| 2149 | -------- | -------- | -------- | -------- | 2150 | type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.| 2151 | callback | Callback<StationInf]> | Yes| Callback used to return the event.| 2152 2153**Error codes** 2154 2155For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2156 2157| **ID**| **Error Message**| 2158| -------- | -------- | 2159| 201 | Permission denied. | 2160| 202 | System API is not allowed called by Non-system application. | 2161| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2162| 801 | Capability not supported. | 2163| 2601000 | Operation failed. | 2164 2165## wifiManager.off('hotspotStaLeave')<sup>9+</sup> 2166 2167off(type: 'hotspotStaLeave', callback?: Callback<StationInfo>): void 2168 2169Unsubscribes from the event of an STA leaving a Wi-Fi hotspot. 2170 2171**System API**: This is a system API. 2172 2173**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT 2174 2175**System capability**: SystemCapability.Communication.WiFi.AP.Core 2176 2177**Parameters** 2178 2179| **Name**| **Type**| **Mandatory**| **Description**| 2180| -------- | -------- | -------- | -------- | 2181| type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.| 2182| callback | Callback<StationInf]> | No| Callback to unregister.| 2183 2184**Error codes** 2185 2186For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md). 2187 2188| **ID**| **Error Message**| 2189| -------- | -------- | 2190| 201 | Permission denied. | 2191| 202 | System API is not allowed called by Non-system application. | 2192| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2193| 801 | Capability not supported. | 2194| 2601000 | Operation failed. | 2195 2196**Example** 2197```ts 2198import { wifiManager } from '@kit.ConnectivityKit'; 2199 2200let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => { 2201 console.info("Receive hotspot sta leave event: " + result); 2202} 2203 2204// Register an event. 2205wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc); 2206 2207// Unregister an event. 2208wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc); 2209 2210``` 2211