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