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