1# @ohos.wifiManager (WLAN)
2The **wifiManager** module provides basic WLAN functionalities (such as wireless access, wireless encryption, and wireless roaming), basic peer-to-peer (P2P) services, and WLAN notification services. It allows applications to interact with other devices through WLAN.
3
4> **NOTE**
5> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
6
7
8## Modules to Import
9
10```ts
11import { wifiManager } from '@kit.ConnectivityKit';
12```
13
14
15## wifiManager.isWifiActive<sup>9+</sup>
16
17isWifiActive(): boolean
18
19Checks whether WLAN is enabled.
20
21**Atomic service API**: This API can be used in atomic services since API version 11.
22
23**System capability**: SystemCapability.Communication.WiFi.STA
24
25**Return value**
26
27  | **Type**| **Description**|
28  | -------- | -------- |
29  | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.|
30
31**Error codes**
32
33For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
34
35| **ID**| **Error Message**|
36| -------- | -------- |
37| 801 | Capability not supported.          |
38| 2501000  | Operation failed.|
39
40**Example**
41
42```ts
43	import { wifiManager } from '@kit.ConnectivityKit';
44
45	try {
46		let isWifiActive = wifiManager.isWifiActive();
47		console.info("isWifiActive:" + isWifiActive);
48	}catch(error){
49		console.error("failed:" + JSON.stringify(error));
50	}
51```
52
53## wifiManager.scan<sup>9+</sup><sup>(deprecated)</sup>
54
55scan(): void
56
57Starts WLAN scanning. Note that WLAN must have been enabled.
58
59> **NOTE**
60> This API is supported since API version 9 and deprecated since API version 10. The substitute API is available only for system applications.
61
62**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
63
64**System capability**: SystemCapability.Communication.WiFi.STA
65
66**Error codes**
67
68For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
69
70| **ID**| **Error Message**|
71| -------- | -------- |
72| 201 | Permission denied.                 |
73| 801 | Capability not supported.          |
74| 2501000  | Operation failed.|
75
76**Example**
77
78```ts
79	import { wifiManager } from '@kit.ConnectivityKit';
80
81	try {
82		wifiManager.scan();
83	}catch(error){
84		console.error("failed:" + JSON.stringify(error));
85	}
86```
87
88
89## wifiManager.getScanResults<sup>9+</sup><sup>(deprecated)</sup>
90
91getScanResults(): Promise&lt;Array&lt;WifiScanInfo&gt;&gt;
92
93Obtains the scan result. This API uses a promise to return the result.
94
95> **NOTE**
96> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead.
97
98**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION))
99ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications.
100
101**System capability**: SystemCapability.Communication.WiFi.STA
102
103**Return value**
104
105| **Type**| **Description**|
106| -------- | -------- |
107| Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo9)&gt;&nbsp;&gt; | Promise used to return the hotspots detected.|
108
109**Error codes**
110
111For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
112
113| **ID**| **Error Message**|
114| -------- | -------- |
115| 201 | Permission denied.                 |
116| 801 | Capability not supported.          |
117| 2501000  | Operation failed.|
118
119## wifiManager.getScanResults<sup>9+</sup><sup>(deprecated)</sup>
120
121getScanResults(callback: AsyncCallback&lt;Array&lt;WifiScanInfo&gt;&gt;): void
122
123Obtains the scan result. This API uses an asynchronous callback to return the result.
124
125> **NOTE**
126> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead.
127
128**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION))
129ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications.
130
131**System capability**: SystemCapability.Communication.WiFi.STA
132
133**Parameters**
134| **Name**| **Type**| **Mandatory**| **Description**|
135| -------- | -------- | -------- | -------- |
136| callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo9)&gt;&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
137
138**Error codes**
139
140For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
141
142| **ID**| **Error Message**|
143| -------- | -------- |
144| 201 | Permission denied.                 |
145| 801 | Capability not supported.          |
146| 2501000  | Operation failed.|
147
148**Example**
149```ts
150  import { wifiManager } from '@kit.ConnectivityKit';
151
152  wifiManager.getScanResults((err, result) => {
153      if (err) {
154          console.error("get scan info error");
155          return;
156      }
157
158      let len = result.length;
159      console.log("wifi received scan info: " + len);
160      for (let i = 0; i < len; ++i) {
161          console.info("ssid: " + result[i].ssid);
162          console.info("bssid: " + result[i].bssid);
163          console.info("capabilities: " + result[i].capabilities);
164          console.info("securityType: " + result[i].securityType);
165          console.info("rssi: " + result[i].rssi);
166          console.info("band: " + result[i].band);
167          console.info("frequency: " + result[i].frequency);
168          console.info("channelWidth: " + result[i].channelWidth);
169          console.info("timestamp: " + result[i].timestamp);
170      }
171  });
172
173  wifiManager.getScanResults().then(result => {
174      let len = result.length;
175      console.log("wifi received scan info: " + len);
176      for (let i = 0; i < len; ++i) {
177          console.info("ssid: " + result[i].ssid);
178          console.info("bssid: " + result[i].bssid);
179          console.info("capabilities: " + result[i].capabilities);
180          console.info("securityType: " + result[i].securityType);
181          console.info("rssi: " + result[i].rssi);
182          console.info("band: " + result[i].band);
183          console.info("frequency: " + result[i].frequency);
184          console.info("channelWidth: " + result[i].channelWidth);
185          console.info("timestamp: " + result[i].timestamp);
186      }
187  }).catch((err:number) => {
188      console.error("failed:" + JSON.stringify(err));
189  });
190```
191
192## wifiManager.getScanResultsSync<sup>9+</sup><sup>(deprecated)</sup>
193
194getScanResultsSync(): &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo9)&gt;
195
196Obtains the scan result. This API returns the result synchronously.
197
198> **NOTE**
199> This API is supported since API version 9 and deprecated since API version 10. Use [wifiManager.getScanInfoList](#wifimanagergetscaninfolist10) instead.
200
201**Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION))
202ohos.permission.GET_WIFI_PEERS_MAC is available only for system applications.
203
204**System capability**: SystemCapability.Communication.WiFi.STA
205
206**Return value**
207
208| **Type**| **Description**|
209| -------- | -------- |
210| &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo9)&gt; | Scan result obtained.|
211
212**Error codes**
213
214For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
215
216| **ID**| **Error Message**|
217| -------- | -------- |
218| 201 | Permission denied.                 |
219| 801 | Capability not supported.          |
220| 2501000  | Operation failed.|
221
222**Example**
223
224```ts
225	import { wifiManager } from '@kit.ConnectivityKit';
226
227	try {
228		let scanInfoList = wifiManager.getScanResultsSync();
229		console.info("scanInfoList:" + JSON.stringify(scanInfoList));
230		let len = scanInfoList.length;
231        console.log("wifi received scan info: " + len);
232		if(len > 0){
233			for (let i = 0; i < len; ++i) {
234				console.info("ssid: " + scanInfoList[i].ssid);
235				console.info("bssid: " + scanInfoList[i].bssid);
236				console.info("capabilities: " + scanInfoList[i].capabilities);
237				console.info("securityType: " + scanInfoList[i].securityType);
238				console.info("rssi: " + scanInfoList[i].rssi);
239				console.info("band: " + scanInfoList[i].band);
240				console.info("frequency: " + scanInfoList[i].frequency);
241				console.info("channelWidth: " + scanInfoList[i].channelWidth);
242				console.info("timestamp: " + scanInfoList[i].timestamp);
243			}
244		}
245	}catch(error){
246		console.error("failed:" + JSON.stringify(error));
247	}
248
249```
250
251## wifiManager.getScanInfoList<sup>10+</sup>
252
253getScanInfoList(): Array&lt;WifiScanInfo&gt;
254
255Obtains the scanning result.
256
257**Required permissions**: ohos.permission.GET_WIFI_INFO
258
259**Atomic service API**: This API can be used in atomic services since API version 12.
260
261**System capability**: SystemCapability.Communication.WiFi.STA
262
263**Return value**
264
265| **Type**| **Description**|
266| -------- | -------- |
267| Array&lt;[WifiScanInfo](#wifiscaninfo9)&gt; | Hotspots detected. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **bssid** in the return value is a real device address. Otherwise, **bssid** is a random device address.|
268
269**Error codes**
270
271For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
272
273| **ID**| **Error Message**|
274| -------- | -------- |
275| 201 | Permission denied.                 |
276| 801 | Capability not supported.          |
277| 2501000  | Operation failed.|
278
279**Example**
280
281```ts
282	import { wifiManager } from '@kit.ConnectivityKit';
283
284	try {
285		let scanInfoList = wifiManager.getScanInfoList();
286		console.info("scanInfoList:" + JSON.stringify(scanInfoList));
287		let len = scanInfoList.length;
288        console.log("wifi received scan info: " + len);
289		if(len > 0){
290			for (let i = 0; i < len; ++i) {
291				console.info("ssid: " + scanInfoList[i].ssid);
292				console.info("bssid: " + scanInfoList[i].bssid);
293				console.info("capabilities: " + scanInfoList[i].capabilities);
294				console.info("securityType: " + scanInfoList[i].securityType);
295				console.info("rssi: " + scanInfoList[i].rssi);
296				console.info("band: " + scanInfoList[i].band);
297				console.info("frequency: " + scanInfoList[i].frequency);
298				console.info("channelWidth: " + scanInfoList[i].channelWidth);
299				console.info("timestamp: " + scanInfoList[i].timestamp);
300				console.info("supportedWifiCategory: " + scanInfoList[i].supportedWifiCategory);
301				console.info("isHiLinkNetwork: " + scanInfoList[i].isHiLinkNetwork);
302			}
303		}
304	}catch(error){
305		console.error("failed:" + JSON.stringify(error));
306	}
307
308```
309
310## WifiScanInfo<sup>9+</sup>
311
312Represents WLAN hotspot information.
313
314**System capability**: SystemCapability.Communication.WiFi.STA
315
316
317| **Name**| **Type**| **Readable**| **Writable**| **Description**|
318| -------- | -------- | -------- | -------- | -------- |
319| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format. The maximum length is 32 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
320| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot, for example, **00:11:22:33:44:55**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
321| bssidType<sup>10+</sup>| [DeviceAddressType](#deviceaddresstype10) | Yes| No| BSSID type of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
322| capabilities | string | Yes| No| Hotspot capabilities.|
323| securityType | [WifiSecurityType](#wifisecuritytype9) | Yes| No| WLAN security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
324| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
325| band | number | Yes| No| Frequency band of the WLAN access point (AP). The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.|
326| frequency | number | Yes| No| Frequency of the WLAN AP.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
327| channelWidth | number | Yes| No| Channel width of the WLAN AP. For details, see [WifiChannelWidth](#wifichannelwidth9).|
328| centerFrequency0 | number | Yes| No| Center frequency of the hotspot.|
329| centerFrequency1 | number | Yes| No| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.|
330| infoElems | Array&lt;[WifiInfoElem](#wifiinfoelem9)&gt; | Yes| No| Information elements.|
331| timestamp | number | Yes| No| Timestamp.|
332| supportedWifiCategory<sup>12+</sup> | [WifiCategory](#wificategory12) | Yes| No| Highest Wi-Fi category supported by the hotspot.|
333| isHiLinkNetwork<sup>12+</sup> | boolean | Yes| No| Whether the hotspot supports HiLink. The value **true** indicates that the hotspot supports HiLink. The value **false** means the opposite.|
334
335## DeviceAddressType<sup>10+</sup>
336
337Enumerates the Wi-Fi device address (MAC/BSSID) types.
338
339**System capability**: SystemCapability.Communication.WiFi.Core
340
341**Atomic service API**: This API can be used in atomic services since API version 12.
342
343| **Name**| **Value**| **Description**|
344| -------- | -------- | -------- |
345| RANDOM_DEVICE_ADDRESS | 0 | Random device address.|
346| REAL_DEVICE_ADDRESS | 1 | Read device address.|
347
348## WifiSecurityType<sup>9+</sup>
349
350Enumerates the WLAN security types.
351
352**System capability**: SystemCapability.Communication.WiFi.Core
353
354
355| **Name**| **Value**| **Description**|
356| -------- | -------- | -------- |
357| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type.|
358| WIFI_SEC_TYPE_OPEN | 1 | Open security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
359| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP). This type is not supported by the candidate network configuration (**addCandidateConfig**).|
360| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK).|
361| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE).|
362| WIFI_SEC_TYPE_EAP | 5 | Extensible Authentication Protocol (EAP).|
363| WIFI_SEC_TYPE_EAP_SUITE_B | 6 | Suite B 192-bit encryption.|
364| WIFI_SEC_TYPE_OWE | 7 | Opportunistic Wireless Encryption (OWE).|
365| WIFI_SEC_TYPE_WAPI_CERT | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).|
366| WIFI_SEC_TYPE_WAPI_PSK | 9 | WAPI-PSK.|
367
368
369## WifiBandType<sup>10+</sup>
370
371Enumerates the Wi-Fi band types.
372
373**System capability**: SystemCapability.Communication.WiFi.STA
374
375| **Name**| **Value**| **Description**|
376| -------- | -------- | -------- |
377| WIFI_BAND_NONE | 0 | Invalid band type|
378| WIFI_BAND_2G | 1 | 2.4 GHz|
379| WIFI_BAND_5G | 2 | 5 GHz|
380| WIFI_BAND_6G | 3 | 6 GHz|
381| WIFI_BAND_60G | 4 | 60 GHz|
382
383## WifiStandard<sup>10+</sup>
384
385Enumerates the Wi-Fi standards.
386
387**System capability**: SystemCapability.Communication.WiFi.STA
388
389| **Name**| **Value**| **Description**|
390| -------- | -------- | -------- |
391| WIFI_STANDARD_UNDEFINED | 0 | Invalid Wi-Fi standard|
392| WIFI_STANDARD_11A | 1 | 802.11a|
393| WIFI_STANDARD_11B | 2 | 802.11b|
394| WIFI_STANDARD_11G | 3 | 802.11g|
395| WIFI_STANDARD_11N | 4 | 802.11n|
396| WIFI_STANDARD_11AC | 5 | 802.11ac|
397| WIFI_STANDARD_11AX | 6 | 802.11ax|
398| WIFI_STANDARD_11AD | 7 | 802.11ad|
399
400## WifiInfoElem<sup>9+</sup>
401
402Represents a WLAN information element.
403
404**System capability**: SystemCapability.Communication.WiFi.STA
405
406
407| **Name**| **Type**| **Readable**| **Writable**| **Description**|
408| -------- | -------- | -------- | -------- | -------- |
409| eid | number | Yes| No| ID of the information element.|
410| content | Uint8Array | Yes| No| Content of the information element.|
411
412
413## WifiChannelWidth<sup>9+</sup>
414
415Enumerates the WLAN channel widths.
416
417**System capability**: SystemCapability.Communication.WiFi.STA
418
419
420| **Name**| **Value**| **Description**|
421| -------- | -------- | -------- |
422| WIDTH_20MHZ | 0 | 20 MHz|
423| WIDTH_40MHZ | 1 | 40 MHz|
424| WIDTH_80MHZ | 2 | 80 MHz|
425| WIDTH_160MHZ | 3 | 160 MHz|
426| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>|
427| WIDTH_INVALID | 5 | Invalid value|
428
429
430## WifiDeviceConfig<sup>9+</sup>
431
432Represents the WLAN configuration.
433
434**System capability**: SystemCapability.Communication.WiFi.STA
435
436
437| **Name**| **Type**| **Readable**| **Writable**| **Description**|
438| -------- | -------- | -------- | -------- | -------- |
439| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format. The maximum length is 32 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
440| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot, for example, **00:11:22:33:44:55**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
441| bssidType<sup>10+</sup> | [DeviceAddressType](#deviceaddresstype10) | Yes| No| BSSID type of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
442| preSharedKey | string | Yes| No| PSK of the hotspot, which cannot exceed 64 bytes.<br>When **securityType** is **WIFI_SEC_TYPE_OPEN**, this parameter must be an empty string. When **securityType** is any other value, this parameter cannot be empty.<br>When **securityType** is **WIFI_SEC_TYPE_WEP**, the PSK must be of 5, 10, 13, 26, 16, or 32 bytes. If the PSK length is 10, 26, 16, or 32 bytes, the PSK must be a hexadecimal number.<br>When **securityType** is **WIFI_SEC_TYPE_SAE**, the minimum PSK length is 1 byte.<br>When **securityType** is **WIFI_SEC_TYPE_PSK**, the minimum PSK length is 8 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
443| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.|
444| securityType | [WifiSecurityType](#wifisecuritytype9)| Yes| No| Security type.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
445| eapConfig<sup>10+</sup> | [WifiEapConfig](#wifieapconfig10) | Yes| No| EAP configuration. This parameter is mandatory only when **securityType** is **WIFI_SEC_TYPE_EAP**.|
446| wapiConfig<sup>12+</sup> | [WifiWapiConfig](#wifiwapiconfig12) | Yes| No| WAPI configuration. This parameter is mandatory only when **securityType** is **WIFI_SEC_TYPE_WAPI_CERT** or** WIFI_SEC_TYPE_WAPI_PSK**.|
447
448## WifiEapConfig<sup>10+</sup>
449
450Represents EAP configuration information.
451
452**System capability**: SystemCapability.Communication.WiFi.STA
453
454| **Name**| **Type**| **Readable**| **Writable**| **Description**|
455| -------- | -------- | -------- | -------- | -------- |
456| eapMethod | [EapMethod](#eapmethod10) | Yes| No| EAP authentication method.|
457| phase2Method | [Phase2Method](#phase2method10) | Yes| No| Phase 2 authentication method. This parameter is mandatory only when **eapMethod** is **EAP_PEAP** or **EAP_TTLS**.|
458| identity | string | Yes| No| Identity Information. When **eapMethod** is **EAP_PEAP**, **EAP_TLS**, or **EAP_PWD**, this parameter cannot be empty.|
459| anonymousIdentity | string | Yes| No| Anonymous identity. This parameter is not used currently.|
460| password | string | Yes| No| Password. When **eapMethod** is **EAP_PEAP** or **EAP_PWD**, this parameter cannot be empty.|
461| caCertAlias | string | Yes| No| CA certificate alias.|
462| caPath | string | Yes| No| CA certificate path.|
463| clientCertAlias | string | Yes| No| Client certificate alias.|
464| certEntry | Uint8Array | Yes| Yes| CA certificate content. If **eapMethod** is **EAP_TLS** and this parameter is not specified, **clientCertAlias** cannot be empty.|
465| certPassword | string | Yes| Yes| CA certificate password.|
466| altSubjectMatch | string | Yes| No| A string to match the alternate subject.|
467| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.|
468| realm | string | Yes| No| Realm for the passpoint credential.|
469| plmn | string | Yes| No| Public land mobile network (PLMN) of the passpoint credential provider.|
470| eapSubId | number | Yes| No| Sub-ID of the SIM card.|
471
472
473## WifiWapiConfig<sup>12+</sup>
474
475Represents WAPI configuration.
476
477**System capability**: SystemCapability.Communication.WiFi.STA
478
479| **Name**| **Type**| **Readable**| **Writable**| **Description**|
480| -------- | -------- | -------- | -------- | -------- |
481| wapiPskType | [WapiPskType](#wapipsktype12)| Yes| Yes| PSK type.|
482| wapiAsCert | string | No| Yes| AS certificate.|
483| wapiUserCert | string | No| Yes| User Certificate.|
484
485## WapiPskType<sup>12+</sup>
486
487Enumerates the WAPI authentication types.
488
489**System capability**: SystemCapability.Communication.WiFi.Core
490
491| Name| Value| Description|
492| -------- | -------- | -------- |
493| WAPI_PSK_ASCII | 0 | ASCII.|
494| WAPI_PSK_HEX | 1 | HEX.|
495
496## EapMethod<sup>10+</sup>
497
498Enumerates the EAP authentication methods.
499
500**System capability**: SystemCapability.Communication.WiFi.STA
501
502| Name| Value| Description|
503| -------- | -------- | -------- |
504| EAP_NONE | 0 | Not specified.|
505| EAP_PEAP | 1 | PEAP.|
506| EAP_TLS | 2 | TLS.|
507| EAP_TTLS | 3 | TTLS.|
508| EAP_PWD | 4 | Password.|
509| EAP_SIM | 5 | SIM.|
510| EAP_AKA | 6 | AKA.|
511| EAP_AKA_PRIME | 7 | AKA Prime.|
512| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.|
513
514## Phase2Method<sup>10+</sup>
515
516Enumerates the Phase 2 authentication methods.
517
518**System capability**: SystemCapability.Communication.WiFi.STA
519
520| Name| Value| Description|
521| -------- | -------- | -------- |
522| PHASE2_NONE | 0 | Not specified.|
523| PHASE2_PAP | 1 | PAP.|
524| PHASE2_MSCHAP | 2 | MS-CHAP.|
525| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.|
526| PHASE2_GTC | 4 | GTC.|
527| PHASE2_SIM | 5 | SIM.|
528| PHASE2_AKA | 6 | AKA.|
529| PHASE2_AKA_PRIME | 7 | AKA Prime.|
530
531## WifiCategory<sup>12+</sup>
532
533Represents the highest Wi-Fi type supported by a hotspot.
534
535**System capability**: SystemCapability.Communication.WiFi.STA
536
537| Name| Value| Description|
538| -------- | -------- | -------- |
539| DEFAULT | 1 | Default, that is, Wi-Fi types lower than Wi-Fi 6.|
540| WIFI6 | 2 | Wi-Fi 6|
541| WIFI6_PLUS | 3 | Wi-Fi 6+|
542
543## wifiManager.addCandidateConfig<sup>9+</sup>
544
545addCandidateConfig(config: WifiDeviceConfig): Promise&lt;number&gt;
546
547Adds the candidate network configuration. This API uses a promise to return the result. Before using this API, ensure that WLAN is enabled.
548
549**Required permissions**: ohos.permission.SET_WIFI_INFO
550
551**Atomic service API**: This API can be used in atomic services since API version 12.
552
553**System capability**: SystemCapability.Communication.WiFi.STA
554
555**Parameters**
556
557| **Name**| **Type**| **Mandatory**| **Description**|
558| -------- | -------- | -------- | -------- |
559| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.|
560
561**Return value**
562
563  | **Type**| **Description**|
564  | -------- | -------- |
565  | Promise&lt;number&gt; | Promise used to return the network configuration ID.|
566
567**Error codes**
568
569For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
570
571| **ID**| **Error Message**|
572| -------- | ---------------------------- |
573| 201 | Permission denied.                 |
574| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.|
575| 801 | Capability not supported.          |
576| 2501000  | Operation failed.|
577
578**Example**
579`````ts
580	import { wifiManager } from '@kit.ConnectivityKit';
581
582	try {
583		let config:wifiManager.WifiDeviceConfig = {
584			ssid : "****",
585			preSharedKey : "****",
586			securityType : 0
587		}
588		wifiManager.addCandidateConfig(config).then(result => {
589			console.info("result:" + JSON.stringify(result));
590		}).catch((err:number) => {
591			console.error("failed:" + JSON.stringify(err));
592		});
593	}catch(error){
594		console.error("failed:" + JSON.stringify(error));
595	}
596`````
597
598## wifiManager.addCandidateConfig<sup>9+</sup>
599
600addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;number&gt;): void
601
602Adds the configuration of a candidate network. This API uses an asynchronous callback to return the result.
603
604**Required permissions**: ohos.permission.SET_WIFI_INFO
605
606**System capability**: SystemCapability.Communication.WiFi.STA
607
608**Atomic service API**: This API can be used in atomic services since API version 12.
609
610**Parameters**
611
612| **Name**| **Type**| **Mandatory**| **Description**|
613| -------- | -------- | -------- | -------- |
614| config | [WifiDeviceConfig](#wifideviceconfig9) | Yes| WLAN configuration to add. The default **bssidType** is random device address.|
615| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.|
616
617**Error codes**
618
619For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
620
621| **ID**| **Error Message**|
622| -------- | ---------------------------- |
623| 201 | Permission denied.                 |
624| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.|
625| 801 | Capability not supported.          |
626| 2501000  | Operation failed.|
627
628**Example**
629`````ts
630	import { wifiManager } from '@kit.ConnectivityKit';
631
632	try {
633		let config:wifiManager.WifiDeviceConfig = {
634			ssid : "****",
635			preSharedKey : "****",
636			securityType : 0
637		}
638		wifiManager.addCandidateConfig(config,(error,result) => {
639			console.info("result:" + JSON.stringify(result));
640		});
641	}catch(error){
642		console.error("failed:" + JSON.stringify(error));
643	}
644`````
645
646## wifiManager.removeCandidateConfig<sup>9+</sup>
647
648removeCandidateConfig(networkId: number): Promise&lt;void&gt;
649
650Removes the configuration of a candidate network. This API uses a promise to return the result.
651
652**Required permissions**: ohos.permission.SET_WIFI_INFO
653
654**Atomic service API**: This API can be used in atomic services since API version 12.
655
656**System capability**: SystemCapability.Communication.WiFi.STA
657
658**Parameters**
659
660  | **Name**| **Type**| **Mandatory**| **Description**|
661  | -------- | -------- | -------- | -------- |
662  | networkId | number | Yes| ID of the network configuration to remove.|
663
664**Return value**
665
666  | **Type**| **Description**|
667  | -------- | -------- |
668  | Promise&lt;void&gt; | Promise used to return the result.|
669
670**Error codes**
671
672For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
673
674| **ID**| **Error Message**|
675| -------- | ---------------------------- |
676| 201 | Permission denied.                 |
677| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed.|
678| 801 | Capability not supported.          |
679| 2501000  | Operation failed.|
680| 2501001  | Wi-Fi STA disabled. |
681
682**Example**
683
684```ts
685	import { wifiManager } from '@kit.ConnectivityKit';
686
687	try {
688		let networkId = 0;
689		wifiManager.removeCandidateConfig(networkId).then(result => {
690			console.info("result:" + JSON.stringify(result));
691		}).catch((err:number) => {
692			console.error("failed:" + JSON.stringify(err));
693		});
694	}catch(error){
695		console.error("failed:" + JSON.stringify(error));
696	}
697```
698
699## wifiManager.removeCandidateConfig<sup>9+</sup>
700
701removeCandidateConfig(networkId: number, callback: AsyncCallback&lt;void&gt;): void
702
703Removes the configuration of a candidate network. This API uses an asynchronous callback to return the result.
704
705**Required permissions**: ohos.permission.SET_WIFI_INFO
706
707**System capability**: SystemCapability.Communication.WiFi.STA
708
709**Atomic service API**: This API can be used in atomic services since API version 12.
710
711**Parameters**
712
713  | **Name**| **Type**| **Mandatory**| **Description**|
714  | -------- | -------- | -------- | -------- |
715  | networkId | number | Yes| ID of the network configuration to remove.|
716  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0**. If the operation fails, **error** is not **0**.|
717
718**Error codes**
719
720For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
721
722| **ID**| **Error Message**|
723| -------- | ---------------------------- |
724| 201 | Permission denied.                 |
725| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. |
726| 801 | Capability not supported.          |
727| 2501000  | Operation failed.|
728| 2501001  | Wi-Fi STA disabled. |
729
730**Example**
731```ts
732	import { wifiManager } from '@kit.ConnectivityKit';
733
734	try {
735		let networkId = 0;
736		wifiManager.removeCandidateConfig(networkId,(error,result) => {
737		console.info("result:" + JSON.stringify(result));
738		});
739	}catch(error){
740		console.error("failed:" + JSON.stringify(error));
741	}
742```
743
744## wifiManager.getCandidateConfigs<sup>9+</sup>
745
746getCandidateConfigs(): &nbsp;Array&lt;WifiDeviceConfig&gt;
747
748Obtains candidate network configuration.
749
750**Required permissions**:
751
752API version 10 and later: ohos.permission.GET_WIFI_INFO
753
754**Atomic service API**: This API can be used in atomic services since API version 12.
755
756**System capability**: SystemCapability.Communication.WiFi.STA
757
758**Return value**
759
760  | **Type**| **Description**|
761  | -------- | -------- |
762  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig9)&gt; | Candidate network configuration obtained.|
763
764**Error codes**
765
766For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
767
768| **ID**| **Error Message**|
769| -------- | ---------------------------- |
770| 201 | Permission denied.                 |
771| 801 | Capability not supported.          |
772| 2501000  | Operation failed.|
773
774**Example**
775
776```ts
777	import { wifiManager } from '@kit.ConnectivityKit';
778
779	try {
780		let configs = wifiManager.getCandidateConfigs();
781		console.info("configs:" + JSON.stringify(configs));
782		let len = configs.length;
783        console.log("result len: " + len);
784		if(len > 0){
785			for (let i = 0; i < len; ++i) {
786				console.info("ssid: " + configs[i].ssid);
787				console.info("bssid: " + configs[i].bssid);
788			}
789		}
790	}catch(error){
791		console.error("failed:" + JSON.stringify(error));
792	}
793
794```
795
796## wifiManager.connectToCandidateConfig<sup>9+</sup>
797
798connectToCandidateConfig(networkId: number): void
799
800Connects to a candidate network added by the application. If the device is already connected to a hotspot, disconnect it from the hotspot first.
801
802**Required permissions**: ohos.permission.SET_WIFI_INFO
803
804**Atomic service API**: This API can be used in atomic services since API version 12.
805
806**System capability**: SystemCapability.Communication.WiFi.STA
807
808**Parameters**
809
810  | **Name**| **Type**| **Mandatory**| **Description**|
811  | -------- | -------- | -------- | -------- |
812  | networkId | number | Yes| ID of the candidate network configuration.|
813
814**Error codes**
815
816For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
817
818| **ID**| **Error Message**|
819| -------- | ---------------------------- |
820| 201 | Permission denied.                 |
821| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. |
822| 801 | Capability not supported.          |
823| 2501000  | Operation failed.|
824| 2501001  | Wi-Fi STA disabled.|
825
826**Example**
827```ts
828	import { wifiManager } from '@kit.ConnectivityKit';
829
830	try {
831		let networkId = 0; // Candidate network ID, which is generated when a candidate network is added. The value is obtained from WifiDeviceConfig.netId.
832		wifiManager.connectToCandidateConfig(networkId);
833	}catch(error){
834		console.error("failed:" + JSON.stringify(error));
835	}
836
837```
838
839
840## wifiManager.getSignalLevel<sup>9+</sup>
841
842getSignalLevel(rssi: number, band: number): number
843
844Obtains the WLAN signal level.
845
846**Required permissions**: ohos.permission.GET_WIFI_INFO
847
848**System capability**: SystemCapability.Communication.WiFi.STA
849
850**Parameters**
851
852  | **Name**| **Type**| **Mandatory**| **Description**|
853  | -------- | -------- | -------- | -------- |
854  | rssi | number | Yes| RSSI of the hotspot, in dBm.|
855  | band | number | Yes| Frequency band of the WLAN AP. The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.|
856
857**Return value**
858
859  | **Type**| **Description**|
860  | -------- | -------- |
861  | number | Signal level obtained. The value range is [0, 4].|
862
863**Error codes**
864
865For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
866
867| **ID**| **Error Message**|
868| -------- | -------- |
869| 201 | Permission denied.                 |
870| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. |
871| 801 | Capability not supported.          |
872| 2501000  | Operation failed.|
873
874**Example**
875```ts
876	import { wifiManager } from '@kit.ConnectivityKit';
877
878	try {
879		let rssi = 0;
880		let band = 0;
881		let level = wifiManager.getSignalLevel(rssi,band);
882		console.info("level:" + JSON.stringify(level));
883	}catch(error){
884		console.error("failed:" + JSON.stringify(error));
885	}
886
887```
888
889## wifiManager.getLinkedInfo<sup>9+</sup>
890
891getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
892
893Obtains WLAN connection information. This API uses a promise to return the result.
894
895**Required permissions**: ohos.permission.GET_WIFI_INFO
896
897If **macType** to be obtained is **1** (device MAC address), the caller must have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, a random MAC address is returned in **macAddress**.
898
899**Atomic service API**: This API can be used in atomic services since API version 12.
900
901**System capability**: SystemCapability.Communication.WiFi.STA
902
903**Return value**
904
905  | Type| Description|
906  | -------- | -------- |
907  | Promise&lt;[WifiLinkedInfo](#wifilinkedinfo9)&gt; | Promise used to return the WLAN connection information.|
908
909**Error codes**
910
911For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
912
913| **ID**| **Error Message**|
914| -------- | -------- |
915| 201 | Permission denied.                 |
916| 801 | Capability not supported.          |
917| 2501000  | Operation failed.|
918| 2501001  | Wi-Fi STA disabled.|
919
920## wifiManager.getLinkedInfo<sup>9+</sup>
921
922getLinkedInfo(callback: AsyncCallback&lt;WifiLinkedInfo&gt;): void
923
924Obtains WLAN connection information. This API uses an asynchronous callback to return the result.
925
926**Required permissions**: ohos.permission.GET_WIFI_INFO
927
928If **macType** to be obtained is **1** (device MAC address), the caller must have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, a random MAC address is returned in **macAddress**.
929
930**System capability**: SystemCapability.Communication.WiFi.STA
931
932**Parameters**
933
934  | Name| Type| Mandatory| Description|
935  | -------- | -------- | -------- | -------- |
936  | callback | AsyncCallback&lt;[WifiLinkedInfo](#wifilinkedinfo9)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If the operation fails, **err** is not **0**.|
937
938**Error codes**
939
940For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
941
942| **ID**| **Error Message**|
943| -------- | -------- |
944| 201 | Permission denied.                 |
945| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
946| 801 | Capability not supported.          |
947| 2501000  | Operation failed.|
948| 2501001  | Wi-Fi STA disabled.|
949
950**Example**
951```ts
952  import { wifiManager } from '@kit.ConnectivityKit';
953
954  wifiManager.getLinkedInfo((err, data:wifiManager.WifiLinkedInfo) => {
955      if (err) {
956          console.error("get linked info error");
957          return;
958      }
959      console.info("get wifi linked info: " + JSON.stringify(data));
960  });
961
962  wifiManager.getLinkedInfo().then(data => {
963      console.info("get wifi linked info: " + JSON.stringify(data));
964  }).catch((error:number) => {
965      console.info("get linked info error");
966  });
967```
968
969
970## WifiLinkedInfo<sup>9+</sup>
971
972Represents the WLAN connection information.
973
974**System capability**: SystemCapability.Communication.WiFi.STA
975
976| Name| Type| Readable| Writable| Description|
977| -------- | -------- | -------- | -------- | -------- |
978| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
979| bssid | string | Yes| No| BSSID of the hotspot.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
980| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
981| band | number | Yes| No| Frequency band of the WLAN AP. The value **1** indicates 2.4 GHz, and **2** indicates 5 GHz.|
982| linkSpeed | number | Yes| No| Uplink speed of the WLAN AP, in Mbps/s.|
983| rxLinkSpeed<sup>10+</sup> | number | Yes| No| Downlink speed of the WLAN AP, in Mbps/s.|
984| maxSupportedTxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported, in Mbps/s.|
985| maxSupportedRxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum downlink speed supported, in Mbps/s.|
986| frequency | number | Yes| No| Frequency of the WLAN AP.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
987| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.|
988| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.|
989| macType | number | Yes| No| MAC address type. <br>The value **0** indicates random MAC address, and **1** indicates device MAC address.|
990| macAddress | string | Yes| No| MAC address of the device.|
991| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection (the Wi-Fi connection information and the status information of the local device can be viewed.)|
992| connState | [ConnState](#connstate9) | Yes| No| WLAN connection state.|
993| channelWidth<sup>10+</sup> | [WifiChannelWidth](#wifichannelwidth9) | Yes| No| Channel bandwidth of the connected hotspot.|
994| wifiStandard<sup>10+</sup> | [WifiStandard](#wifistandard10) | Yes| No| Wi-Fi standard used by the connected hotspot.|
995| supportedWifiCategory<sup>12+</sup> | [WifiCategory](#wificategory12) | Yes| No| Highest Wi-Fi category supported by the hotspot.|
996| isHiLinkNetwork<sup>12+</sup> | boolean | Yes| No| Whether the hotspot supports HiLink. The value **true** indicates that the hotspot supports HiLink. The value **false** means the opposite.|
997
998## ConnState<sup>9+</sup>
999
1000Enumerates the WLAN connection states.
1001
1002**System capability**: SystemCapability.Communication.WiFi.STA
1003
1004| Name| Value| Description|
1005| -------- | -------- | -------- |
1006| SCANNING | 0 | The device is scanning for available APs.|
1007| CONNECTING | 1 | A WLAN connection is being established.|
1008| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.|
1009| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.|
1010| CONNECTED | 4 | A WLAN connection is established.|
1011| DISCONNECTING | 5 | The WLAN connection is being disconnected.|
1012| DISCONNECTED | 6 | The WLAN connection is disconnected.|
1013| UNKNOWN | 7 | Failed to set up the WLAN connection.|
1014
1015
1016## wifiManager.isConnected<sup>9+</sup>
1017
1018isConnected(): boolean
1019
1020Checks whether WLAN is connected.
1021
1022**Required permissions**: ohos.permission.GET_WIFI_INFO
1023
1024**Atomic service API**: This API can be used in atomic services since API version 12.
1025
1026**System capability**: SystemCapability.Communication.WiFi.STA
1027
1028**Return value**
1029
1030  | **Type**| **Description**|
1031  | -------- | -------- |
1032  | boolean | Returns **true** if WLAN is connected; returns **false** otherwise.|
1033
1034**Error codes**
1035
1036For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1037
1038| **ID**| **Error Message**|
1039| -------- | -------- |
1040| 201 | Permission denied.                 |
1041| 801 | Capability not supported.          |
1042| 2501000  | Operation failed.|
1043
1044**Example**
1045```ts
1046	import { wifiManager } from '@kit.ConnectivityKit';
1047
1048	try {
1049		let ret = wifiManager.isConnected();
1050		console.info("isConnected:" + ret);
1051	}catch(error){
1052		console.error("failed:" + JSON.stringify(error));
1053	}
1054
1055```
1056
1057
1058## wifiManager.isFeatureSupported<sup>9+</sup>
1059
1060isFeatureSupported(featureId: number): boolean
1061
1062Checks whether the device supports the specified WLAN feature.
1063
1064**Required permissions**: ohos.permission.GET_WIFI_INFO
1065
1066**System capability**: SystemCapability.Communication.WiFi.Core
1067
1068**Parameters**
1069
1070  | **Name**| **Type**| Mandatory| **Description**|
1071  | -------- | -------- | -------- | -------- |
1072  | featureId | number | Yes| Feature ID.|
1073
1074**Feature IDs**
1075
1076| Value| Description|
1077| -------- | -------- |
1078| 0x0001 | WLAN infrastructure mode|
1079| 0x0002 | 5 GHz feature|
1080| 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature|
1081| 0x0008 | Wi-Fi Direct|
1082| 0x0010 | SoftAP|
1083| 0x0040 | Wi-Fi Aware|
1084| 0x8000 | WLAN AP/STA concurrency|
1085| 0x8000000 | WPA3 Personal (WPA-3 SAE)|
1086| 0x10000000 | WPA3-Enterprise Suite B |
1087| 0x20000000 | Enhanced open feature|
1088
1089**Return value**
1090
1091  | **Type**| **Description**|
1092  | -------- | -------- |
1093  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
1094
1095**Error codes**
1096
1097For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1098
1099| **ID**| **Error Message**|
1100  | -------- | -------- |
1101| 201 | Permission denied.                 |
1102| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. |
1103| 801 | Capability not supported.          |
1104| 2401000  | Operation failed.|
1105
1106**Example**
1107```ts
1108	import { wifiManager } from '@kit.ConnectivityKit';
1109
1110	try {
1111		let featureId = 0;
1112		let ret = wifiManager.isFeatureSupported(featureId);
1113		console.info("isFeatureSupported:" + ret);
1114	}catch(error){
1115		console.error("failed:" + JSON.stringify(error));
1116	}
1117
1118```
1119
1120
1121## wifiManager.getIpInfo<sup>9+</sup>
1122
1123getIpInfo(): IpInfo
1124
1125Obtains IPv4 information.
1126
1127**Required permissions**: ohos.permission.GET_WIFI_INFO
1128
1129**System capability**: SystemCapability.Communication.WiFi.STA
1130
1131**Return value**
1132
1133  | **Type**| **Description**|
1134  | -------- | -------- |
1135  | [IpInfo](#ipinfo9) | IP information obtained.|
1136
1137**Error codes**
1138
1139For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1140
1141| **ID**| **Error Message**|
1142| -------- | -------- |
1143| 201 | Permission denied.                 |
1144| 801 | Capability not supported.          |
1145| 2501000  | Operation failed.|
1146
1147**Example**
1148```ts
1149	import { wifiManager } from '@kit.ConnectivityKit';
1150
1151	try {
1152		let info = wifiManager.getIpInfo();
1153		console.info("info:" + JSON.stringify(info));
1154	}catch(error){
1155		console.error("failed:" + JSON.stringify(error));
1156	}
1157```
1158
1159## IpInfo<sup>9+</sup>
1160
1161Represents IPv4 information.
1162
1163**System capability**: SystemCapability.Communication.WiFi.STA
1164
1165| **Name**| **Type**| **Readable**| **Writable**| **Description**|
1166| -------- | -------- | -------- | -------- | -------- |
1167| ipAddress | number | Yes| No| IP address.|
1168| gateway | number | Yes| No| Gateway.|
1169| netmask | number | Yes| No| Subnet mask.|
1170| primaryDns | number | Yes| No| IP address of the preferred DNS server.|
1171| secondDns | number | Yes| No| IP address of the alternate DNS server.|
1172| serverIp | number | Yes| No| IP address of the DHCP server.|
1173| leaseDuration | number | Yes| No| Lease duration of the IP address, in seconds.|
1174
1175
1176## wifiManager.getIpv6Info<sup>10+</sup>
1177
1178getIpv6Info(): Ipv6Info
1179
1180Obtains IPv6 information.
1181
1182**Required permissions**: ohos.permission.GET_WIFI_INFO
1183
1184**System capability**: SystemCapability.Communication.WiFi.STA
1185
1186**Return value**
1187
1188| **Type**| **Description**|
1189| -------- | -------- |
1190| [Ipv6Info](#ipv6info10) | IPv6 information obtained.|
1191
1192**Error codes**
1193
1194For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1195
1196| **ID**| **Error Message**|
1197| -------- | -------- |
1198| 201 | Permission denied.                 |
1199| 801 | Capability not supported.          |
1200| 2501000  | Operation failed.|
1201
1202**Example**
1203```ts
1204	import { wifiManager } from '@kit.ConnectivityKit';
1205
1206	try {
1207		let info = wifiManager.getIpv6Info();
1208		console.info("info:" + JSON.stringify(info));
1209	}catch(error){
1210		console.error("failed:" + JSON.stringify(error));
1211	}
1212```
1213## Ipv6Info<sup>10+</sup>
1214
1215Represents the IPv6 information.
1216
1217**System capability**: SystemCapability.Communication.WiFi.STA
1218
1219| **Name**| **Type**| **Readable**| **Writable**| **Description**|
1220| -------- | -------- | -------- | -------- | -------- |
1221| linkIpv6Address | string | Yes| No| IPv6 address of the link.|
1222| globalIpv6Address | string | Yes| No| Global IPv6 address.|
1223| randomGlobalIpv6Address | string | Yes| No| Random global IPv6 address. This parameter is reserved.|
1224| uniqueIpv6Address<sup>12+</sup> | string | Yes| No| Unique local address (ULA) in IPv6 format.|
1225| randomUniqueIpv6Address<sup>12+</sup> | string | Yes| No| Random unique local address (RULA) in IPv6 format.|
1226| gateway | string | Yes| No| Gateway.|
1227| netmask | string | Yes| No| Subnet mask.|
1228| primaryDNS | string | Yes| No| IPv6 address of the preferred DNS server.|
1229| secondDNS | string | Yes| No| IPv6 address of the alternate DNS server.|
1230
1231## wifiManager.getCountryCode<sup>9+</sup>
1232
1233getCountryCode(): string
1234
1235Obtains the country code.
1236
1237**Required permissions**: ohos.permission.GET_WIFI_INFO
1238
1239**System capability**: SystemCapability.Communication.WiFi.Core
1240
1241**Return value**
1242
1243  | **Type**| **Description**|
1244  | -------- | -------- |
1245  | string | Country code obtained.|
1246
1247**Error codes**
1248
1249For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1250
1251| **ID**| **Error Message**|
1252| -------- | -------- |
1253| 201 | Permission denied.                 |
1254| 801 | Capability not supported.          |
1255| 2401000  | Operation failed.|
1256
1257**Example**
1258```ts
1259	import { wifiManager } from '@kit.ConnectivityKit';
1260
1261	try {
1262		let code = wifiManager.getCountryCode();
1263		console.info("code:" + code);
1264	}catch(error){
1265		console.error("failed:" + JSON.stringify(error));
1266	}
1267```
1268
1269
1270
1271
1272## wifiManager.isBandTypeSupported<sup>10+</sup>
1273
1274isBandTypeSupported(bandType: WifiBandType): boolean
1275
1276Checks whether the current frequency band is supported.
1277
1278**Required permissions**: ohos.permission.GET_WIFI_INFO
1279
1280**System capability**: SystemCapability.Communication.WiFi.STA
1281
1282**Parameters**
1283
1284  | **Name**| **Type**| **Mandatory**| **Description**|
1285  | -------- | -------- | -------- | -------- |
1286  | bandType | [WifiBandType](#wifibandtype10) | Yes| Wi-Fi band type.|
1287
1288**Return value**
1289
1290  | **Type**| **Description**|
1291  | -------- | -------- |
1292  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
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| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. |
1302| 801 | Capability not supported.          |
1303| 2501000  | Operation failed.|
1304
1305**Example**
1306```ts
1307	import { wifiManager } from '@kit.ConnectivityKit';
1308
1309	try {
1310		let type = 0;
1311		let isBandTypeSupported = wifiManager.isBandTypeSupported(type);
1312		console.info("isBandTypeSupported:" + isBandTypeSupported);
1313	}catch(error){
1314		console.error("failed:" + JSON.stringify(error));
1315	}
1316```
1317
1318
1319## wifiManager.isMeteredHotspot<sup>11+</sup>
1320
1321isMeteredHotspot(): boolean
1322
1323Checks whether the Wi-Fi network connected to the device is a smartphone hotspot.
1324
1325**Required permissions**: ohos.permission.GET_WIFI_INFO
1326
1327**System capability**: SystemCapability.Communication.WiFi.STA
1328
1329**Return value**
1330
1331  | **Type**| **Description**|
1332  | -------- | -------- |
1333  | boolean | Returns **true** if the Wi-Fi network connected is a smartphone hotspot; returns **false** otherwise.|
1334
1335**Error codes**
1336
1337For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1338
1339| **ID**| **Error Message**|
1340| -------- | -------- |
1341| 201 | Permission denied.                 |
1342| 801 | Capability not supported.          |
1343| 2501000  | Operation failed.|
1344| 2501001  | Wi-Fi STA disabled. |
1345
1346**Example**
1347
1348```ts
1349	import { wifiManager } from '@kit.ConnectivityKit';
1350
1351	try {
1352		let isMeteredHotspot = wifiManager.isMeteredHotspot();
1353		console.info("isMeteredHotspot:" + isMeteredHotspot);
1354	}catch(error){
1355		console.error("failed:" + JSON.stringify(error));
1356	}
1357```
1358
1359
1360
1361## wifiManager.getP2pLinkedInfo<sup>9+</sup>
1362
1363getP2pLinkedInfo(): Promise&lt;WifiP2pLinkedInfo&gt;
1364
1365Obtains P2P connection information. This API uses a promise to return the result.
1366
1367**Required permissions**: ohos.permission.GET_WIFI_INFO
1368
1369To obtain **groupOwnerAddr**, the caller must also have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an all-zero address is returned in **groupOwnerAddr**.
1370
1371**System capability**: SystemCapability.Communication.WiFi.P2P
1372
1373**Return value**
1374
1375  | Type| Description|
1376  | -------- | -------- |
1377  | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Promise used to return the P2P connection information obtained.|
1378
1379**Error codes**
1380
1381For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1382
1383| **ID**| **Error Message**|
1384| -------- | -------- |
1385| 201 | Permission denied.                 |
1386| 801 | Capability not supported.          |
1387| 2801000  | Operation failed. |
1388
1389
1390## wifiManager.getP2pLinkedInfo<sup>9+</sup>
1391
1392getP2pLinkedInfo(callback: AsyncCallback&lt;WifiP2pLinkedInfo&gt;): void
1393
1394Obtains P2P link information. This API uses an asynchronous callback to return the result.
1395
1396**Required permissions**: ohos.permission.GET_WIFI_INFO
1397
1398To obtain **groupOwnerAddr**, the caller must also have the ohos.permission.GET_WIFI_LOCAL_MAC permission, which is available only for system applications. Without this permission, an all-zero address is returned in **groupOwnerAddr**.
1399
1400**System capability**: SystemCapability.Communication.WiFi.P2P
1401
1402**Parameters**
1403
1404  | Name| Type| Mandatory| Description|
1405  | -------- | -------- | -------- | -------- |
1406  | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If the operation fails, **err** is not **0**.|
1407
1408**Error codes**
1409
1410For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1411
1412| **ID**| **Error Message**|
1413| -------- | -------- |
1414| 201 | Permission denied.                 |
1415| 801 | Capability not supported.          |
1416| 2801000  | Operation failed. |
1417| 2801001  | Wi-Fi STA disabled. |
1418
1419**Example**
1420```ts
1421	import { wifiManager } from '@kit.ConnectivityKit';
1422
1423	wifiManager.getP2pLinkedInfo((err, data:wifiManager.WifiP2pLinkedInfo) => {
1424    if (err) {
1425        console.error("get p2p linked info error");
1426        return;
1427    }
1428		console.info("get wifi p2p linked info: " + JSON.stringify(data));
1429	});
1430
1431	wifiManager.getP2pLinkedInfo().then(data => {
1432		console.info("get wifi p2p linked info: " + JSON.stringify(data));
1433	});
1434```
1435
1436
1437## WifiP2pLinkedInfo<sup>9+</sup>
1438
1439Represents the P2P link information.
1440
1441**System capability**: SystemCapability.Communication.WiFi.P2P
1442
1443| Name| Type| Readable| Writable| Description|
1444| -------- | -------- | -------- | -------- | -------- |
1445| connectState | [P2pConnectState](#p2pconnectstate9) | Yes| No| P2P connection state.|
1446| isGroupOwner | boolean | Yes| No| Whether it is the group owner (GO).|
1447| groupOwnerAddr | string | Yes| No| IP address of the group.|
1448
1449
1450## P2pConnectState<sup>9+</sup>
1451
1452Enumerates the P2P connection states.
1453
1454**System capability**: SystemCapability.Communication.WiFi.P2P
1455
1456| Name| Value| Description|
1457| -------- | -------- | -------- |
1458| DISCONNECTED | 0 | Disconnected.|
1459| CONNECTED | 1 | Connected.|
1460
1461## wifiManager.getCurrentGroup<sup>9+</sup>
1462
1463getCurrentGroup(): Promise&lt;WifiP2pGroupInfo&gt;
1464
1465Obtains the current P2P group information. This API uses a promise to return the result.
1466
1467**Required permissions**:
1468
1469API version 10 and later: ohos.permission.GET_WIFI_INFO
1470
1471**System capability**: SystemCapability.Communication.WiFi.P2P
1472
1473**Return value**
1474
1475| Type| Description|
1476| -------- | -------- |
1477| Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt; | Promise used to return the P2P group information obtained. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
1478
1479**Error codes**
1480
1481For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1482
1483| **ID**| **Error Message**|
1484| -------- | -------- |
1485| 201 | Permission denied.                 |
1486| 801 | Capability not supported.          |
1487| 2801000  | Operation failed. |
1488
1489## wifiManager.getCurrentGroup<sup>9+</sup>
1490
1491getCurrentGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void
1492
1493Obtains the current P2P group information. This API uses an asynchronous callback to return the result.
1494
1495**Required permissions**:
1496
1497API version 10 and later: ohos.permission.GET_WIFI_INFO
1498
1499**System capability**: SystemCapability.Communication.WiFi.P2P
1500
1501**Parameters**
1502
1503| Name| Type| Mandatory| Description|
1504| -------- | -------- | -------- | -------- |
1505| callback | AsyncCallback&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If the operation fails, **error** is not **0**. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
1506
1507**Error codes**
1508
1509For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1510
1511| **ID**| **Error Message**|
1512| -------- | -------- |
1513| 201 | Permission denied.                 |
1514| 801 | Capability not supported.          |
1515| 2801000  | Operation failed. |
1516
1517**Example**
1518```ts
1519	import { wifiManager } from '@kit.ConnectivityKit';
1520	// The current group information can be obtained only after the P2P group is created or the connection is successful.
1521	wifiManager.getCurrentGroup((err, data:wifiManager.WifiP2pGroupInfo) => {
1522    if (err) {
1523        console.error("get current P2P group error");
1524        return;
1525    }
1526		console.info("get current P2P group: " + JSON.stringify(data));
1527	});
1528
1529	wifiManager.getCurrentGroup().then(data => {
1530		console.info("get current P2P group: " + JSON.stringify(data));
1531	});
1532```
1533
1534## wifiManager.getP2pPeerDevices<sup>9+</sup>
1535
1536getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;
1537
1538Obtains the peer device list in the P2P connection. This API uses a promise to return the result.
1539
1540**Required permissions**:
1541
1542API version 10 and later: ohos.permission.GET_WIFI_INFO
1543
1544**System capability**: SystemCapability.Communication.WiFi.P2P
1545
1546**Return value**
1547
1548| Type| Description|
1549| -------- | -------- |
1550| Promise&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Promise used to return the peer device list. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
1551
1552**Error codes**
1553
1554For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1555
1556| **ID**| **Error Message**|
1557| -------- | -------- |
1558| 201 | Permission denied.                 |
1559| 801 | Capability not supported.          |
1560| 2801000  | Operation failed. |
1561
1562## wifiManager.getP2pPeerDevices<sup>9+</sup>
1563
1564getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void
1565
1566Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result.
1567
1568**Required permissions**:
1569
1570API version 10 and later: ohos.permission.GET_WIFI_INFO
1571
1572**System capability**: SystemCapability.Communication.WiFi.P2P
1573
1574**Parameters**
1575
1576| Name| Type| Mandatory| Description|
1577| -------- | -------- | -------- | -------- |
1578| callback | AsyncCallback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If the operation fails, **err** is not **0**. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
1579
1580**Error codes**
1581
1582For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1583
1584| **ID**| **Error Message**|
1585| -------- | -------- |
1586| 201 | Permission denied.                 |
1587| 801 | Capability not supported.          |
1588| 2801000  | Operation failed. |
1589| 2801001  | Wi-Fi STA disabled. |
1590
1591**Example**
1592```ts
1593	import { wifiManager } from '@kit.ConnectivityKit';
1594	// The peer device list can be obtained only after the P2P discovery is complete.
1595	wifiManager.getP2pPeerDevices((err, data:wifiManager.WifiP2pDevice) => {
1596    if (err) {
1597        console.error("get P2P peer devices error");
1598        return;
1599    }
1600		console.info("get P2P peer devices: " + JSON.stringify(data));
1601	});
1602
1603	wifiManager.getP2pPeerDevices().then(data => {
1604		console.info("get P2P peer devices: " + JSON.stringify(data));
1605	});
1606```
1607
1608## WifiP2pDevice<sup>9+</sup>
1609
1610Represents the P2P device information.
1611
1612**System capability**: SystemCapability.Communication.WiFi.P2P
1613
1614| Name| Type| Readable| Writable| Description|
1615| -------- | -------- | -------- | -------- | -------- |
1616| deviceName | string | Yes| No| Device name.|
1617| deviceAddress | string | Yes| No| MAC address of the device.|
1618| deviceAddressType<sup>10+</sup> | [DeviceAddressType](#deviceaddresstype10) | Yes| No| MAC address type of the device.|
1619| primaryDeviceType | string | Yes| No| Type of the primary device.|
1620| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus9) | Yes| No| Device status.|
1621| groupCapabilities | number | Yes| No| Group capabilities.|
1622
1623
1624## P2pDeviceStatus<sup>9+</sup>
1625
1626Enumerates the P2P device states.
1627
1628**System capability**: SystemCapability.Communication.WiFi.P2P
1629
1630| Name| Value| Description|
1631| -------- | -------- | -------- |
1632| CONNECTED | 0 | Connected.|
1633| INVITED | 1 | Invited.|
1634| FAILED | 2 | Failed.|
1635| AVAILABLE | 3 | Available.|
1636| UNAVAILABLE | 4 | Unavailable.|
1637
1638
1639## wifiManager.getP2pLocalDevice<sup>9+</sup>
1640
1641getP2pLocalDevice(): Promise&lt;WifiP2pDevice&gt;
1642
1643Obtains the local device information in the P2P connection. This API uses a promise to return the result.
1644
1645**Required permissions**:
1646
1647API version 11 and later: ohos.permission.GET_WIFI_INFO
1648
1649**System capability**: SystemCapability.Communication.WiFi.P2P
1650
1651**Return value**
1652
1653  | Type| Description|
1654  | -------- | -------- |
1655  | Promise&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Promise used to return the local device information obtained.|
1656
1657**Error codes**
1658
1659For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1660
1661| **ID**| **Error Message**|
1662| -------- | -------- |
1663| 201 | Permission denied.                 |
1664| 801 | Capability not supported.          |
1665| 2801000  | Operation failed. |
1666
1667## wifiManager.getP2pLocalDevice<sup>9+</sup>
1668
1669getP2pLocalDevice(callback: AsyncCallback&lt;WifiP2pDevice&gt;): void
1670
1671Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result.
1672
1673**Required permissions**:
1674
1675API version 11 and later: ohos.permission.GET_WIFI_INFO
1676
1677**System capability**: SystemCapability.Communication.WiFi.P2P
1678
1679**Parameters**
1680
1681  | Name| Type| Mandatory| Description|
1682  | -------- | -------- | -------- | -------- |
1683  | callback | AsyncCallback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **0** and **data** is the local device information obtained. If the operation fails, **error** is not **0**.|
1684
1685**Error codes**
1686
1687| **ID**| **Error Message**|
1688| -------- | -------- |
1689| 201 | Permission denied.                 |
1690| 801 | Capability not supported.          |
1691| 2801000  | Operation failed. |
1692| 2801001  | Wi-Fi STA disabled. |
1693
1694**Example**
1695```ts
1696	import { wifiManager } from '@kit.ConnectivityKit';
1697	// The local device information can be obtained only after a P2P group is created or the connection is successful.
1698	wifiManager.getP2pLocalDevice((err, data:wifiManager.WifiP2pDevice) => {
1699    if (err) {
1700        console.error("get P2P local device error");
1701        return;
1702    }
1703		console.info("get P2P local device: " + JSON.stringify(data));
1704	});
1705
1706	wifiManager.getP2pLocalDevice().then(data => {
1707		console.info("get P2P local device: " + JSON.stringify(data));
1708	});
1709```
1710
1711## wifiManager.createGroup<sup>9+</sup>
1712
1713createGroup(config: WifiP2PConfig): void
1714
1715Creates a P2P group.
1716
1717**Required permissions**: ohos.permission.GET_WIFI_INFO
1718
1719**System capability**: SystemCapability.Communication.WiFi.P2P
1720
1721**Parameters**
1722
1723| **Name**| **Type**| Mandatory| **Description**|
1724| -------- | -------- | -------- | -------- |
1725| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration. The default **DeviceAddressType** is random device address.|
1726
1727**Error codes**
1728
1729For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1730
1731| **ID**| **Error Message**|
1732| -------- | -------- |
1733| 201 | Permission denied.                 |
1734| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1735| 801 | Capability not supported.          |
1736| 2801000  | Operation failed. |
1737| 2801001  | Wi-Fi STA disabled. |
1738
1739**Example**
1740```ts
1741	import { wifiManager } from '@kit.ConnectivityKit';
1742
1743	try {
1744		let config:wifiManager.WifiP2PConfig = {
1745			deviceAddress: "****",
1746			netId: 0,
1747			passphrase: "*****",
1748			groupName: "****",
1749			goBand: 0
1750		}
1751		wifiManager.createGroup(config);
1752
1753	}catch(error){
1754		console.error("failed:" + JSON.stringify(error));
1755	}
1756```
1757
1758## WifiP2PConfig<sup>9+</sup>
1759
1760Represents P2P group configuration.
1761
1762**System capability**: SystemCapability.Communication.WiFi.P2P
1763
1764| Name| Type| Readable| Writable| Description|
1765| -------- | -------- | -------- | -------- | -------- |
1766| deviceAddress | string | Yes| No| Device address.|
1767| deviceAddressType<sup>10+</sup>| [DeviceAddressType](#deviceaddresstype10) | Yes| No| Device address type.|
1768| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.|
1769| passphrase | string | Yes| No| Passphrase of the group.|
1770| groupName | string | Yes| No| Name of the group.|
1771| goBand | [GroupOwnerBand](#groupownerband9) | Yes| No| Frequency band of the group.|
1772
1773
1774## GroupOwnerBand<sup>9+</sup>
1775
1776Enumerates the P2P group frequency bands.
1777
1778**System capability**: SystemCapability.Communication.WiFi.P2P
1779
1780| Name| Value| Description|
1781| -------- | -------- | -------- |
1782| GO_BAND_AUTO | 0 | Auto.|
1783| GO_BAND_2GHZ | 1 | 2.4 GHz.|
1784| GO_BAND_5GHZ | 2 | 5 GHz.|
1785
1786
1787## wifiManager.removeGroup<sup>9+</sup>
1788
1789removeGroup(): void
1790
1791Removes this P2P group.
1792
1793**Required permissions**: ohos.permission.GET_WIFI_INFO
1794
1795**System capability**: SystemCapability.Communication.WiFi.P2P
1796
1797**Error codes**
1798
1799For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1800
1801| **ID**| **Error Message**|
1802| -------- | -------- |
1803| 201 | Permission denied.                 |
1804| 801 | Capability not supported.          |
1805| 2801000  | Operation failed. |
1806| 2801001  | Wi-Fi STA disabled. |
1807
1808**Example**
1809```ts
1810	import { wifiManager } from '@kit.ConnectivityKit';
1811
1812	try {
1813		wifiManager.removeGroup();
1814	}catch(error){
1815		console.error("failed:" + JSON.stringify(error));
1816	}
1817```
1818
1819## wifiManager.p2pConnect<sup>9+</sup>
1820
1821p2pConnect(config: WifiP2PConfig): void
1822
1823Sets up a P2P connection.
1824
1825**Required permissions**:
1826
1827API version 10 and later: ohos.permission.GET_WIFI_INFO
1828
1829**System capability**: SystemCapability.Communication.WiFi.P2P
1830
1831**Parameters**
1832
1833| **Name**| **Type**| Mandatory| **Description**|
1834| -------- | -------- | -------- | -------- |
1835| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration. The default **DeviceAddressType** is random device address.|
1836
1837**Error codes**
1838
1839For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1840
1841| **ID**| **Error Message**|
1842| -------- | -------- |
1843| 201 | Permission denied.                 |
1844| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1845| 801 | Capability not supported.          |
1846| 2801000  | Operation failed. |
1847| 2801001  | Wi-Fi STA disabled. |
1848
1849**Example**
1850```ts
1851  import { wifiManager } from '@kit.ConnectivityKit';
1852
1853  let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => {
1854      console.info("p2p connection change receive event: " + JSON.stringify(result));
1855      wifiManager.getP2pLinkedInfo((err, data:wifiManager.WifiP2pLinkedInfo) => {
1856          if (err) {
1857              console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err));
1858              return;
1859          }
1860          console.info("get getP2pLinkedInfo: " + JSON.stringify(data));
1861      });
1862  }
1863  wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
1864
1865  let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => {
1866      console.info("p2p device change receive event: " + JSON.stringify(result));
1867  }
1868  wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
1869
1870  let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => {
1871      console.info("p2p peer device change receive event: " + JSON.stringify(result));
1872      wifiManager.getP2pPeerDevices((err, data:wifiManager.WifiP2pDevice) => {
1873          if (err) {
1874              console.error('failed to get peer devices: ' + JSON.stringify(err));
1875              return;
1876          }
1877          console.info("get peer devices: " + JSON.stringify(data));
1878          let len = data.length;
1879          for (let i = 0; i < len; ++i) {
1880              if (data[i].deviceName === "my_test_device") {
1881                  console.info("p2p connect to test device: " + data[i].deviceAddress);
1882                  let config:wifiManager.WifiP2PConfig = {
1883                      deviceAddress:data[i].deviceAddress,
1884                      netId:-2,
1885                      passphrase:"",
1886                      groupName:"",
1887                      goBand:0,
1888                  }
1889                  wifiManager.p2pConnect(config);
1890              }
1891          }
1892      });
1893  }
1894  wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
1895
1896  let recvP2pPersistentGroupChangeFunc = () => {
1897      console.info("p2p persistent group change receive event");
1898
1899      wifiManager.getCurrentGroup((err, data:wifiManager.WifiP2pGroupInfo) => {
1900          if (err) {
1901              console.error('failed to get current group: ' + JSON.stringify(err));
1902              return;
1903          }
1904          console.info("get current group: " + JSON.stringify(data));
1905      });
1906  }
1907  wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
1908
1909  setTimeout(() => {wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000);
1910  setTimeout(() =>  {wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
1911  setTimeout(() =>  {wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
1912  setTimeout(() =>  {wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
1913  console.info("start discover devices -> " + wifiManager.startDiscoverDevices());
1914```
1915
1916## wifiManager.p2pCancelConnect<sup>9+</sup>
1917
1918p2pCancelConnect(): void
1919
1920Cancels the P2P connection being set up.
1921
1922**Required permissions**: ohos.permission.GET_WIFI_INFO
1923
1924**System capability**: SystemCapability.Communication.WiFi.P2P
1925
1926**Error codes**
1927
1928For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1929
1930| **ID**| **Error Message**|
1931| -------- | -------- |
1932| 201 | Permission denied.                 |
1933| 801 | Capability not supported.          |
1934| 2801000  | Operation failed. |
1935| 2801001  | Wi-Fi STA disabled. |
1936
1937**Example**
1938```ts
1939	import { wifiManager } from '@kit.ConnectivityKit';
1940
1941	try {
1942		wifiManager.p2pCancelConnect();
1943	}catch(error){
1944		console.error("failed:" + JSON.stringify(error));
1945	}
1946```
1947
1948## wifiManager.startDiscoverDevices<sup>9+</sup>
1949
1950startDiscoverDevices(): void
1951
1952Starts to discover devices.
1953
1954**Required permissions**:
1955
1956API version 10 and later: ohos.permission.GET_WIFI_INFO
1957
1958**System capability**: SystemCapability.Communication.WiFi.P2P
1959
1960**Error codes**
1961
1962For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1963
1964| **ID**| **Error Message**|
1965| -------- | -------- |
1966| 201 | Permission denied.                 |
1967| 801 | Capability not supported.          |
1968| 2801000  | Operation failed. |
1969| 2801001  | Wi-Fi STA disabled. |
1970
1971**Example**
1972```ts
1973	import { wifiManager } from '@kit.ConnectivityKit';
1974
1975	try {
1976		wifiManager.startDiscoverDevices();
1977	}catch(error){
1978		console.error("failed:" + JSON.stringify(error));
1979	}
1980```
1981
1982## wifiManager.stopDiscoverDevices<sup>9+</sup>
1983
1984stopDiscoverDevices(): void
1985
1986Stops discovering devices.
1987
1988**Required permissions**: ohos.permission.GET_WIFI_INFO
1989
1990**System capability**: SystemCapability.Communication.WiFi.P2P
1991
1992**Error codes**
1993
1994For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
1995
1996| **ID**| **Error Message**|
1997| -------- | -------- |
1998| 201 | Permission denied.                 |
1999| 801 | Capability not supported.          |
2000| 2801000  | Operation failed. |
2001| 2801001  | Wi-Fi STA disabled. |
2002
2003**Example**
2004```ts
2005	import { wifiManager } from '@kit.ConnectivityKit';
2006
2007	try {
2008		wifiManager.stopDiscoverDevices();
2009	}catch(error){
2010		console.error("failed:" + JSON.stringify(error));
2011	}
2012```
2013
2014
2015
2016## WifiP2pGroupInfo<sup>9+</sup>
2017
2018Represents the P2P group information.
2019
2020**System capability**: SystemCapability.Communication.WiFi.P2P
2021
2022| Name| Type| Readable| Writable| Description|
2023| -------- | -------- | -------- | -------- | -------- |
2024| isP2pGo | boolean | Yes| No| Whether the device is the group owner.|
2025| ownerInfo | [WifiP2pDevice](#wifip2pdevice9) | Yes| No| Device information of the group.|
2026| passphrase | string | Yes| No| Passphrase of the group.|
2027| interface | string | Yes| No| Interface name.|
2028| groupName | string | Yes| No| Group name.|
2029| networkId | number | Yes| No| Network ID.|
2030| frequency | number | Yes| No| Frequency of the group.|
2031| clientDevices | [WifiP2pDevice[]](#wifip2pdevice9) | Yes| No| List of connected devices.|
2032| goIpAddress | string | Yes| No| IP address of the group.|
2033
2034
2035## wifiManager.on('wifiStateChange')<sup>9+</sup>
2036
2037on(type: 'wifiStateChange', callback: Callback&lt;number&gt;): void
2038
2039Subscribes to WLAN state changes. When the service exits, call off(type: 'wifiStateChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2040
2041**Required permissions**: ohos.permission.GET_WIFI_INFO
2042
2043**Atomic service API**: This API can be used in atomic services since API version 12.
2044
2045**System capability**: SystemCapability.Communication.WiFi.STA
2046
2047**Parameters**
2048
2049  | **Name**| **Type**| **Mandatory**| **Description**|
2050  | -------- | -------- | -------- | -------- |
2051  | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.|
2052  | callback | Callback&lt;number&gt; | Yes| Callback used to return the WLAN state.|
2053
2054**Error codes**
2055
2056For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2057
2058| **ID**| **Error Message**|
2059| -------- | ---------------------------- |
2060| 201 | Permission denied.                 |
2061| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2062| 801 | Capability not supported.          |
2063| 2501000  | Operation failed.|
2064
2065**WLAN states**
2066
2067| **Value**| **Description**|
2068| -------- | -------- |
2069| 0 | Deactivated|
2070| 1 | Activated|
2071| 2 | Activating|
2072| 3 | Deactivating|
2073
2074
2075## wifiManager.off('wifiStateChange')<sup>9+</sup>
2076
2077off(type: 'wifiStateChange', callback?: Callback&lt;number&gt;): void
2078
2079Unsubscribes from WLAN state changes.
2080
2081**Required permissions**: ohos.permission.GET_WIFI_INFO
2082
2083**Atomic service API**: This API can be used in atomic services since API version 12.
2084
2085**System capability**: SystemCapability.Communication.WiFi.STA
2086
2087**Parameters**
2088
2089  | **Name**| **Type**| **Mandatory**| **Description**|
2090  | -------- | -------- | -------- | -------- |
2091  | type | string | Yes| Event type, which has a fixed value of **wifiStateChange**.|
2092  | callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2093
2094**Error codes**
2095
2096For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2097
2098| **ID**| **Error Message**|
2099| -------- | ---------------------------- |
2100| 201 | Permission denied.                 |
2101| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2102| 801 | Capability not supported.          |
2103| 2501000  | Operation failed.|
2104
2105**Example**
2106```ts
2107  import { wifiManager } from '@kit.ConnectivityKit';
2108
2109  let recvPowerNotifyFunc = (result:number) => {
2110      console.info("Receive power state change event: " + result);
2111  }
2112
2113  // Register an event.
2114  wifiManager.on("wifiStateChange", recvPowerNotifyFunc);
2115
2116  // Unregister an event.
2117  wifiManager.off("wifiStateChange", recvPowerNotifyFunc);
2118```
2119
2120
2121## wifiManager.on('wifiConnectionChange')<sup>9+</sup>
2122
2123on(type: 'wifiConnectionChange', callback: Callback&lt;number&gt;): void
2124
2125Subscribes to WLAN connection state changes. When the service exits, call off(type: 'wifiConnectionChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2126
2127**Required permissions**: ohos.permission.GET_WIFI_INFO
2128
2129**Atomic service API**: This API can be used in atomic services since API version 12.
2130
2131**System capability**: SystemCapability.Communication.WiFi.STA
2132
2133**Parameters**
2134
2135  | **Name**| **Type**| **Mandatory**| **Description**|
2136  | -------- | -------- | -------- | -------- |
2137  | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.|
2138  | callback | Callback&lt;number&gt; | Yes| Callback used to return the WLAN connection state.|
2139
2140**WLAN connection states**
2141
2142| **Value**| **Description**|
2143| -------- | -------- |
2144| 0 | Disconnected.|
2145| 1 | Connected.|
2146
2147**Error codes**
2148
2149For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2150
2151| **ID**| **Error Message**|
2152| -------- | ---------------------------- |
2153| 201 | Permission denied.                 |
2154| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2155| 801 | Capability not supported.          |
2156| 2501000  | Operation failed.|
2157
2158## wifiManager.off('wifiConnectionChange')<sup>9+</sup>
2159
2160off(type: 'wifiConnectionChange', callback?: Callback&lt;number&gt;): void
2161
2162Unsubscribes from WLAN connection state changes.
2163
2164**Required permissions**: ohos.permission.GET_WIFI_INFO
2165
2166**Atomic service API**: This API can be used in atomic services since API version 12.
2167
2168**System capability**: SystemCapability.Communication.WiFi.STA
2169
2170**Parameters**
2171
2172  | **Name**| **Type**| **Mandatory**| **Description**|
2173  | -------- | -------- | -------- | -------- |
2174  | type | string | Yes| Event type, which has a fixed value of **wifiConnectionChange**.|
2175  | callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2176
2177**Error codes**
2178
2179For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2180
2181| **ID**| **Error Message**|
2182| -------- | ---------------------------- |
2183| 201 | Permission denied.                 |
2184| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2185| 801 | Capability not supported.          |
2186| 2501000  | Operation failed.|
2187
2188**Example**
2189```ts
2190  import { wifiManager } from '@kit.ConnectivityKit';
2191
2192  let recvWifiConnectionChangeFunc = (result:number) => {
2193      console.info("Receive wifi connection change event: " + result);
2194  }
2195
2196  // Register an event.
2197  wifiManager.on("wifiConnectionChange", recvWifiConnectionChangeFunc);
2198
2199  // Unregister an event.
2200  wifiManager.off("wifiConnectionChange", recvWifiConnectionChangeFunc);
2201```
2202
2203## wifiManager.on('wifiScanStateChange')<sup>9+</sup>
2204
2205on(type: 'wifiScanStateChange', callback: Callback&lt;number&gt;): void
2206
2207Subscribes to WLAN scan state changes. When the service exits, call off(type: 'wifiScanStateChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2208
2209**Required permissions**: ohos.permission.GET_WIFI_INFO
2210
2211**Atomic service API**: This API can be used in atomic services since API version 12.
2212
2213**System capability**: SystemCapability.Communication.WiFi.STA
2214
2215**Parameters**
2216
2217  | **Name**| **Type**| **Mandatory**| **Description**|
2218  | -------- | -------- | -------- | -------- |
2219  | type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.|
2220  | callback | Callback&lt;number&gt; | Yes| Callback used to return the WLAN scan state.|
2221
2222**WLAN scan states**
2223
2224| **Value**| **Description**|
2225| -------- | -------- |
2226| 0 | Scan failed.|
2227| 1 | Scan successful.|
2228
2229**Error codes**
2230
2231For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2232
2233| **ID**| **Error Message**|
2234| -------- | ---------------------------- |
2235| 201 | Permission denied.                 |
2236| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2237| 801 | Capability not supported.          |
2238| 2501000  | Operation failed.|
2239
2240## wifiManager.off('wifiScanStateChange')<sup>9+</sup>
2241
2242off(type: 'wifiScanStateChange', callback?: Callback&lt;number&gt;): void
2243
2244Unsubscribes from WLAN scan state changes.
2245
2246**Required permissions**: ohos.permission.GET_WIFI_INFO
2247
2248**Atomic service API**: This API can be used in atomic services since API version 12.
2249
2250**System capability**: SystemCapability.Communication.WiFi.STA
2251
2252**Parameters**
2253
2254| **Name**| **Type**| **Mandatory**| **Description**|
2255| -------- | -------- | -------- | -------- |
2256| type | string | Yes| Event type, which has a fixed value of **wifiScanStateChange**.|
2257| callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2258
2259**Error codes**
2260
2261For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2262
2263| **ID**| **Error Message**|
2264| -------- | ---------------------------- |
2265| 201 | Permission denied.                 |
2266| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2267| 801 | Capability not supported.          |
2268| 2501000  | Operation failed.|
2269
2270**Example**
2271```ts
2272  import { wifiManager } from '@kit.ConnectivityKit';
2273
2274  let recvWifiScanStateChangeFunc = (result:number) => {
2275      console.info("Receive Wifi scan state change event: " + result);
2276  }
2277
2278  // Register an event.
2279  wifiManager.on("wifiScanStateChange", recvWifiScanStateChangeFunc);
2280
2281  // Unregister an event.
2282  wifiManager.off("wifiScanStateChange", recvWifiScanStateChangeFunc);
2283```
2284
2285## wifiManager.on('wifiRssiChange')<sup>9+</sup>
2286
2287on(type: 'wifiRssiChange', callback: Callback&lt;number&gt;): void
2288
2289Subscribes to RSSI changes. When the service exits, call off(type: 'wifiRssiChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2290
2291**Required permissions**: ohos.permission.GET_WIFI_INFO
2292
2293**System capability**: SystemCapability.Communication.WiFi.STA
2294
2295**Parameters**
2296
2297  | **Name**| **Type**| **Mandatory**| **Description**|
2298  | -------- | -------- | -------- | -------- |
2299  | type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.|
2300  | callback | Callback&lt;number&gt; | Yes| Callback used to return the RSSI, in dBm.|
2301
2302**Error codes**
2303
2304For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2305
2306| **ID**| **Error Message**|
2307| -------- | ---------------------------- |
2308| 201 | Permission denied.                 |
2309| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2310| 801 | Capability not supported.          |
2311| 2501000  | Operation failed.|
2312
2313## wifiManager.off('wifiRssiChange')<sup>9+</sup>
2314
2315off(type: 'wifiRssiChange', callback?: Callback&lt;number&gt;): void
2316
2317Unsubscribes from RSSI changes.
2318
2319**Required permissions**: ohos.permission.GET_WIFI_INFO
2320
2321**System capability**: SystemCapability.Communication.WiFi.STA
2322
2323**Parameters**
2324
2325| **Name**| **Type**| **Mandatory**| **Description**|
2326| -------- | -------- | -------- | -------- |
2327| type | string | Yes| Event type, which has a fixed value of **wifiRssiChange**.|
2328| callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2329
2330**Error codes**
2331
2332For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2333
2334| **ID**| **Error Message**|
2335| -------- | ---------------------------- |
2336| 201 | Permission denied.                 |
2337| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2338| 801 | Capability not supported.          |
2339| 2501000  | Operation failed.|
2340
2341**Example**
2342```ts
2343  import { wifiManager } from '@kit.ConnectivityKit';
2344
2345  let recvWifiRssiChangeFunc = (result:number) => {
2346      console.info("Receive wifi rssi change event: " + result);
2347  }
2348
2349  // Register an event.
2350  wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc);
2351
2352  // Unregister an event.
2353  wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc);
2354```
2355
2356## wifiManager.on('hotspotStateChange')<sup>9+</sup>
2357
2358on(type: 'hotspotStateChange', callback: Callback&lt;number&gt;): void
2359
2360Subscribes to hotspot state changes. When the service exits, call off(type: 'hotspotStateChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2361
2362**Required permissions**: ohos.permission.GET_WIFI_INFO
2363
2364**System capability**: SystemCapability.Communication.WiFi.AP.Core
2365
2366**Parameters**
2367
2368| **Name**| **Type**| **Mandatory**| **Description**|
2369| -------- | -------- | -------- | -------- |
2370| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.|
2371| callback | Callback&lt;number&gt; | Yes| Callback used to return the hotspot state.|
2372
2373**Hotspot states**
2374
2375| **Value**| **Description**|
2376| -------- | -------- |
2377| 0 | Deactivated|
2378| 1 | Activated|
2379| 2 | Activating|
2380| 3 | Deactivating|
2381
2382**Error codes**
2383
2384For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2385
2386| **ID**| **Error Message**|
2387| -------- | ---------------------------- |
2388| 201 | Permission denied.                 |
2389| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2390| 801 | Capability not supported.          |
2391| 2601000  | Operation failed. |
2392
2393## wifiManager.off('hotspotStateChange')<sup>9+</sup>
2394
2395off(type: 'hotspotStateChange', callback?: Callback&lt;number&gt;): void
2396
2397Unsubscribes from hotspot state changes.
2398
2399**Required permissions**: ohos.permission.GET_WIFI_INFO
2400
2401**System capability**: SystemCapability.Communication.WiFi.AP.Core
2402
2403**Parameters**
2404
2405| **Name**| **Type**| **Mandatory**| **Description**|
2406| -------- | -------- | -------- | -------- |
2407| type | string | Yes| Event type, which has a fixed value of **hotspotStateChange**.|
2408| callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2409
2410**Error codes**
2411
2412For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2413
2414| **ID**| **Error Message**|
2415| -------- | ---------------------------- |
2416| 201 | Permission denied.                 |
2417| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2418| 801 | Capability not supported.          |
2419| 2601000  | Operation failed. |
2420
2421**Example**
2422```ts
2423  import { wifiManager } from '@kit.ConnectivityKit';
2424
2425  let recvHotspotStateChangeFunc = (result:number) => {
2426      console.info("Receive hotspot state change event: " + result);
2427  }
2428
2429  // Register an event.
2430  wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc);
2431
2432  // Unregister an event.
2433  wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc);
2434```
2435
2436
2437## wifiManager.on('p2pStateChange')<sup>9+</sup>
2438
2439on(type: 'p2pStateChange', callback: Callback&lt;number&gt;): void
2440
2441Subscribes to P2P state changes. When the service exits, call off(type: 'p2pStateChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2442
2443**Required permissions**: ohos.permission.GET_WIFI_INFO
2444
2445**System capability**: SystemCapability.Communication.WiFi.P2P
2446
2447**Parameters**
2448
2449| **Name**| **Type**| **Mandatory**| **Description**|
2450| -------- | -------- | -------- | -------- |
2451| type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.|
2452| callback | Callback&lt;number&gt; | Yes| Callback used to return the P2P state.|
2453
2454**P2P states**
2455
2456| **Value**| **Description**|
2457| -------- | -------- |
2458| 1 | Available|
2459| 2 | Opening|
2460| 3 | Opened|
2461| 4 | Closing|
2462| 5 | Closed|
2463
2464**Error codes**
2465
2466For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2467
2468| **ID**| **Error Message**|
2469| -------- | ---------------------------- |
2470| 201 | Permission denied.                 |
2471| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2472| 801 | Capability not supported.          |
2473| 2801000  | Operation failed. |
2474
2475## wifiManager.off('p2pStateChange')<sup>9+</sup>
2476
2477off(type: 'p2pStateChange', callback?: Callback&lt;number&gt;): void
2478
2479Unsubscribes from P2P state changes.
2480
2481**Required permissions**: ohos.permission.GET_WIFI_INFO
2482
2483**System capability**: SystemCapability.Communication.WiFi.P2P
2484
2485**Parameters**
2486
2487  | **Name**| **Type**| **Mandatory**| **Description**|
2488  | -------- | -------- | -------- | -------- |
2489  | type | string | Yes| Event type, which has a fixed value of **p2pStateChange**.|
2490  | callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2491
2492**Error codes**
2493
2494For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2495
2496| **ID**| **Error Message**|
2497| -------- | ---------------------------- |
2498| 201 | Permission denied.                 |
2499| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2500| 801 | Capability not supported.          |
2501| 2801000  | Operation failed. |
2502
2503**Example**
2504```ts
2505  import { wifiManager } from '@kit.ConnectivityKit';
2506
2507  let recvP2pStateChangeFunc = (result:number) => {
2508      console.info("Receive p2p state change event: " + result);
2509  }
2510
2511  // Register an event.
2512  wifiManager.on("p2pStateChange", recvP2pStateChangeFunc);
2513
2514  // Unregister an event.
2515  wifiManager.off("p2pStateChange", recvP2pStateChangeFunc);
2516```
2517
2518## wifiManager.on('p2pConnectionChange')<sup>9+</sup>
2519
2520on(type: 'p2pConnectionChange', callback: Callback&lt;WifiP2pLinkedInfo&gt;): void
2521
2522Subscribes to P2P connection state changes. When the service exits, call off(type: 'p2pConnectionChange', callback?: Callback&lt;WifiP2pLinkedInfo&gt;) to unregister the callback registered.
2523
2524**Required permissions**: ohos.permission.GET_WIFI_INFO
2525
2526**System capability**: SystemCapability.Communication.WiFi.P2P
2527
2528**Parameters**
2529
2530  | **Name**| **Type**| **Mandatory**| **Description**|
2531  | -------- | -------- | -------- | -------- |
2532  | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.|
2533  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Yes| Callback used to return the WLAN state.|
2534
2535**Error codes**
2536
2537For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2538
2539| **ID**| **Error Message**|
2540| -------- | ---------------------------- |
2541| 201 | Permission denied.                 |
2542| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2543| 801 | Capability not supported.          |
2544| 2801000  | Operation failed. |
2545
2546## wifiManager.off('p2pConnectionChange')<sup>9+</sup>
2547
2548off(type: 'p2pConnectionChange', callback?: Callback&lt;WifiP2pLinkedInfo&gt;): void
2549
2550Unsubscribes from P2P connection state changes.
2551
2552**Required permissions**: ohos.permission.GET_WIFI_INFO
2553
2554**System capability**: SystemCapability.Communication.WiFi.P2P
2555
2556**Parameters**
2557
2558  | **Name**| **Type**| **Mandatory**| **Description**|
2559  | -------- | -------- | -------- | -------- |
2560  | type | string | Yes| Event type, which has a fixed value of **p2pConnectionChange**.|
2561  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2562
2563**Error codes**
2564
2565For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2566
2567| **ID**| **Error Message**|
2568| -------- | ---------------------------- |
2569| 201 | Permission denied.                 |
2570| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2571| 801 | Capability not supported.          |
2572| 2801000  | Operation failed. |
2573
2574**Example**
2575```ts
2576  import { wifiManager } from '@kit.ConnectivityKit';
2577
2578  let recvP2pConnectionChangeFunc = (result:wifiManager.WifiP2pLinkedInfo) => {
2579      console.info("Receive p2p connection change event: " + result);
2580  }
2581
2582  // Register an event.
2583  wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
2584
2585  // Unregister an event.
2586  wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);
2587```
2588
2589## wifiManager.on('p2pDeviceChange')<sup>9+</sup>
2590
2591on(type: 'p2pDeviceChange', callback: Callback&lt;WifiP2pDevice&gt;): void
2592
2593Subscribes to P2P device status changes. When the service exits, call off(type: 'p2pDeviceChange', callback?: Callback&lt;WifiP2pDevice&gt;) to unregister the callback registered.
2594
2595**Required permissions**:
2596
2597API version 10 and later: ohos.permission.GET_WIFI_INFO
2598
2599**System capability**: SystemCapability.Communication.WiFi.P2P
2600
2601**Parameters**
2602
2603  | **Name**| **Type**| **Mandatory**| **Description**|
2604  | -------- | -------- | -------- | -------- |
2605  | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.|
2606  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Yes| Callback used to return the WLAN state.|
2607
2608**Error codes**
2609
2610For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2611
2612| **ID**| **Error Message**|
2613| -------- | ---------------------------- |
2614| 201 | Permission denied.                 |
2615| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2616| 801 | Capability not supported.          |
2617| 2801000  | Operation failed. |
2618
2619## wifiManager.off('p2pDeviceChange')<sup>9+</sup>
2620
2621off(type: 'p2pDeviceChange', callback?: Callback&lt;WifiP2pDevice&gt;): void
2622
2623Unsubscribes from P2P device state changes.
2624
2625**System capability**: SystemCapability.Communication.WiFi.P2P
2626
2627**Parameters**
2628
2629  | **Name**| **Type**| **Mandatory**| **Description**|
2630  | -------- | -------- | -------- | -------- |
2631  | type | string | Yes| Event type, which has a fixed value of **p2pDeviceChange**.|
2632  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2633
2634**Error codes**
2635
2636For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2637
2638| **ID**| **Error Message**|
2639| -------- | ---------------------------- |
2640| 201<sup>10+</sup> | Permission denied.                 |
2641| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2642| 801 | Capability not supported.          |
2643| 2801000  | Operation failed. |
2644
2645**Example**
2646```ts
2647  import { wifiManager } from '@kit.ConnectivityKit';
2648
2649  let recvP2pDeviceChangeFunc = (result:wifiManager.WifiP2pDevice) => {
2650      console.info("Receive p2p device change event: " + result);
2651  }
2652
2653  // Register an event.
2654  wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
2655
2656  // Unregister an event.
2657  wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);
2658```
2659
2660## wifiManager.on('p2pPeerDeviceChange')<sup>9+</sup>
2661
2662on(type: 'p2pPeerDeviceChange', callback: Callback&lt;WifiP2pDevice[]&gt;): void
2663
2664Subscribes to P2P peer device status changes. When the service exits, call off(type: 'p2pPeerDeviceChange', callback?: Callback&lt;WifiP2pDevice[]&gt;) to unregister the callback registered.
2665
2666**Required permissions**:
2667
2668API version 10 and later: ohos.permission.GET_WIFI_INFO
2669
2670**System capability**: SystemCapability.Communication.WiFi.P2P
2671
2672**Parameters**
2673
2674| **Name**| **Type**| **Mandatory**| **Description**|
2675| -------- | -------- | -------- | -------- |
2676| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.|
2677| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Yes| Callback used to return the peer device status. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
2678
2679**Error codes**
2680
2681For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2682
2683| **ID**| **Error Message**|
2684| -------- | ---------------------------- |
2685| 201 | Permission denied.                 |
2686| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2687| 801 | Capability not supported.          |
2688| 2801000  | Operation failed. |
2689
2690## wifiManager.off('p2pPeerDeviceChange')<sup>9+</sup>
2691
2692off(type: 'p2pPeerDeviceChange', callback?: Callback&lt;WifiP2pDevice[]&gt;): void
2693
2694Unsubscribes from P2P peer device state changes.
2695
2696**System capability**: SystemCapability.Communication.WiFi.P2P
2697
2698**Parameters**
2699
2700| **Name**| **Type**| **Mandatory**| **Description**|
2701| -------- | -------- | -------- | -------- |
2702| type | string | Yes| Event type, which has a fixed value of **p2pPeerDeviceChange**.|
2703| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event. If the caller has the ohos.permission.GET_WIFI_PEERS_MAC permission (available only for system applications), **deviceAddress** in the return value is a real device address. Otherwise, **deviceAddress** is a random device address.|
2704
2705**Error codes**
2706
2707For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2708
2709| **ID**| **Error Message**|
2710| -------- | ---------------------------- |
2711| 201<sup>10+</sup> | Permission denied.                 |
2712| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2713| 801 | Capability not supported.          |
2714| 2801000  | Operation failed. |
2715
2716**Example**
2717```ts
2718  import { wifiManager } from '@kit.ConnectivityKit';
2719
2720  let recvP2pPeerDeviceChangeFunc = (result:wifiManager.WifiP2pDevice[]) => {
2721      console.info("Receive p2p peer device change event: " + result);
2722  }
2723
2724  // Register an event.
2725  wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
2726
2727  // Unregister an event.
2728  wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
2729```
2730
2731## wifiManager.on('p2pPersistentGroupChange')<sup>9+</sup>
2732
2733on(type: 'p2pPersistentGroupChange', callback: Callback&lt;void&gt;): void
2734
2735Subscribes to P2P persistent group changes. When the service exits, call off(type: 'p2pPersistentGroupChange', callback?: Callback&lt;void&gt;) to unregister the callback registered.
2736
2737**Required permissions**: ohos.permission.GET_WIFI_INFO
2738
2739**System capability**: SystemCapability.Communication.WiFi.P2P
2740
2741**Parameters**
2742
2743  | **Name**| **Type**| **Mandatory**| **Description**|
2744  | -------- | -------- | -------- | -------- |
2745  | type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.|
2746  | callback | Callback&lt;void&gt; | Yes| Callback used to return the WLAN state.|
2747
2748**Error codes**
2749
2750For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2751
2752| **ID**| **Error Message**|
2753| -------- | ---------------------------- |
2754| 201 | Permission denied.                 |
2755| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2756| 801 | Capability not supported.          |
2757| 2801000  | Operation failed. |
2758
2759## wifiManager.off('p2pPersistentGroupChange')<sup>9+</sup>
2760
2761off(type: 'p2pPersistentGroupChange', callback?: Callback&lt;void&gt;): void
2762
2763Unsubscribes from P2P persistent group state changes.
2764
2765**Required permissions**: ohos.permission.GET_WIFI_INFO
2766
2767**System capability**: SystemCapability.Communication.WiFi.P2P
2768
2769**Parameters**
2770
2771| **Name**| **Type**| **Mandatory**| **Description**|
2772| -------- | -------- | -------- | -------- |
2773| type | string | Yes| Event type, which has a fixed value of **p2pPersistentGroupChange**.|
2774| callback | Callback&lt;void&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2775
2776**Error codes**
2777
2778For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2779
2780| **ID**| **Error Message**|
2781| -------- | ---------------------------- |
2782| 201 | Permission denied.                 |
2783| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2784| 801 | Capability not supported.          |
2785| 2801000  | Operation failed. |
2786
2787**Example**
2788```ts
2789  import { wifiManager } from '@kit.ConnectivityKit';
2790
2791  let recvP2pPersistentGroupChangeFunc = (result:void) => {
2792      console.info("Receive p2p persistent group change event: " + result);
2793  }
2794
2795  // Register an event.
2796  wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
2797
2798  // Unregister an event.
2799  wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
2800```
2801
2802## wifiManager.on('p2pDiscoveryChange')<sup>9+</sup>
2803
2804on(type: 'p2pDiscoveryChange', callback: Callback&lt;number&gt;): void
2805
2806Subscribes to P2P device discovery changes. When the service exits, call off(type: 'p2pDiscoveryChange', callback?: Callback&lt;number&gt;) to unregister the callback registered.
2807
2808**Required permissions**: ohos.permission.GET_WIFI_INFO
2809
2810**System capability**: SystemCapability.Communication.WiFi.P2P
2811
2812**Parameters**
2813
2814  | **Name**| **Type**| **Mandatory**| **Description**|
2815  | -------- | -------- | -------- | -------- |
2816  | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.|
2817  | callback | Callback&lt;number&gt; | Yes| Callback used to return the P2P device discovery change.|
2818
2819**P2P discovered device states**
2820
2821| **Value**| **Description**|
2822| -------- | -------- |
2823| 0 | Initial state.|
2824| 1 | Discovered.|
2825
2826**Error codes**
2827
2828For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2829
2830| **ID**| **Error Message**|
2831| -------- | ---------------------------- |
2832| 201 | Permission denied.                 |
2833| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2834| 801 | Capability not supported.          |
2835| 2801000  | Operation failed. |
2836
2837## wifiManager.off('p2pDiscoveryChange')<sup>9+</sup>
2838
2839off(type: 'p2pDiscoveryChange', callback?: Callback&lt;number&gt;): void
2840
2841Unsubscribes from P2P device discovery state changes.
2842
2843**Required permissions**: ohos.permission.GET_WIFI_INFO
2844
2845**System capability**: SystemCapability.Communication.WiFi.P2P
2846
2847**Parameters**
2848
2849  | **Name**| **Type**| **Mandatory**| **Description**|
2850  | -------- | -------- | -------- | -------- |
2851  | type | string | Yes| Event type, which has a fixed value of **p2pDiscoveryChange**.|
2852  | callback | Callback&lt;number&gt; | No| Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified event.|
2853
2854**Error codes**
2855
2856For details about the error codes, see [Wi-Fi Error Codes](errorcode-wifi.md).
2857
2858| **ID**| **Error Message**|
2859| -------- | ---------------------------- |
2860| 201 | Permission denied.                 |
2861| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2862| 801 | Capability not supported.          |
2863| 2801000  | Operation failed. |
2864
2865**Example**
2866```ts
2867  import { wifiManager } from '@kit.ConnectivityKit';
2868
2869  let recvP2pDiscoveryChangeFunc = (result:number) => {
2870      console.info("Receive p2p discovery change event: " + result);
2871  }
2872
2873  // Register an event.
2874  wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
2875
2876  // Unregister an event.
2877  wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
2878```
2879