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