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