• 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>9+</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 | Returns **true** if the hotspot supports dual band; returns **false** otherwise.|
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.setHotspotConfig<sup>9+</sup>
1065
1066setHotspotConfig(config: HotspotConfig): void
1067
1068Sets hotspot configuration.
1069
1070**System API**: This is a system API.
1071
1072**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
1073
1074**System capability**: SystemCapability.Communication.WiFi.AP.Core
1075
1076**Parameters**
1077
1078  | **Name**| **Type**| **Mandatory**| **Description**|
1079  | -------- | -------- | -------- | -------- |
1080  | config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.|
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| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1091| 801 | Capability not supported.          |
1092| 2601000  | Operation failed. |
1093
1094**Example**
1095```ts
1096	import { wifiManager } from '@kit.ConnectivityKit';
1097
1098	try {
1099		let config:wifiManager.HotspotConfig = {
1100			ssid: "****",
1101			securityType: 3,
1102			band: 0,
1103			channel: 0,
1104			preSharedKey: "****",
1105			maxConn: 0
1106		}
1107		let ret = wifiManager.setHotspotConfig(config);
1108		console.info("result:" + ret);
1109	}catch(error){
1110		console.error("failed:" + JSON.stringify(error));
1111	}
1112```
1113
1114## HotspotConfig<sup>9+</sup>
1115
1116Represents the hotspot configuration.
1117
1118**System API**: This is a system API.
1119
1120**System capability**: SystemCapability.Communication.WiFi.AP.Core
1121
1122| **Name**| **Type**| **Readable**| **Writable**| **Description**|
1123| -------- | -------- | -------- | -------- | -------- |
1124| ssid | string | Yes| Yes| SSID of the hotspot, in UTF-8 format.|
1125| securityType | [WifiSecurityType](js-apis-wifiManager.md#wifisecuritytype9)| Yes| Yes| Security type.|
1126| 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.|
1127| 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)|
1128| preSharedKey | string | Yes| Yes| PSK of the hotspot.|
1129| maxConn | number | Yes| Yes| Maximum number of connections allowed.|
1130
1131## wifiManager.getHotspotConfig<sup>9+</sup>
1132
1133getHotspotConfig(): HotspotConfig
1134
1135Obtains hotspot configuration.
1136
1137**System API**: This is a system API.
1138
1139**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
1140
1141**System capability**: SystemCapability.Communication.WiFi.AP.Core
1142
1143**Return value**
1144
1145  | **Type**| **Description**|
1146  | -------- | -------- |
1147  | [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.|
1148
1149**Error codes**
1150
1151For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1152
1153| **ID**| **Error Message**|
1154| -------- | -------- |
1155| 201 | Permission denied.                 |
1156| 202 | System API is not allowed called by Non-system application. |
1157| 801 | Capability not supported.          |
1158| 2601000  | Operation failed. |
1159
1160**Example**
1161```ts
1162	import { wifiManager } from '@kit.ConnectivityKit';
1163
1164	try {
1165		let config = wifiManager.getHotspotConfig();
1166		console.info("result:" + JSON.stringify(config));
1167	}catch(error){
1168		console.error("failed:" + JSON.stringify(error));
1169	}
1170```
1171
1172## wifiManager.getStations<sup>9+</sup>
1173
1174getStations(): &nbsp;Array&lt;StationInfo&gt;
1175
1176Obtains information about the connected stations.
1177
1178**System API**: This is a system API.
1179
1180**Required permissions**:
1181
1182API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only)
1183
1184API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only)
1185
1186**System capability**: SystemCapability.Communication.WiFi.AP.Core
1187
1188**Return value**
1189
1190| **Type**| **Description**|
1191| -------- | -------- |
1192| &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.|
1193
1194**Error codes**
1195
1196For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1197
1198| **ID**| **Error Message**|
1199| -------- | -------- |
1200| 201 | Permission denied.                 |
1201| 202 | System API is not allowed called by Non-system application. |
1202| 801 | Capability not supported.          |
1203| 2601000  | Operation failed. |
1204
1205**Example**
1206```ts
1207	import { wifiManager } from '@kit.ConnectivityKit';
1208
1209	try {
1210		let stations = wifiManager.getStations();
1211		console.info("result:" + JSON.stringify(stations));
1212	}catch(error){
1213		console.error("failed:" + JSON.stringify(error));
1214	}
1215```
1216
1217## StationInfo<sup>9+</sup>
1218
1219Represents the station information.
1220
1221**System API**: This is a system API.
1222
1223**System capability**: SystemCapability.Communication.WiFi.AP.Core
1224
1225| **Name**| **Type**| **Readable**| **Writable**| **Description**|
1226| -------- | -------- | -------- | -------- | -------- |
1227| name | string | Yes| No| Device name.|
1228| macAddress | string | Yes| No| MAC address.|
1229| macAddressType<sup>10+</sup> | [DeviceAddressType](js-apis-wifiManager.md#deviceaddresstype10) | Yes| No| MAC address type.|
1230| ipAddress | string | Yes| No| IP address.|
1231
1232## wifiManager.addHotspotBlockList<sup>11+</sup>
1233
1234addHotspotBlockList(stationInfo: StationInfo)
1235
1236Adds a device to the list of blocked devices of the hotspot. Devices in the list cannot access the hotspot.
1237
1238**System API**: This is a system API.
1239
1240**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
1241
1242**System capability**: SystemCapability.Communication.WiFi.AP.Core
1243
1244**Parameters**
1245
1246| **Name**| **Type**| **Mandatory**| **Description**|
1247| -------- | -------- | -------- | -------- |
1248| stationInfo | [StationInfo](#stationinfo9) | Yes| Device to add.|
1249
1250**Error codes**
1251
1252For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1253
1254| **ID**| **Error Message**|
1255| -------- | -------- |
1256| 201 | Permission denied.                 |
1257| 202 | System API is not allowed called by Non-system application. |
1258| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1259| 801 | Capability not supported.          |
1260| 2601000  | Operation failed. |
1261
1262**Example**
1263
1264```ts
1265	import { wifiManager } from '@kit.ConnectivityKit';
1266
1267	try {
1268		let config:wifiManager.StationInfo = {
1269			name : "testSsid",
1270			macAddress : "11:22:33:44:55:66",
1271			ipAddress : "192.168.1.111"
1272		}
1273		// The device can be added to the block list only after the hotspot is enabled.
1274		wifiManager.addHotspotBlockList(config);
1275	}catch(error){
1276		console.error("failed:" + JSON.stringify(error));
1277	}
1278```
1279
1280## wifiManager.delHotspotBlockList<sup>11+</sup>
1281
1282delHotspotBlockList(stationInfo: StationInfo)
1283
1284Deletes a device from the list of blocked devices of the hotspot.
1285
1286**System API**: This is a system API.
1287
1288**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
1289
1290**System capability**: SystemCapability.Communication.WiFi.AP.Core
1291
1292**Parameters**
1293
1294| **Name**| **Type**| **Mandatory**| **Description**|
1295| -------- | -------- | -------- | -------- |
1296| stationInfo | [StationInfo](#stationinfo9) | Yes| Device to delete.|
1297
1298**Error codes**
1299
1300For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1301
1302| **ID**| **Error Message**|
1303| -------- | -------- |
1304| 201 | Permission denied.                 |
1305| 202 | System API is not allowed called by Non-system application. |
1306| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1307| 801 | Capability not supported.          |
1308| 2601000  | Operation failed. |
1309
1310**Example**
1311
1312```ts
1313	import { wifiManager } from '@kit.ConnectivityKit';
1314
1315	try {
1316		let config:wifiManager.StationInfo = {
1317			name : "testSsid",
1318			macAddress : "11:22:33:44:55:66",
1319			ipAddress : "192.168.1.111"
1320		}
1321		wifiManager.delHotspotBlockList(config);
1322	}catch(error){
1323		console.error("failed:" + JSON.stringify(error));
1324	}
1325```
1326
1327## wifiManager.getHotspotBlockList<sup>11+</sup>
1328
1329getHotspotBlockList(): Array&lt;StationInfo&gt;
1330
1331Obtains the list of blocked devices of the hotspot.
1332
1333**System API**: This is a system API.
1334
1335**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
1336
1337**System capability**: SystemCapability.Communication.WiFi.AP.Core
1338
1339**Return value**
1340
1341| **Type**| **Description**|
1342| -------- | -------- |
1343| &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; | List of blocked devices obtained.|
1344
1345**Error codes**
1346
1347For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1348
1349| **ID**| **Error Message**|
1350  | -------- | -------- |
1351| 201 | Permission denied.                 |
1352| 202 | System API is not allowed called by Non-system application. |
1353| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. |
1354| 801 | Capability not supported.          |
1355| 2601000  | Operation failed. |
1356
1357**Example**
1358
1359```ts
1360	import { wifiManager } from '@kit.ConnectivityKit';
1361
1362	try {
1363		let data = wifiManager.getHotspotBlockList();
1364		console.info("result:" + JSON.stringify(data));
1365	}catch(error){
1366		console.error("failed:" + JSON.stringify(error));
1367	}
1368```
1369
1370## wifiManager.deletePersistentGroup<sup>9+</sup>
1371
1372deletePersistentGroup(netId: number): void
1373
1374Deletes a persistent group.
1375
1376**System API**: This is a system API.
1377
1378**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
1379
1380**System capability**: SystemCapability.Communication.WiFi.P2P
1381
1382**Parameters**
1383
1384
1385  | **Name**| **Type**| Mandatory| **Description**|
1386  | -------- | -------- | -------- | -------- |
1387  | netId | number | Yes| ID of the group to delete.|
1388
1389**Error codes**
1390
1391For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1392
1393| **ID**| **Error Message**|
1394| -------- | -------- |
1395| 201 | Permission denied.                 |
1396| 202 | System API is not allowed called by Non-system application. |
1397| 401 | Invalid parameters. Possible causes: 1.Incorrect parameter types. |
1398| 801 | Capability not supported.          |
1399| 2801000  | Operation failed. |
1400| 2801001  | Wi-Fi STA disabled. |
1401
1402**Example**
1403```ts
1404	import { wifiManager } from '@kit.ConnectivityKit';
1405
1406	try {
1407		let netId = 0;
1408		wifiManager.deletePersistentGroup(netId);
1409	}catch(error){
1410		console.error("failed:" + JSON.stringify(error));
1411	}
1412```
1413
1414## wifiManager.getP2pGroups<sup>9+</sup>
1415
1416getP2pGroups(): Promise&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;
1417
1418Obtains information about all P2P groups. This API uses a promise to return the result.
1419
1420**System API**: This is a system API.
1421
1422**Required permissions**:
1423
1424API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
1425
1426API version 10 and later : ohos.permission.GET_WIFI_INFO
1427
1428**System capability**: SystemCapability.Communication.WiFi.P2P
1429
1430**Return value**
1431
1432| Type| Description|
1433| -------- | -------- |
1434| 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.|
1435
1436**Error codes**
1437
1438For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1439
1440| **ID**| **Error Message**|
1441| -------- | -------- |
1442| 201 | Permission denied.                 |
1443| 202 | System API is not allowed called by Non-system application. |
1444| 801 | Capability not supported.          |
1445| 2801000  | Operation failed. |
1446
1447**Example**
1448```ts
1449	import { wifiManager } from '@kit.ConnectivityKit';
1450
1451	wifiManager.getP2pGroups((err, data:wifiManager.WifiP2pGroupInfo) => {
1452    if (err) {
1453        console.error("get P2P groups error");
1454        return;
1455    }
1456		console.info("get P2P groups: " + JSON.stringify(data));
1457	});
1458
1459	wifiManager.getP2pGroups().then(data => {
1460		console.info("get P2P groups: " + JSON.stringify(data));
1461	});
1462
1463```
1464
1465
1466## wifiManager.getP2pGroups<sup>9+</sup>
1467
1468getP2pGroups(callback: AsyncCallback&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;): void
1469
1470Obtains information about all P2P groups. This API uses an asynchronous callback to return the result.
1471
1472**System API**: This is a system API.
1473
1474**Required permissions**:
1475
1476API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
1477
1478API version 10 and later : ohos.permission.GET_WIFI_INFO
1479
1480**System capability**: SystemCapability.Communication.WiFi.P2P
1481
1482**Parameters**
1483
1484| Name| Type| Mandatory| Description|
1485| -------- | -------- | -------- | -------- |
1486| 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.|
1487
1488**Error codes**
1489
1490For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1491
1492| **ID**| **Error Message**|
1493| -------- | -------- |
1494| 201 | Permission denied.                 |
1495| 202 | System API is not allowed called by Non-system application. |
1496| 801 | Capability not supported.          |
1497| 2801000  | Operation failed. |
1498| 2801001  | Wi-Fi STA disabled. |
1499
1500## wifiManager.setDeviceName<sup>9+</sup>
1501
1502setDeviceName(devName: string): void
1503
1504Sets the device name.
1505
1506**System API**: This is a system API.
1507
1508**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
1509
1510**System capability**: SystemCapability.Communication.WiFi.P2P
1511
1512**Parameters**
1513
1514  | **Name**| **Type**| **Mandatory**| **Description**|
1515  | -------- | -------- | -------- | -------- |
1516  | devName | string | Yes| Device name to set.|
1517
1518**Error codes**
1519
1520For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1521
1522| **ID**| **Error Message**|
1523| -------- | -------- |
1524| 201 | Permission denied.                 |
1525| 202 | System API is not allowed called by Non-system application. |
1526| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. |
1527| 801 | Capability not supported.          |
1528| 2801000  | Operation failed. |
1529| 2801001  | Wi-Fi STA disabled. |
1530
1531**Example**
1532```ts
1533	import { wifiManager } from '@kit.ConnectivityKit';
1534
1535	try {
1536		let name = "****";
1537		wifiManager.setDeviceName(name);
1538	}catch(error){
1539		console.error("failed:" + JSON.stringify(error));
1540	}
1541```
1542
1543
1544## wifiManager.on('streamChange')<sup>9+</sup>
1545
1546on(type: 'streamChange', callback: Callback&lt;number&gt;): void
1547
1548Subscribes to Wi-Fi stream changes. When the service exits, call off(type: 'streamChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
1549
1550**System API**: This is a system API.
1551
1552**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION
1553
1554**System capability**: SystemCapability.Communication.WiFi.STA
1555
1556**Parameters**
1557
1558| **Name**| **Type**| **Mandatory**| **Description**|
1559| -------- | -------- | -------- | -------- |
1560| type | string | Yes| Event type, which has a fixed value of **streamChange**.|
1561| 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.|
1562
1563**Error codes**
1564
1565For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1566
1567| **ID**| **Error Message**|
1568| -------- | -------- |
1569| 201 | Permission denied.                 |
1570| 202 | System API is not allowed called by Non-system application. |
1571| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1572| 801 | Capability not supported.          |
1573| 2501000  | Operation failed.|
1574
1575## wifiManager.off('streamChange')<sup>9+</sup>
1576
1577off(type: 'streamChange', callback?: Callback&lt;number&gt;): void
1578
1579Unsubscribes from Wi-Fi stream changes.
1580
1581**System API**: This is a system API.
1582
1583**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION
1584
1585**System capability**: SystemCapability.Communication.WiFi.STA
1586
1587**Parameters**
1588
1589| **Name**| **Type**| **Mandatory**| **Description**|
1590| -------- | -------- | -------- | -------- |
1591| type | string | Yes| Event type, which has a fixed value of **streamChange**.|
1592| 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.|
1593
1594**Error codes**
1595
1596For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1597
1598| **ID**| **Error Message**|
1599| -------- | -------- |
1600| 201 | Permission denied.                 |
1601| 202 | System API is not allowed called by Non-system application. |
1602| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1603| 801 | Capability not supported.          |
1604| 2501000  | Operation failed.|
1605
1606**Example**
1607```ts
1608import { wifi } from '@kit.ConnectivityKit';
1609
1610let recvStreamChangeFunc = (result:number) => {
1611    console.info("Receive stream change event: " + result);
1612}
1613
1614// Register an event.
1615wifi.on("streamChange", recvStreamChangeFunc);
1616
1617// Unregister an event.
1618wifi.off("streamChange", recvStreamChangeFunc);
1619
1620```
1621## wifiManager.on('deviceConfigChange')<sup>9+</sup>
1622
1623on(type: 'deviceConfigChange', callback: Callback&lt;number&gt;): void
1624
1625Subscribes to Wi-Fi device configuration changes. When the service exits, call off(type: 'deviceConfigChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
1626
1627**System API**: This is a system API.
1628
1629**Required permissions**: ohos.permission.GET_WIFI_INFO
1630
1631**System capability**: SystemCapability.Communication.WiFi.STA
1632
1633**Parameters**
1634
1635| **Name**| **Type**| **Mandatory**| **Description**|
1636| -------- | -------- | -------- | -------- |
1637| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.|
1638| callback | Callback&lt;number&gt; | 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.|
1639
1640**Error codes**
1641
1642For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1643
1644| **ID**| **Error Message**|
1645| -------- | -------- |
1646| 201 | Permission denied.                 |
1647| 202 | System API is not allowed called by Non-system application. |
1648| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1649| 801 | Capability not supported.          |
1650| 2501000  | Operation failed.|
1651
1652## wifiManager.off('deviceConfigChange')<sup>9+</sup>
1653
1654off(type: 'deviceConfigChange', callback?: Callback&lt;number&gt;): void
1655
1656Unsubscribes from Wi-Fi device configuration changes.
1657
1658**System API**: This is a system API.
1659
1660**Required permissions**: ohos.permission.GET_WIFI_INFO
1661
1662**System capability**: SystemCapability.Communication.WiFi.STA
1663
1664**Parameters**
1665
1666| **Name**| **Type**| **Mandatory**| **Description**|
1667| -------- | -------- | -------- | -------- |
1668| type | string | Yes| Event type, which has a fixed value of **deviceConfigChange**.|
1669| callback | Callback&lt;number&gt; | 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.|
1670
1671**Error codes**
1672
1673For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1674
1675| **ID**| **Error Message**|
1676| -------- | -------- |
1677| 201 | Permission denied.                 |
1678| 202 | System API is not allowed called by Non-system application. |
1679| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1680| 801 | Capability not supported.          |
1681| 2501000  | Operation failed.|
1682
1683**Example**
1684```ts
1685import { wifiManager } from '@kit.ConnectivityKit';
1686
1687let recvDeviceConfigChangeFunc = (result:number) => {
1688    console.info("Receive device config change event: " + result);
1689}
1690
1691// Register an event.
1692wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc);
1693
1694// Unregister an event.
1695wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc);
1696
1697```
1698
1699## wifiManager.on('hotspotStaJoin')<sup>9+</sup>
1700
1701on(type: 'hotspotStaJoin', callback: Callback&lt;StationInfo&gt;): void
1702
1703Subscribes 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.
1704
1705**System API**: This is a system API.
1706
1707**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT
1708
1709**System capability**: SystemCapability.Communication.WiFi.AP.Core
1710
1711**Parameters**
1712
1713| **Name**| **Type**| **Mandatory**| **Description**|
1714| -------- | -------- | -------- | -------- |
1715| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.|
1716| callback | Callback&lt;StationInfo&gt; | Yes| Callback used to return the event.|
1717
1718**Error codes**
1719
1720For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1721
1722| **ID**| **Error Message**|
1723| -------- | -------- |
1724| 201 | Permission denied.                 |
1725| 202 | System API is not allowed called by Non-system application. |
1726| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1727| 801 | Capability not supported.          |
1728| 2601000  | Operation failed. |
1729
1730## wifiManager.off('hotspotStaJoin')<sup>9+</sup>
1731
1732off(type: 'hotspotStaJoin', callback?: Callback&lt;StationInfo&gt;): void
1733
1734Unsubscribes from the event of an STA joining a Wi-Fi hotspot.
1735
1736**System API**: This is a system API.
1737
1738**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT
1739
1740**System capability**: SystemCapability.Communication.WiFi.AP.Core
1741
1742**Parameters**
1743
1744| **Name**| **Type**| **Mandatory**| **Description**|
1745| -------- | -------- | -------- | -------- |
1746| type | string | Yes| Event type, which has a fixed value of **hotspotStaJoin**.|
1747| callback | Callback&lt;StationInfo&gt; | No| Callback to unregister.|
1748
1749**Error codes**
1750
1751For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1752
1753| **ID**| **Error Message**|
1754| -------- | -------- |
1755| 201 | Permission denied.                 |
1756| 202 | System API is not allowed called by Non-system application. |
1757| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1758| 801 | Capability not supported.          |
1759| 2601000  | Operation failed. |
1760
1761**Example**
1762```ts
1763import { wifiManager } from '@kit.ConnectivityKit';
1764
1765let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => {
1766    console.info("Receive hotspot sta join event: " + result);
1767}
1768
1769// Register an event.
1770wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc);
1771
1772// Unregister an event.
1773wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc);
1774
1775```
1776
1777## wifiManager.on('hotspotStaLeave')<sup>9+</sup>
1778
1779on(type: 'hotspotStaLeave', callback: Callback&lt;StationInfo&gt;): void
1780
1781Subscribes 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.
1782
1783**System API**: This is a system API.
1784
1785**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT
1786
1787**System capability**: SystemCapability.Communication.WiFi.AP.Core
1788
1789**Parameters**
1790
1791  | **Name**| **Type**| **Mandatory**| **Description**|
1792  | -------- | -------- | -------- | -------- |
1793  | type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.|
1794  | callback | Callback&lt;StationInf]&gt; | Yes| Callback used to return the event.|
1795
1796**Error codes**
1797
1798For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1799
1800| **ID**| **Error Message**|
1801| -------- | -------- |
1802| 201 | Permission denied.                 |
1803| 202 | System API is not allowed called by Non-system application. |
1804| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1805| 801 | Capability not supported.          |
1806| 2601000  | Operation failed. |
1807
1808## wifiManager.off('hotspotStaLeave')<sup>9+</sup>
1809
1810off(type: 'hotspotStaLeave', callback?: Callback&lt;StationInfo&gt;): void
1811
1812Unsubscribes from the event of an STA leaving a Wi-Fi hotspot.
1813
1814**System API**: This is a system API.
1815
1816**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT
1817
1818**System capability**: SystemCapability.Communication.WiFi.AP.Core
1819
1820**Parameters**
1821
1822| **Name**| **Type**| **Mandatory**| **Description**|
1823| -------- | -------- | -------- | -------- |
1824| type | string | Yes| Event type, which has a fixed value of **hotspotStaLeave**.|
1825| callback | Callback&lt;StationInf]&gt; | No| Callback to unregister.|
1826
1827**Error codes**
1828
1829For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1830
1831| **ID**| **Error Message**|
1832| -------- | -------- |
1833| 201 | Permission denied.                 |
1834| 202 | System API is not allowed called by Non-system application. |
1835| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1836| 801 | Capability not supported.          |
1837| 2601000  | Operation failed. |
1838
1839**Example**
1840```ts
1841import { wifiManager } from '@kit.ConnectivityKit';
1842
1843let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => {
1844    console.info("Receive hotspot sta leave event: " + result);
1845}
1846
1847// Register an event.
1848wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc);
1849
1850// Unregister an event.
1851wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc);
1852
1853```
1854