• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# WLAN
2
3> **NOTE**<br>
4> 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.
5
6
7## Modules to Import
8
9```js
10import wifi from '@ohos.wifi';
11```
12
13## wifi.isWifiActive
14
15isWifiActive(): boolean
16
17Checks whether the WLAN is activated.
18
19- **Required permissions**:
20  ohos.permission.GET_WIFI_INFO
21
22- **System capability**:
23  SystemCapability.Communication.WiFi.STA
24
25- **Return value**
26  | **Type**| **Description**|
27  | -------- | -------- |
28  | boolean | Returns **true** if the WLAN is activated; returns **false** otherwise.|
29
30
31## wifi.scan
32
33scan(): boolean
34
35Starts a scan for WLAN.
36
37- **Required permissions**:
38  ohos.permission.SET_WIFI_INFO and ohos.permission.LOCATION
39
40- **System capability**:
41  SystemCapability.Communication.WiFi.STA
42
43- **Return value**
44  | **Type**| **Description**|
45  | -------- | -------- |
46  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
47
48
49## wifi.getScanInfos
50
51getScanInfos(): Promise&lt;Array&lt;WifiScanInfo&gt;&gt;
52
53Obtains the scan result. This API uses a promise to return the result.
54
55- **Required permissions**:
56  ohos.permission.GET_WIFI_INFO, ohos.permission.GET_WIFI_PEERS_MAC, or ohos.permission.LOCATION
57
58- **System capability**:
59  SystemCapability.Communication.WiFi.STA
60
61- **Return value**
62  | **Type**| **Description**|
63  | -------- | -------- |
64  | Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the scan result, which is a list of hotspots detected.|
65
66
67## wifi.getScanInfos
68
69getScanInfos(callback: AsyncCallback&lt;Array&lt;WifiScanInfo&gt;&gt;): void
70
71Obtains the scan result. This API uses an asynchronous callback to return the result.
72
73- **Required permissions**:
74  ohos.permission.GET_WIFI_INFO, ohos.permission.GET_WIFI_PEERS_MAC, or ohos.permission.LOCATION
75
76- **System capability**:
77  SystemCapability.Communication.WiFi.STA
78
79- **Parameters**
80  | **Name**| **Type**| **Mandatory**| **Description**|
81  | -------- | -------- | -------- | -------- |
82  | callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&gt; | Yes| Callback invoked to return the result, which is a list of hotspots detected.|
83
84- **Example**
85  ```js
86  import wifi from '@ohos.wifi';
87
88  wifi.getScanInfos((err, result) => {
89      if (err) {
90          console.error("get scan info error");
91          return;
92      }
93
94      var len = Object.keys(result).length;
95      console.log("wifi received scan info: " + len);
96      for (var i = 0; i < len; ++i) {
97          console.info("ssid: " + result[i].ssid);
98          console.info("bssid: " + result[i].bssid);
99          console.info("capabilities: " + result[i].capabilities);
100          console.info("securityType: " + result[i].securityType);
101          console.info("rssi: " + result[i].rssi);
102          console.info("band: " + result[i].band);
103          console.info("frequency: " + result[i].frequency);
104          console.info("channelWidth: " + result[i].channelWidth);
105          console.info("timestamp: " + result[i].timestamp);
106      }
107  });
108
109  wifi.getScanInfos().then(result => {
110      var len = Object.keys(result).length;
111      console.log("wifi received scan info: " + len);
112      for (var i = 0; i < len; ++i) {
113          console.info("ssid: " + result[i].ssid);
114          console.info("bssid: " + result[i].bssid);
115          console.info("capabilities: " + result[i].capabilities);
116          console.info("securityType: " + result[i].securityType);
117          console.info("rssi: " + result[i].rssi);
118          console.info("band: " + result[i].band);
119          console.info("frequency: " + result[i].frequency);
120          console.info("channelWidth: " + result[i].channelWidth);
121          console.info("timestamp: " + result[i].timestamp);
122      }
123  });
124  ```
125
126
127## WifiScanInfo
128
129Represents WLAN hotspot information.
130
131| **Name**| **Type**| **Readable/Writable**| **Description**|
132| -------- | -------- | -------- | -------- |
133| ssid | string | Read only| Service set identifier (SSID) of the hotspot, in UTF-8 format.|
134| bssid | string | Read only| Basic service set identifier (BSSID) of the hotspot.|
135| capabilities | string | Read only| Hotspot capabilities.|
136| securityType | [WifiSecurityType](#WifiSecurityType) | Read only| WLAN security type.|
137| rssi | number | Read only| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
138| band | number | Read only| Frequency band of the WLAN access point (AP).|
139| frequency | number | Read only| Frequency of the WLAN AP.|
140| channelWidth | number | Read only| Channel width of the WLAN AP.|
141| timestamp | number | Read only| Timestamp.|
142
143
144## WifiSecurityType
145
146Enumerates the WLAN security types.
147
148| **Name**| **Default Value**| **Description**|
149| -------- | -------- | -------- |
150| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type|
151| WIFI_SEC_TYPE_OPEN | 1 | Open security type|
152| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP)|
153| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK)|
154| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE)|
155
156
157## wifi.addUntrustedConfig<sup>7+</sup>
158
159addUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;
160
161Adds untrusted WLAN configuration. This API uses a promise to return the result.
162- **NOTE**<br>This API is not supported by OpenHarmony 3.1 Release.
163
164- **Required permissions**:
165  ohos.permission.SET_WIFI_INFO
166
167- **System capability**:
168  SystemCapability.Communication.WiFi.STA
169
170- **Parameters**
171  | **Name**| **Type**| **Mandatory**| **Description**|
172  | -------- | -------- | -------- | -------- |
173  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to add.|
174
175- **Return value**
176  | **Type**| **Description**|
177  | -------- | -------- |
178  | Promise&lt;boolean&gt; | Promise used to return the operation result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
179
180## WifiDeviceConfig
181
182Represents the WLAN configuration.
183
184| **Name**| **Type**| **Readable/Writable**| **Description**|
185| -------- | -------- | -------- | -------- |
186| ssid | string | Read only| SSID of the hotspot, in UTF-8 format.|
187| bssid | string | Read only| BSSID of the hotspot.|
188| preSharedKey | string | Read only| PSK of the hotspot.|
189| isHiddenSsid | boolean | Read only| Whether the network is hidden.|
190| securityType | [WifiSecurityType](#WifiSecurityType) | Read only| Security type.|
191
192
193## wifi.addUntrustedConfig<sup>7+</sup>
194
195addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void
196
197Adds untrusted WLAN configuration. This API uses an asynchronous callback to return the result.
198
199- **NOTE**<br>This API is not supported by OpenHarmony 3.1 Release.
200
201- **Required permissions**:
202  ohos.permission.SET_WIFI_INFO
203
204- **System capability**:
205  SystemCapability.Communication.WiFi.STA
206
207- **Parameters**
208  | **Name**| **Type**| **Mandatory**| **Description**|
209  | -------- | -------- | -------- | -------- |
210  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to add.|
211  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback invoked to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
212
213
214## wifi.removeUntrustedConfig<sup>7+</sup>
215
216removeUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;
217
218Removes untrusted WLAN configuration. This API uses a promise to return the result.
219
220- **Required permissions**:
221  ohos.permission.SET_WIFI_INFO
222
223- **System capability**:
224  SystemCapability.Communication.WiFi.STA
225
226- **Parameters**
227  | **Name**| **Type**| **Mandatory**| **Description**|
228  | -------- | -------- | -------- | -------- |
229  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to remove.|
230
231- **Return value**
232  | **Type**| **Description**|
233  | -------- | -------- |
234  | Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
235
236
237## wifi.removeUntrustedConfig<sup>7+</sup>
238
239removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void
240
241Removes untrusted WLAN configuration. This API uses an asynchronous callback to return the result.
242
243- **Required permissions**:
244  ohos.permission.SET_WIFI_INFO
245
246- **System capability**:
247  SystemCapability.Communication.WiFi.STA
248
249- **Parameters**
250  | **Name**| **Type**| **Mandatory**| **Description**|
251  | -------- | -------- | -------- | -------- |
252  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to remove.|
253  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback invoked used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
254
255
256## wifi.getSignalLevel
257
258getSignalLevel(rssi: number, band: number): number
259
260Obtains the WLAN signal level.
261
262- **Required permissions**:
263  ohos.permission.GET_WIFI_INFO
264
265- **System capability**:
266  SystemCapability.Communication.WiFi.STA
267
268- **Parameters**
269  | **Name**| **Type**| **Mandatory**| **Description**|
270  | -------- | -------- | -------- | -------- |
271  | rssi | number | Yes| RSSI of the hotspot, in dBm.|
272  | band | number | Yes| Frequency band of the WLAN AP.|
273
274- **Return value**
275  | **Type**| **Description**|
276  | -------- | -------- |
277  | number | Signal level obtained. The value range is [0, 4].|
278
279
280## wifi.getLinkedInfo
281
282getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
283
284Obtains WLAN connection information. This API uses a promise to return the result.
285
286- **Required permissions**:
287  ohos.permission.GET_WIFI_INFO
288
289- **System capability**:
290  SystemCapability.Communication.WiFi.STA
291
292- **Return value**
293  | Type| Description|
294  | -------- | -------- |
295  | Promise&lt;[WifiLinkedInfo](#WifiLinkedInfo)&gt; | Promise used to return the WLAN connection information obtained.|
296
297
298## wifi.getLinkedInfo
299
300getLinkedInfo(callback: AsyncCallback&lt;WifiLinkedInfo&gt;): void
301
302Obtains WLAN connection information. This API uses a callback to return the result.
303
304- **Required permissions**:
305  ohos.permission.GET_WIFI_INFO
306
307- **System capability**:
308  SystemCapability.Communication.WiFi.STA
309
310- **Parameters**
311  | Name| Type| Mandatory| Description|
312  | -------- | -------- | -------- | -------- |
313  | callback | AsyncCallback&lt;[WifiLinkedInfo](#WifiLinkedInfo)&gt; | Yes| Callback invoked to return the WLAN connection information obtained.|
314
315- **Example**
316  ```js
317  import wifi from '@ohos.wifi';
318
319  wifi.getLinkedInfo((err, data) => {
320      if (err) {
321          console.error("get linked info error");
322          return;
323      }
324      console.info("get wifi linked info: " + JSON.stringify(data));
325  });
326
327  wifi.getLinkedInfo().then(data => {
328      console.info("get wifi linked info: " + JSON.stringify(data));
329  }).catch(error => {
330      console.info("get linked info error");
331  });
332  ```
333
334
335## WifiLinkedInfo
336
337Represents the WLAN connection information.
338
339| Name| Type| Readable/Writable| Description|
340| -------- | -------- | -------- | -------- |
341| ssid | string | Read only| SSID of the hotspot, in UTF-8 format.|
342| bssid | string | Read only| BSSID of the hotspot.|
343| rssi | number | Read only| RSSI of the hotspot, in dBm.|
344| band | number | Read only| Frequency band of the WLAN AP.|
345| linkSpeed | number | Read only| Speed of the WLAN AP.|
346| frequency | number | Read only| Frequency of the WLAN AP.|
347| isHidden | boolean | Read only| Whether the WLAN AP is hidden.|
348| isRestricted | boolean | Read only| Whether data volume is restricted at the WLAN AP.|
349| macAddress | string | Read only| MAC address of the device.|
350| ipAddress | number | Read only| IP address of the device that sets up the WLAN connection.|
351| connState | [ConnState](#ConnState) | Read only| WLAN connection state.|
352
353
354## ConnState
355
356Enumerates the WLAN connection states.
357
358| Name| Default Value| Description|
359| -------- | -------- | -------- |
360| SCANNING | 0 | The device is scanning for available APs.|
361| CONNECTING | 1 | A WLAN connection is being established.|
362| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.|
363| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.|
364| CONNECTED | 4 | A WLAN connection is established.|
365| DISCONNECTING | 5 | The WLAN connection is being disconnected.|
366| DISCONNECTED | 6 | The WLAN connection is disconnected.|
367| UNKNOWN | 7 | Failed to set up the WLAN connection.|
368
369
370## wifi.isConnected<sup>7+</sup>
371
372isConnected(): boolean
373
374Checks whether the WLAN is connected.
375
376- **Required permissions**:
377  ohos.permission.GET_WIFI_INFO
378
379- **System capability**:
380  SystemCapability.Communication.WiFi.STA
381
382- **Return value**
383  | **Type**| **Description**|
384  | -------- | -------- |
385  | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|
386
387
388## wifi.isFeatureSupported<sup>7+</sup>
389
390isFeatureSupported(featureId: number): boolean
391
392Checks whether the device supports the specified WLAN feature.
393
394- **Required permissions**:
395  ohos.permission.GET_WIFI_INFO
396
397- **System capability**:
398  SystemCapability.Communication.WiFi.Core
399
400- **Parameters**
401  | **Name**| **Type**| Mandatory| **Description**|
402  | -------- | -------- | -------- | -------- |
403  | featureId | number | Yes| Feature ID.|
404
405- **Return value**
406  | **Type**| **Description**|
407  | -------- | -------- |
408  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
409
410- Enumerates the WLAN features.
411  | Value| Description|
412  | -------- | -------- |
413  | 0x0001 | WLAN infrastructure mode|
414  | 0x0002 | 5 GHz feature|
415  | 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature|
416  | 0x0008 | Wi-Fi Direct|
417  | 0x0010 | SoftAP|
418  | 0x0040 | Wi-Fi AWare|
419  | 0x8000 | WLAN AP/STA concurrency|
420  | 0x8000000 | WPA3 Personal (WPA-3 SAE)|
421  | 0x10000000 | WPA3-Enterprise Suite B |
422  | 0x20000000 | Enhanced open feature|
423
424
425## wifi.getIpInfo<sup>7+</sup>
426
427getIpInfo(): IpInfo
428
429Obtains IP information.
430
431- **Required permissions**:
432  ohos.permission.GET_WIFI_INFO
433
434- **System capability**:
435  SystemCapability.Communication.WiFi.STA
436
437- **Return value**
438  | **Type**| **Description**|
439  | -------- | -------- |
440  | [IpInfo](#IpInfo) | IP information obtained.|
441
442
443## IpInfo<sup>7+</sup>
444
445Represents IP information.
446
447| **Name**| **Type**| **Readable/Writable**| **Description**|
448| -------- | -------- | -------- | -------- |
449| ipAddress | number | Read only| IP address.|
450| gateway | number | Read only| Gateway.|
451| netmask | number | Read only| Subnet mask.|
452| primaryDns | number | Read only| IP address of the preferred DNS server.|
453| secondDns | number | Read only| IP address of the alternate DNS server.|
454| serverIp | number | Read only| IP address of the DHCP server.|
455| leaseDuration | number | Read only| Lease duration of the IP address.|
456
457
458## wifi.getCountryCode<sup>7+</sup>
459
460getCountryCode(): string
461
462Obtains the country code.
463
464- **Required permissions**:
465  ohos.permission.GET_WIFI_INFO
466
467- **System capability**:
468  SystemCapability.Communication.WiFi.Core
469
470- **Return value**
471  | **Type**| **Description**|
472  | -------- | -------- |
473  | string | Country code obtained.|
474
475
476## wifi.getP2pLinkedInfo<sup>8+</sup>
477
478getP2pLinkedInfo(): Promise&lt;WifiP2pLinkedInfo&gt;
479
480Obtains peer-to-peer (P2P) connection information. This API uses a promise to return the result.
481
482- **Required permissions**:
483  ohos.permission.GET_WIFI_INFO
484
485- **System capability**:
486  SystemCapability.Communication.WiFi.P2P
487
488- **Return value**
489  | Type| Description|
490  | -------- | -------- |
491  | Promise&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Promise used to return the P2P connection information obtained.|
492
493
494## wifi.getP2pLinkedInfo<sup>8+</sup>
495
496getP2pLinkedInfo(callback: AsyncCallback&lt;WifiP2pLinkedInfo&gt;): void
497
498Obtains P2P connection information. This API uses an asynchronous callback to return the result.
499
500- **Required permissions**:
501  ohos.permission.GET_WIFI_INFO
502
503- **System capability**:
504  SystemCapability.Communication.WiFi.P2P
505
506- **Parameters**
507  | Name| Type| Mandatory| Description|
508  | -------- | -------- | -------- | -------- |
509  | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Yes| Callback invoked to return the P2P connection information obtained.|
510
511
512## WifiP2pLinkedInfo<sup>8+</sup>
513
514Represents the WLAN connection information.
515
516| Name| Type| Readable/Writable| Description|
517| -------- | -------- | -------- | -------- |
518| connectState | [P2pConnectState](#P2pConnectState) | Read only| P2P connection state.|
519| isGroupOwner | boolean | Read only| Whether it is a group.|
520| groupOwnerAddr | string | Read only| MAC address of the group.|
521
522
523## P2pConnectState<sup>8+</sup>
524
525Enumerates the P2P connection states.
526
527| Name| Default Value| Description|
528| -------- | -------- | -------- |
529| DISCONNECTED | 0 | Disconnected|
530| CONNECTED | 1 | Connected|
531
532
533## wifi.getCurrentGroup<sup>8+</sup>
534
535getCurrentGroup(): Promise&lt;WifiP2pGroupInfo&gt;
536
537Obtains the current P2P group information. This API uses a promise to return the result.
538
539- **Required permissions**:
540  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
541
542- **System capability**:
543  SystemCapability.Communication.WiFi.P2P
544
545- **Return value**
546  | Type| Description|
547  | -------- | -------- |
548  | Promise&lt;[WifiP2pGroupInfo](#WifiP2pGroupInfo)&gt; | Promise used to return the P2P group information obtained.|
549
550
551## wifi.getCurrentGroup<sup>8+</sup>
552
553getCurrentGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void
554
555Obtains the P2P group information. This API uses an asynchronous callback to return the result.
556
557- **Required permissions**:
558  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
559
560- **System capability**:
561  SystemCapability.Communication.WiFi.P2P
562
563- **Parameters**
564  | Name| Type| Mandatory| Description|
565  | -------- | -------- | -------- | -------- |
566  | callback | AsyncCallback&lt;[WifiP2pGroupInfo](#WifiP2pGroupInfo)&gt; | Yes| Callback invoked to return the P2P group information obtained.|
567
568
569## WifiP2pGroupInfo<sup>8+</sup>
570
571Represents the P2P group information.
572
573| Name| Type| Readable/Writable| Description|
574| -------- | -------- | -------- | -------- |
575| isP2pGo | boolean | Read only| Whether it is a group.|
576| ownerInfo | [WifiP2pDevice](#WifiP2pDevice) | Read only| Device information of the group.|
577| passphrase | string | Read only| Passphrase of the group.|
578| interface | string | Read only| Interface name.|
579| groupName | string | Read only| Group name.|
580| networkId | number | Read only| Network ID.|
581| frequency | number | Read only| Frequency of the group.|
582| clientDevices | [WifiP2pDevice[]](#WifiP2pDevice) | Read only| List of connected devices.|
583| goIpAddress | string | Read only| IP address of the group.|
584
585## WifiP2pDevice<sup>8+</sup>
586
587Represents the P2P device information.
588
589| Name| Type| Readable/Writable| Description|
590| -------- | -------- | -------- | -------- |
591| deviceName | string | Read only| Device name.|
592| deviceAddress | string | Read only| MAC address of the device.|
593| primaryDeviceType | string | Read only| Type of the primary device.|
594| deviceStatus | [P2pDeviceStatus](#P2pDeviceStatus) | Read only| Device status.|
595| groupCapabilities | number | Read only| Group capabilities.|
596
597## P2pDeviceStatus<sup>8+</sup>
598
599Enumerates the P2P device states.
600
601| Name| Default Value| Description|
602| -------- | -------- | -------- |
603| CONNECTED | 0 | Connected|
604| INVITED | 1 | Invited|
605| FAILED | 2 | Failed|
606| AVAILABLE | 3 | Available|
607| UNAVAILABLE | 4 | Unavailable|
608
609
610## wifi.getP2pPeerDevices<sup>8+</sup>
611
612getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;
613
614Obtains the list of peer devices in the P2P connection. This API uses a promise to return the result.
615
616- **Required permissions**:
617  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
618
619- **System capability**:
620  SystemCapability.Communication.WiFi.P2P
621
622- **Return value**
623  | Type| Description|
624  | -------- | -------- |
625  | Promise&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Promise used to return the peer device list obtained.|
626
627
628## wifi.getP2pPeerDevices<sup>8+</sup>
629
630getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void
631
632Obtains the list of peer devices in the P2P connection. This API uses an asynchronous callback to return the result.
633
634- **Required permissions**:
635  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
636
637- **System capability**:
638  SystemCapability.Communication.WiFi.P2P
639
640- **Parameters**
641  | Name| Type| Mandatory| Description|
642  | -------- | -------- | -------- | -------- |
643  | callback | AsyncCallback&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Yes| Callback involed to return the peer device list obtained.|
644
645
646## wifi.createGroup<sup>8+</sup>
647
648createGroup(config: WifiP2PConfig): boolean;
649
650Creates a P2P group.
651
652- **Required permissions**:
653  ohos.permission.GET_WIFI_INFO
654
655- **System capability**:
656  SystemCapability.Communication.WiFi.P2P
657
658- **Parameters**
659  | **Name**| **Type**| Mandatory| **Description**|
660  | -------- | -------- | -------- | -------- |
661  | config | [WifiP2PConfig](#WifiP2PConfig) | Yes| Group configuration.|
662
663- **Return value**
664  | Type| Description|
665  | -------- | -------- |
666  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
667
668## WifiP2PConfig<sup>8+</sup>
669
670Represents P2P group configuration.
671
672| Name| Type| Readable/Writable| Description|
673| -------- | -------- | -------- | -------- |
674| deviceAddress | string | Read only| Device address.|
675| netId | number | Read only| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.|
676| passphrase | string | Read only| Passphrase of the group.|
677| groupName | string | Read only| Name of the group.|
678| goBand | [GroupOwnerBand](#GroupOwnerBand) | Read only| Frequency band of the group.|
679
680
681## GroupOwnerBand<sup>8+</sup>
682
683Enumerates the P2P group frequency bands.
684
685| Name| Default Value| Description|
686| -------- | -------- | -------- |
687| GO_BAND_AUTO | 0 | Auto|
688| GO_BAND_2GHZ | 1 | 2 GHz|
689| GO_BAND_5GHZ | 2 | 5 GHz|
690
691## wifi.removeGroup<sup>8+</sup>
692
693removeGroup(): boolean;
694
695Removes this P2P group.
696
697- **Required permissions**:
698  ohos.permission.GET_WIFI_INFO
699
700- **System capability**:
701  SystemCapability.Communication.WiFi.P2P
702
703- **Return value**
704  | Type| Description|
705  | -------- | -------- |
706  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
707
708
709## wifi.p2pConnect<sup>8+</sup>
710
711p2pConnect(config: WifiP2PConfig): boolean;
712
713Sets up a P2P connection.
714
715- **Required permissions**:
716  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
717
718- **System capability**:
719  SystemCapability.Communication.WiFi.P2P
720
721- **Parameters**
722  | **Name**| **Type**| Mandatory| **Description**|
723  | -------- | -------- | -------- | -------- |
724  | config | [WifiP2PConfig](#WifiP2PConfig) | Yes| P2P group configuration.|
725
726- **Return value**
727  | Type| Description|
728  | -------- | -------- |
729  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
730
731
732- **Example**
733  ```js
734  import wifi from '@ohos.wifi';
735
736  var recvP2pConnectionChangeFunc = result => {
737      console.info("p2p connection change receive event: " + JSON.stringify(result));
738      wifi.getP2pLinkedInfo((err, data) => {
739          if (err) {
740              console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err));
741              return;
742          }
743          console.info("get getP2pLinkedInfo: " + JSON.stringify(data));
744      });
745  }
746  wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
747
748  var recvP2pDeviceChangeFunc = result => {
749      console.info("p2p device change receive event: " + JSON.stringify(result));
750  }
751  wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
752
753  var recvP2pPeerDeviceChangeFunc = result => {
754      console.info("p2p peer device change receive event: " + JSON.stringify(result));
755      wifi.getP2pPeerDevices((err, data) => {
756          if (err) {
757              console.error('failed to get peer devices: ' + JSON.stringify(err));
758              return;
759          }
760          console.info("get peer devices: " + JSON.stringify(data));
761          var len = Object.keys(data).length;
762          for (var i = 0; i < len; ++i) {
763              if (data[i].deviceName === "my_test_device") {
764                  console.info("p2p connect to test device: " + data[i].deviceAddress);
765                  var config = {
766                      "deviceAddress":data[i].deviceAddress,
767                      "netId":-2,
768                      "passphrase":"",
769                      "groupName":"",
770                      "goBand":0,
771                  }
772                  wifi.p2pConnect(config);
773              }
774          }
775      });
776  }
777  wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
778
779  var recvP2pPersistentGroupChangeFunc = result => {
780      console.info("p2p persistent group change receive event");
781
782      wifi.getCurrentGroup((err, data) => {
783          if (err) {
784              console.error('failed to get current group: ' + JSON.stringify(err));
785              return;
786          }
787          console.info("get current group: " + JSON.stringify(data));
788      });
789  }
790  wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
791
792  setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000);
793  setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
794  setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
795  setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
796  console.info("start discover devices -> " + wifi.startDiscoverDevices());
797  ```
798
799## wifi.p2pCancelConnect<sup>8+</sup>
800
801p2pCancelConnect(): boolean;
802
803Cancels this P2P connection.
804
805- **Required permissions**:
806  ohos.permission.GET_WIFI_INFO
807
808- **System capability**:
809  SystemCapability.Communication.WiFi.P2P
810
811- **Return value**
812  | Type| Description|
813  | -------- | -------- |
814  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
815
816
817## wifi.startDiscoverDevices<sup>8+</sup>
818
819startDiscoverDevices(): boolean;
820
821Starts to discover devices.
822
823- **Required permissions**:
824  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
825
826- **System capability**:
827  SystemCapability.Communication.WiFi.P2P
828
829- **Return value**
830  | Type| Description|
831  | -------- | -------- |
832  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
833
834
835## wifi.stopDiscoverDevices<sup>8+</sup>
836
837stopDiscoverDevices(): boolean;
838
839Stops discovering devices.
840
841- **Required permissions**:
842  ohos.permission.GET_WIFI_INFO
843
844- **System capability**:
845  SystemCapability.Communication.WiFi.P2P
846
847- **Return value**
848  | Type| Description|
849  | -------- | -------- |
850  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
851
852
853## wifi.on('wifiStateChange')<sup>7+</sup>
854
855on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
856
857Registers the WLAN state change events.
858
859- **Required permissions**:
860  ohos.permission.GET_WIFI_INFO
861
862- **System capability**:
863  SystemCapability.Communication.WiFi.STA
864
865- **Parameters**
866  | **Name**| **Type**| **Mandatory**| **Description**|
867  | -------- | -------- | -------- | -------- |
868  | type | string | Yes| Event type. The value is **wifiStateChange**.|
869  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN state.|
870
871- Enumerates the WLAN states.
872  | **Value**| **Description**|
873  | -------- | -------- |
874  | 0 | Deactivated|
875  | 1 | Activated|
876  | 2 | Activating|
877  | 3 | Deactivating|
878
879
880## wifi.off('wifiStateChange')<sup>7+</sup>
881
882off(type: "wifiStateChange", callback?: Callback&lt;number&gt;): void
883
884Unregisters the WLAN state change events.
885
886- **Required permissions**:
887  ohos.permission.GET_WIFI_INFO
888
889- **System capability**:
890  SystemCapability.Communication.WiFi.STA
891
892- **Parameters**
893  | **Name**| **Type**| **Mandatory**| **Description**|
894  | -------- | -------- | -------- | -------- |
895  | type | string | Yes| Event type. The value is **wifiStateChange**.|
896  | callback | Callback&lt;number&gt; | No| Callback used to return the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
897
898- **Example**
899  ```js
900  import wifi from '@ohos.wifi';
901
902  var WIFI_POWER_STATE = "wifiStateChange";
903  var recvPowerNotifyFunc = result => {
904      console.info("Receive power state change event: " + result);
905  }
906
907  // Register an event.
908  wifi.on(WIFI_POWER_STATE, recvPowerNotifyFunc);
909
910  // Unregister an event.
911  wifi.off(WIFI_POWER_STATE, recvPowerNotifyFunc);
912  ```
913
914
915## wifi.on('wifiConnectionChange')<sup>7+</sup>
916
917on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
918
919Registers the WLAN connection state change events.
920
921- **Required permissions**:
922  ohos.permission.GET_WIFI_INFO
923
924- **System capability**:
925  SystemCapability.Communication.WiFi.STA
926
927- **Parameters**
928  | **Name**| **Type**| **Mandatory**| **Description**|
929  | -------- | -------- | -------- | -------- |
930  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
931  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN connection state.|
932
933- Enumerates the WLAN connection states.
934  | **Value**| **Description**|
935  | -------- | -------- |
936  | 0 | Disconnected.|
937  | 1 | Connected.|
938
939
940## wifi.off('wifiConnectionChange')<sup>7+</sup>
941
942off(type: "wifiConnectionChange", callback?: Callback&lt;number&gt;): void
943
944Unregisters the WLAN connection state change events.
945
946- **Required permissions**:
947  ohos.permission.GET_WIFI_INFO
948
949- **System capability**:
950  SystemCapability.Communication.WiFi.STA
951
952- **Parameters**
953  | **Name**| **Type**| **Mandatory**| **Description**|
954  | -------- | -------- | -------- | -------- |
955  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
956  | callback | Callback&lt;number&gt; | No| Callback used to return the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
957
958
959## wifi.on('wifiScanStateChange')<sup>7+</sup>
960
961on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
962
963Registers the WLAN scan state change events.
964
965- **Required permissions**:
966  ohos.permission.GET_WIFI_INFO
967
968- **System capability**:
969  SystemCapability.Communication.WiFi.STA
970
971- **Parameters**
972  | **Name**| **Type**| **Mandatory**| **Description**|
973  | -------- | -------- | -------- | -------- |
974  | type | string | Yes| Event type. The value is **wifiScanStateChange**.|
975  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN scan state.|
976
977- Enumerates the WLAN scan states.
978  | **Value**| **Description**|
979  | -------- | -------- |
980  | 0 | Scan failed.|
981  | 1 | Scan successful.|
982
983
984## wifi.off('wifiScanStateChange')<sup>7+</sup>
985
986off(type: "wifiScanStateChange", callback?: Callback&lt;number&gt;): void
987
988Unregisters the WLAN scan state change events.
989
990- **Required permissions**:
991  ohos.permission.GET_WIFI_INFO
992
993- **System capability**:
994  SystemCapability.Communication.WiFi.STA
995
996- **Parameters**
997
998| **Name**| **Type**| **Mandatory**| **Description**|
999| -------- | -------- | -------- | -------- |
1000| type | string | Yes| Event type. The value is **wifiScanStateChange**.|
1001| callback | Callback&lt;number&gt; | No| Callback used to return the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1002
1003
1004## wifi.on('wifiRssiChange')<sup>7+</sup>
1005
1006on(type: "wifiRssiChange", callback: Callback&lt;number&gt;): void
1007
1008Registers the RSSI change events.
1009
1010- **Required permissions**:
1011  ohos.permission.GET_WIFI_INFO
1012
1013- **System capability**:
1014  SystemCapability.Communication.WiFi.STA
1015
1016- **Parameters**
1017  | **Name**| **Type**| **Mandatory**| **Description**|
1018  | -------- | -------- | -------- | -------- |
1019  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
1020  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the RSSI, in dBm.|
1021
1022
1023## wifi.off('wifiRssiChange')<sup>7+</sup>
1024
1025off(type: "wifiRssiChange", callback?: Callback&lt;number&gt;): void
1026
1027Unregisters the RSSI change events.
1028
1029- **Required permissions**:
1030  ohos.permission.GET_WIFI_INFO
1031
1032- **System capability**:
1033  SystemCapability.Communication.WiFi.STA
1034
1035- **Parameters**
1036  | **Name**| **Type**| **Mandatory**| **Description**|
1037  | -------- | -------- | -------- | -------- |
1038  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
1039  | callback | Callback&lt;number&gt; | No| Callback used to return the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1040
1041
1042## wifi.on('hotspotStateChange')<sup>7+</sup>
1043
1044on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
1045
1046Registers the hotspot state change events.
1047
1048- **Required permissions**:
1049  ohos.permission.GET_WIFI_INFO
1050
1051- **System capability**:
1052  SystemCapability.Communication.WiFi.AP.Core
1053
1054- **Parameters**
1055  | **Name**| **Type**| **Mandatory**| **Description**|
1056  | -------- | -------- | -------- | -------- |
1057  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
1058  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the hotspot state.|
1059
1060- Enumerates the hotspot states.
1061  | **Value**| **Description**|
1062  | -------- | -------- |
1063  | 0 | Deactivated|
1064  | 1 | Activated|
1065  | 2 | Activating|
1066  | 3 | Deactivating|
1067
1068
1069## wifi.off('hotspotStateChange')<sup>7+</sup>
1070
1071off(type: "hotspotStateChange", callback?: Callback&lt;number&gt;): void
1072
1073Unregisters the hotspot state change events.
1074
1075- **Required permissions**:
1076  ohos.permission.GET_WIFI_INFO
1077
1078- **System capability**:
1079  SystemCapability.Communication.WiFi.AP.Core
1080
1081- **Parameters**
1082  | **Name**| **Type**| **Mandatory**| **Description**|
1083  | -------- | -------- | -------- | -------- |
1084  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
1085  | callback | Callback&lt;number&gt; | No| Callback used to return the hotspot state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1086
1087
1088## wifi.on('p2pStateChange')<sup>8+</sup>
1089
1090on(type: "p2pStateChange", callback: Callback&lt;number&gt;): void
1091
1092Registers the P2P state change events.
1093
1094- **Required permissions**:
1095  ohos.permission.GET_WIFI_INFO
1096
1097- **System capability**:
1098  SystemCapability.Communication.WiFi.P2P
1099
1100- **Parameters**
1101  | **Name**| **Type**| **Mandatory**| **Description**|
1102  | -------- | -------- | -------- | -------- |
1103  | type | string | Yes| Event type. The value is **p2pStateChange**.|
1104  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P state.|
1105
1106- Enumerates the P2P states.
1107  | **Value**| **Description**|
1108  | -------- | -------- |
1109  | 1 | Available|
1110  | 2 | Opening|
1111  | 3 | Opened|
1112  | 4 | Closing|
1113  | 5 | Closed|
1114
1115## wifi.off('p2pStateChange')<sup>8+</sup>
1116
1117off(type: "p2pStateChange", callback?: Callback&lt;number&gt;): void
1118
1119Unregisters the P2P state change events.
1120
1121- **Required permissions**:
1122  ohos.permission.GET_WIFI_INFO
1123
1124- **System capability**:
1125  SystemCapability.Communication.WiFi.P2P
1126
1127- **Parameters**
1128  | **Name**| **Type**| **Mandatory**| **Description**|
1129  | -------- | -------- | -------- | -------- |
1130  | type | string | Yes| Event type. The value is **p2pStateChange**.|
1131  | callback | Callback&lt;number&gt; | No| Callback used to return the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1132
1133
1134  ## wifi.on('p2pConnectionChange')<sup>8+</sup>
1135
1136on(type: "p2pConnectionChange", callback: Callback&lt;WifiP2pLinkedInfo&gt;): void
1137
1138Registers the P2P connection state change events.
1139
1140- **Required permissions**:
1141  ohos.permission.GET_WIFI_INFO
1142
1143- **System capability**:
1144  SystemCapability.Communication.WiFi.P2P
1145
1146- **Parameters**
1147  | **Name**| **Type**| **Mandatory**| **Description**|
1148  | -------- | -------- | -------- | -------- |
1149  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
1150  | callback | Callback&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Yes| Callback invoked to return the P2P connection state.|
1151
1152
1153## wifi.off('p2pConnectionChange')<sup>8+</sup>
1154
1155off(type: "p2pConnectionChange", callback?: Callback&lt;WifiP2pLinkedInfo&gt;): void
1156
1157Unregisters the P2P connection state change events.
1158
1159- **Required permissions**:
1160  ohos.permission.GET_WIFI_INFO
1161
1162- **System capability**:
1163  SystemCapability.Communication.WiFi.P2P
1164
1165- **Parameters**
1166  | **Name**| **Type**| **Mandatory**| **Description**|
1167  | -------- | -------- | -------- | -------- |
1168  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
1169  | callback | Callback&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | No| Callback used to return the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1170
1171
1172## wifi.on('p2pDeviceChange')<sup>8+</sup>
1173
1174on(type: "p2pDeviceChange", callback: Callback&lt;WifiP2pDevice&gt;): void
1175
1176Registers the P2P device state change events.
1177
1178- **Required permissions**:
1179  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
1180
1181- **System capability**:
1182  SystemCapability.Communication.WiFi.P2P
1183
1184- **Parameters**
1185  | **Name**| **Type**| **Mandatory**| **Description**|
1186  | -------- | -------- | -------- | -------- |
1187  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
1188  | callback | Callback&lt;[WifiP2pDevice](#WifiP2pDevice)&gt; | Yes| Callback invoked to return the P2P device state.|
1189
1190
1191## wifi.off('p2pDeviceChange')<sup>8+</sup>
1192
1193off(type: "p2pDeviceChange", callback?: Callback&lt;WifiP2pDevice&gt;): void
1194
1195Unregisters the P2P device state change events.
1196
1197- **Required permissions**:
1198  ohos.permission.LOCATION
1199
1200- **System capability**:
1201  SystemCapability.Communication.WiFi.P2P
1202
1203- **Parameters**
1204  | **Name**| **Type**| **Mandatory**| **Description**|
1205  | -------- | -------- | -------- | -------- |
1206  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
1207  | callback | Callback&lt;[WifiP2pDevice](#WifiP2pDevice)&gt; | No| Callback used to return the P2P peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1208
1209
1210## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>
1211
1212on(type: "p2pPeerDeviceChange", callback: Callback&lt;WifiP2pDevice[]&gt;): void
1213
1214Registers the P2P peer device state change events.
1215
1216- **Required permissions**:
1217  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
1218
1219- **System capability**:
1220  SystemCapability.Communication.WiFi.P2P
1221
1222- **Parameters**
1223  | **Name**| **Type**| **Mandatory**| **Description**|
1224  | -------- | -------- | -------- | -------- |
1225  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
1226  | callback | Callback&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Yes| Callback invoked to return the peer device state.|
1227
1228
1229## wifi.off('p2pPeerDeviceChange')<sup>8+</sup>
1230
1231off(type: "p2pPeerDeviceChange", callback?: Callback&lt;WifiP2pDevice[]&gt;): void
1232
1233Unregisters the P2P peer device state change events.
1234
1235- **Required permissions**:
1236  ohos.permission.LOCATION
1237
1238- **System capability**:
1239  SystemCapability.Communication.WiFi.P2P
1240
1241- **Parameters**
1242  | **Name**| **Type**| **Mandatory**| **Description**|
1243  | -------- | -------- | -------- | -------- |
1244  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
1245  | callback | Callback&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | No| Callback used to return the P2P peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1246
1247
1248## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>
1249
1250on(type: "p2pPersistentGroupChange", callback: Callback&lt;void&gt;): void
1251
1252Registers the P2P persistent group state change events.
1253
1254- **Required permissions**:
1255  ohos.permission.GET_WIFI_INFO
1256
1257- **System capability**:
1258  SystemCapability.Communication.WiFi.P2P
1259
1260- **Parameters**
1261  | **Name**| **Type**| **Mandatory**| **Description**|
1262  | -------- | -------- | -------- | -------- |
1263  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
1264  | callback | Callback&lt;void&gt; | Yes| Callback invoked to return the P2P persistent group state.|
1265
1266
1267## wifi.off('p2pPersistentGroupChange')<sup>8+</sup>
1268
1269off(type: "p2pPersistentGroupChange", callback?: Callback&lt;void&gt;): void
1270
1271Unregisters the P2P persistent group state change events.
1272
1273- **Required permissions**:
1274  ohos.permission.GET_WIFI_INFO
1275
1276- **System capability**:
1277  SystemCapability.Communication.WiFi.P2P
1278
1279- **Parameters**
1280  | **Name**| **Type**| **Mandatory**| **Description**|
1281  | -------- | -------- | -------- | -------- |
1282  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
1283  | callback | Callback&lt;void&gt; | No| Callback used to return the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1284
1285
1286## wifi.on('p2pDiscoveryChange')<sup>8+</sup>
1287
1288on(type: "p2pDiscoveryChange", callback: Callback&lt;number&gt;): void
1289
1290Registers the P2P device discovery state change events.
1291
1292- **Required permissions**:
1293  ohos.permission.GET_WIFI_INFO
1294
1295- **System capability**:
1296  SystemCapability.Communication.WiFi.P2P
1297
1298- **Parameters**
1299  | **Name**| **Type**| **Mandatory**| **Description**|
1300  | -------- | -------- | -------- | -------- |
1301  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
1302  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P device discovery state.|
1303
1304- Enumerates the P2P device discovery states.
1305  | **Value**| **Description**|
1306  | -------- | -------- |
1307  | 0 | Initial state|
1308  | 1 | Discovered|
1309
1310
1311## wifi.off('p2pDiscoveryChange')<sup>8+</sup>
1312
1313off(type: "p2pDiscoveryChange", callback?: Callback&lt;number&gt;): void
1314
1315Unregisters the P2P device discovery state change events.
1316
1317- **Required permissions**:
1318  ohos.permission.GET_WIFI_INFO
1319
1320- **System capability**:
1321  SystemCapability.Communication.WiFi.P2P
1322
1323- **Parameters**
1324  | **Name**| **Type**| **Mandatory**| **Description**|
1325  | -------- | -------- | -------- | -------- |
1326  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
1327  | callback | Callback&lt;number&gt; | No| Callback used to return the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
1328