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