js-apis-wifi.md 41.2 KB
Newer Older
A
annie_wangli 已提交
1
# WLAN
W
wusongqing 已提交
2

A
annie_wangli 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> 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.
W
wusongqing 已提交
5 6


A
annie_wangli 已提交
7 8 9
## Modules to Import

```js
Z
zengyawen 已提交
10
import wifi from '@ohos.wifi';
W
wusongqing 已提交
11 12
```

A
annie_wangli 已提交
13
## wifi.isWifiActive
W
wusongqing 已提交
14

A
annie_wangli 已提交
15
isWifiActive(): boolean
W
wusongqing 已提交
16

Z
zengyawen 已提交
17
Checks whether the WLAN is activated.
W
wusongqing 已提交
18

A
annie_wangli 已提交
19 20 21 22 23
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA
W
wusongqing 已提交
24

A
annie_wangli 已提交
25 26 27 28
- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the WLAN is activated; returns **false** otherwise.|
W
wusongqing 已提交
29 30


A
annie_wangli 已提交
31
## wifi.scan
Z
zengyawen 已提交
32

A
annie_wangli 已提交
33
scan(): boolean
Z
zengyawen 已提交
34 35 36

Starts a scan for WLAN.

A
annie_wangli 已提交
37 38
- Required permissions:
  ohos.permission.SET_WIFI_INFO and ohos.permission.LOCATION
Z
zengyawen 已提交
39

A
annie_wangli 已提交
40 41
- System capability:
  SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
42

A
annie_wangli 已提交
43 44 45 46
- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the scan is successful; returns **false** otherwise.|
Z
zengyawen 已提交
47 48


A
annie_wangli 已提交
49 50 51
## wifi.getScanInfos

getScanInfos(): Promise&lt;Array&lt;WifiScanInfo&gt;&gt;
Z
zengyawen 已提交
52 53 54

Obtains the scan result. This method uses a promise to return the result.

A
annie_wangli 已提交
55 56 57 58 59
- Required permissions:
  ohos.permission.GET_WIFI_INFO, ohos.permission.GET_WIFI_PEERS_MAC, or ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
60

A
annie_wangli 已提交
61 62 63 64
- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the scan result, which is a list of hotspots detected.|
Z
zengyawen 已提交
65 66


A
annie_wangli 已提交
67
## wifi.getScanInfos
Z
zengyawen 已提交
68

A
annie_wangli 已提交
69
getScanInfos(callback: AsyncCallback&lt;Array&lt;WifiScanInfo&gt;&gt;): void
Z
zengyawen 已提交
70 71 72

Obtains the scan result. This method uses an asynchronous callback to return the result.

A
annie_wangli 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
- Required permissions:
  ohos.permission.GET_WIFI_INFO, ohos.permission.GET_WIFI_PEERS_MAC, or ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&gt; | Yes| Callback invoked to return the result, which is a list of hotspots detected.|

- Example
  ```js
  import wifi from '@ohos.wifi';
  
  wifi.getScanInfos((err, result) => {
      if (err) {
          console.error("get scan info error");
          return;
      }
  
      var len = Object.keys(result).length;
      console.log("wifi received scan info: " + len);
      for (var i = 0; i < len; ++i) {
          console.info("ssid: " + result[i].ssid);
          console.info("bssid: " + result[i].bssid);
          console.info("capabilities: " + result[i].capabilities);
          console.info("securityType: " + result[i].securityType);
          console.info("rssi: " + result[i].rssi);
          console.info("band: " + result[i].band);
          console.info("frequency: " + result[i].frequency);
          console.info("channelWidth: " + result[i].channelWidth);
          console.info("timestamp: " + result[i].timestamp);
      }
  });
  
  wifi.getScanInfos().then(result => {
      var len = Object.keys(result).length;
      console.log("wifi received scan info: " + len);
      for (var i = 0; i < len; ++i) {
          console.info("ssid: " + result[i].ssid);
          console.info("bssid: " + result[i].bssid);
          console.info("capabilities: " + result[i].capabilities);
          console.info("securityType: " + result[i].securityType);
          console.info("rssi: " + result[i].rssi);
          console.info("band: " + result[i].band);
          console.info("frequency: " + result[i].frequency);
          console.info("channelWidth: " + result[i].channelWidth);
          console.info("timestamp: " + result[i].timestamp);
      }
  });
  ```


## WifiScanInfo

Represents WLAN hotspot information.

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| ssid | string | Read only| Hotspot service set identifier (SSID), in UTF-8 format.|
| bssid | string | Read only| Basic service set identifier (BSSID) of the hotspot.|
| capabilities | string | Read only| Hotspot capabilities.|
| securityType | [WifiSecurityType](#WifiSecurityType) | Read only| WLAN security type.|
| rssi | number | Read only| Signal strength of the hotspot, in dBm.|
| band | number | Read only| Frequency band of the WLAN access point (AP).|
| frequency | number | Read only| Frequency of the WLAN AP.|
| channelWidth | number | Read only| Bandwidth of the WLAN AP.|
| timestamp | number | Read only| Timestamp.|
W
wusongqing 已提交
142 143


A
annie_wangli 已提交
144
## WifiSecurityType
W
wusongqing 已提交
145

A
annie_wangli 已提交
146
Enumerates the WLAN security types.
W
wusongqing 已提交
147

A
annie_wangli 已提交
148 149
| **Name**| **Default Value**| **Description**|
| -------- | -------- | -------- |
A
annie_wangli 已提交
150 151 152 153 154
| WIFI_SEC_TYPE_INVALID | 0 | Invalid security type|
| WIFI_SEC_TYPE_OPEN | 1 | Open security type|
| WIFI_SEC_TYPE_WEP | 2 | Wired Equivalent Privacy (WEP)|
| WIFI_SEC_TYPE_PSK | 3 | Pre-shared key (PSK)|
| WIFI_SEC_TYPE_SAE | 4 | Simultaneous Authentication of Equals (SAE)|
W
wusongqing 已提交
155 156


A
annie_wangli 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
## wifi.addUntrustedConfig<sup>7+</sup>

addUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;

Adds untrusted WLAN configuration. This method uses a promise to return the result.

- Required permissions:
  ohos.permission.SET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to add.|

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return the operation result. The value **true** indicates that the operation is successful; **false** indicates the opposite.|

## WifiDeviceConfig

Represents the WLAN configuration.

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
A
annie_wangli 已提交
185
| ssid | string | Read only| Hotspot service set identifier (SSID), in UTF-8 format.|
A
annie_wangli 已提交
186 187 188
| bssid | string | Read only| BSSID of the hotspot.|
| preSharedKey | string | Read only| Private key of the hotspot.|
| isHiddenSsid | boolean | Read only| Whether to hide the network.|
A
annie_wangli 已提交
189
| securityType | [WifiSecurityType](#WifiSecurityType) | Read only| Security type|
A
annie_wangli 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241


## wifi.addUntrustedConfig<sup>7+</sup>

addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void

Adds untrusted WLAN configuration. This method uses an asynchronous callback to return the result.

- Required permissions:
  ohos.permission.SET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to add.|
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the operation result. The value **true** indicates that the operation is successful; **false** indicates the opposite.|


## wifi.removeUntrustedConfig<sup>7+</sup>

removeUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;

Removes untrusted WLAN configuration. This method uses a promise to return the result.

- Required permissions:
  ohos.permission.SET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to remove.|

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return the operation result. The value **true** indicates that the operation is successful; **false** indicates the opposite.|


## wifi.removeUntrustedConfig<sup>7+</sup>

removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void

Removes untrusted WLAN configuration. This method uses an asynchronous callback to return the result.

- Required permissions:
  ohos.permission.SET_WIFI_INFO
W
wusongqing 已提交
242

A
annie_wangli 已提交
243 244
- System capability:
  SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
245

A
annie_wangli 已提交
246 247 248 249 250
- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#WifiDeviceConfig) | Yes| WLAN configuration to remove.|
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the operation result. The value **true** indicates that the operation is successful; **false** indicates the opposite.|
Z
zengyawen 已提交
251 252


A
annie_wangli 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
## wifi.getSignalLevel

getSignalLevel(rssi: number, band: number): number

Obtains the WLAN signal strength.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- **Parameters**
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | rssi | number | Yes| Signal strength of the hotspot, in dBm.|
  | band | number | Yes| Frequency band of the WLAN AP.|

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | number | Signal strength obtained. The value range is [0,&nbsp;4].|


## wifi.getLinkedInfo

getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
Z
zengyawen 已提交
280 281 282

Obtains WLAN connection information. This method uses a promise to return the result.

A
annie_wangli 已提交
283 284 285 286 287
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
288

A
annie_wangli 已提交
289 290 291 292
- Return value
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiLinkedInfo](#WifiLinkedInfo)&gt; | Promise used to return the WLAN connection information obtained.|
Z
zengyawen 已提交
293 294


A
annie_wangli 已提交
295
## wifi.getLinkedInfo
Z
zengyawen 已提交
296

A
annie_wangli 已提交
297
getLinkedInfo(callback: AsyncCallback&lt;WifiLinkedInfo&gt;): void
Z
zengyawen 已提交
298 299 300

Obtains WLAN connection information. This method uses a callback to return the result.

A
annie_wangli 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiLinkedInfo](#WifiLinkedInfo)&gt; | Yes| Callback invoked to return the WLAN connection information obtained.|

- Example
  ```js
  import wifi from '@ohos.wifi';
  
  wifi.getLinkedInfo((err, data) => {
      if (err) {
          console.error("get linked info error");
          return;
      }
      console.info("get wifi linked info: " + JSON.stringify(data));
  });
  
  wifi.getLinkedInfo().then(data => {
      console.info("get wifi linked info: " + JSON.stringify(data));
  }).catch(error => {
      console.info("get linked info error");
  });
  ```


## WifiLinkedInfo

Represents the WLAN connection information.

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
A
annie_wangli 已提交
338
| ssid | string | Read only| Hotspot SSID, in UTF-8 format.|
A
annie_wangli 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351
| bssid | string | Read only| BSSID of the hotspot.|
| rssi | number | Read only| Signal strength of the hotspot, in dBm.|
| band | number | Read only| Frequency band of the WLAN AP.|
| linkSpeed | number | Read only| Speed of the WLAN AP.|
| frequency | number | Read only| Frequency of the WLAN AP.|
| isHidden | boolean | Read only| Whether the WLAN AP is hidden.|
| isRestricted | boolean | Read only| Whether data volume is restricted at the WLAN AP.|
| macAddress | string | Read only| MAC address of the device.|
| ipAddress | number | Read only| IP address of the device that sets up the WLAN connection.|
| connState | [ConnState](#ConnState) | Read only| WLAN connection state.|


## ConnState
Z
zengyawen 已提交
352 353 354

Enumerates the WLAN connection states.

A
annie_wangli 已提交
355 356 357 358 359 360 361 362 363 364
| Name| Default Value| Description|
| -------- | -------- | -------- |
| SCANNING | 0 | The device is scanning for available APs.|
| CONNECTING | 1 | A WLAN connection is being established.|
| AUTHENTICATING | 2 | An authentication is being performed for a WLAN connection.|
| OBTAINING_IPADDR | 3 | The IP address of the WLAN connection is being acquired.|
| CONNECTED | 4 | A WLAN connection is established.|
| DISCONNECTING | 5 | The WLAN connection is being disconnected.|
| DISCONNECTED | 6 | The WLAN connection is disconnected.|
| UNKNOWN | 7 | Failed to set up a WLAN connection.|
Z
zengyawen 已提交
365 366


A
annie_wangli 已提交
367
## wifi.isConnected<sup>7+</sup>
Z
zengyawen 已提交
368

A
annie_wangli 已提交
369 370 371
isConnected(): boolean

Checks whether the WLAN is connected.
Z
zengyawen 已提交
372

A
annie_wangli 已提交
373 374
- Required permissions:
  ohos.permission.GET_WIFI_INFO
Z
zengyawen 已提交
375

A
annie_wangli 已提交
376 377
- System capability:
  SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
378

A
annie_wangli 已提交
379 380 381 382 383 384 385 386 387
- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|


## wifi.isFeatureSupported<sup>7+</sup>

isFeatureSupported(featureId: number): boolean
Z
zengyawen 已提交
388 389 390

Checks whether the device supports the specified WLAN feature.

A
annie_wangli 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.Core

- **Parameters**
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | featureId | number | Yes| Feature ID.|

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|

- Enumerates the WLAN features.
  | Value| Description|
  | -------- | -------- |
  | 0x0001 | WLAN infrastructure mode|
  | 0x0002 | 5 GHz bandwidth|
  | 0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature|
  | 0x0008 | Wi-Fi Direct|
  | 0x0010 | SoftAP|
  | 0x0040 | Wi-Fi AWare|
  | 0x8000 | WLAN AP/STA concurrency|
  | 0x8000000 | WPA3 Personal (WPA-3 SAE)|
  | 0x10000000 | WPA3-Enterprise&nbsp;Suite-B |
  | 0x20000000 | Enhanced open feature|


## wifi.getIpInfo<sup>7+</sup>

getIpInfo(): IpInfo

Obtains IP information.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | [IpInfo](#IpInfo) | IP information obtained.|


## IpInfo<sup>7+</sup>

Represents IP information.

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
A
annie_wangli 已提交
446 447 448 449 450 451 452
| ipAddress | number | Read only| IP address|
| gateway | number | Read only| Gateway|
| netmask | number | Read only| Subnet mask|
| primaryDns | number | Read only| IP address of the preferred DNS server|
| secondDns | number | Read only| IP address of the alternate DNS server|
| serverIp | number | Read only| IP address of the DHCP server|
| leaseDuration | number | Read only| Lease duration of the IP address|
A
annie_wangli 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591


## wifi.getCountryCode<sup>7+</sup>

getCountryCode(): string

Obtains the country code.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.Core

- Return value
  | **Type**| **Description**|
  | -------- | -------- |
  | string | Country code obtained.|


## wifi.getP2pLinkedInfo<sup>8+</sup>

getP2pLinkedInfo(): Promise&lt;WifiP2pLinkedInfo&gt;

Obtains peer-to-peer (P2P) connection information. This method uses a promise to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Promise used to return the P2P connection information obtained.|


## wifi.getP2pLinkedInfo<sup>8+</sup>

getP2pLinkedInfo(callback: AsyncCallback&lt;WifiP2pLinkedInfo&gt;): void

Obtains P2P connection information. This method uses a callback to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Yes| Callback used to return the P2P connection information obtained.|


## WifiP2pLinkedInfo<sup>8+</sup>

Represents the WLAN connection information.

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| connectState | [P2pConnectState](#P2pConnectState) | Read only| P2P connection state.|
| isGroupOwner | boolean | Read only| Whether it is a group.|
| groupOwnerAddr | string | Read only| MAC address of the group.|


## P2pConnectState<sup>8+</sup>

Enumerates the P2P connection states.

| Name| Default Value| Description|
| -------- | -------- | -------- |
| DISCONNECTED | 0 | Disconnected|
| CONNECTED | 1 | Connected|


## wifi.getCurrentGroup<sup>8+</sup>

getCurrentGroup(): Promise&lt;WifiP2pGroupInfo&gt;

Obtains the current P2P group information. This method uses a promise to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pGroupInfo](#WifiP2pGroupInfo)&gt; | Promise used to return the P2P group information obtained.|


## wifi.getCurrentGroup<sup>8+</sup>

getCurrentGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void

Obtains the P2P group information. This method uses an asynchronous callback to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pGroupInfo](#WifiP2pGroupInfo)&gt; | Yes| Callback used to return the P2P group information obtained.|


## WifiP2pGroupInfo<sup>8+</sup>

Represents the P2P group information.

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| isP2pGo | boolean | Read only| Whether it is a group.|
| ownerInfo | [WifiP2pDevice](#WifiP2pDevice) | Read only| Device information of the group.|
| passphrase | string | Read only| Private key of the group.|
| interface | string | Read only| Interface name.|
| groupName | string | Read only| Group name.|
| networkId | number | Read only| Network ID.|
| frequency | number | Read only| Frequency of the group.|
| clientDevices | [WifiP2pDevice[]](#WifiP2pDevice) | Read only| List of connected devices.|
| goIpAddress | string | Read only| IP address of the group.|

## WifiP2pDevice<sup>8+</sup>

Represents the P2P device information.

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| deviceName | string | Read only| Device name.|
| deviceAddress | string | Read only| MAC address of the device.|
| primaryDeviceType | string | Read only| Type of the primary device.|
| deviceStatus | [P2pDeviceStatus](#P2pDeviceStatus) | Read only| Device status.|
A
Annie_wang 已提交
592
| groupCapabilitys | number | Read only| Group capabilities.|
A
annie_wangli 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852

## P2pDeviceStatus<sup>8+</sup>

Enumerates the device states.

| Name| Default Value| Description|
| -------- | -------- | -------- |
| CONNECTED | 0 | Connected|
| INVITED | 1 | Invited|
| FAILED | 2 | Failed|
| AVAILABLE | 3 | Available|
| UNAVAILABLE | 4 | Unavailable|


## wifi.getP2pPeerDevices<sup>8+</sup>

getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;

Obtains the list of peer devices in a P2P connection. This method uses a promise to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Promise used to return the peer device list obtained.|


## wifi.getP2pPeerDevices<sup>8+</sup>

getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void

Obtains the list of peer devices in a P2P connection. This method uses an asynchronous callback to return the result.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Yes| Callback used to return the peer device list obtained.|


## wifi.createGroup<sup>8+</sup>

createGroup(config: WifiP2PConfig): boolean;

Creates a P2P group.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- **Parameters**
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#WifiP2PConfig) | Yes| Group configuration.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

## WifiP2PConfig<sup>8+</sup>

Represents P2P configuration.

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| deviceAddress | string | Read only| Device address.|
| netId | number | Read only| Network ID. The value **-1** indicates that a temporary group, and **-2** indicates that a persistent group.|
| passphrase | string | Read only| Private key of the group.|
| groupName | string | Read only| Name of the group.|
| goBand | [GroupOwnerBand](#GroupOwnerBand) | Read only| Bandwidth of the group.|


## GroupOwnerBand<sup>8+</sup>

Enumerates the P2P group bandwidths.

| Name| Default Value| Description|
| -------- | -------- | -------- |
| GO_BAND_AUTO | 0 | Auto|
| GO_BAND_2GHZ | 1 | 2 GHz|
| GO_BAND_5GHZ | 2 | 5 GHz|

## wifi.removeGroup<sup>8+</sup>

removeGroup(): boolean;

Removes a P2P group.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## wifi.p2pConnect<sup>8+</sup>

p2pConnect(config: WifiP2PConfig): boolean;

Sets up a P2P connection.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- **Parameters**
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#WifiP2PConfig) | Yes| Connection configuration.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


- Example
  ```js
  import wifi from '@ohos.wifi';
  
  var recvP2pConnectionChangeFunc = result => {
      console.info("p2p connection change receive event: " + JSON.stringify(result));
      wifi.getP2pLinkedInfo((err, data) => {
          if (err) {
              console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err));
              return;
          }
          console.info("get getP2pLinkedInfo: " + JSON.stringify(data));
      });
  }
  wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
  
  var recvP2pDeviceChangeFunc = result => {
      console.info("p2p device change receive event: " + JSON.stringify(result));
  }
  wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
  
  var recvP2pPeerDeviceChangeFunc = result => {
      console.info("p2p peer device change receive event: " + JSON.stringify(result));
      wifi.getP2pPeerDevices((err, data) => {
          if (err) {
              console.error('failed to get peer devices: ' + JSON.stringify(err));
              return;
          }
          console.info("get peer devices: " + JSON.stringify(data));
          var len = Object.keys(data).length;
          for (var i = 0; i < len; ++i) {
              if (data[i].deviceName === "my_test_device") {
                  console.info("p2p connect to test device: " + data[i].deviceAddress);
                  var config = {
                      "deviceAddress":data[i].deviceAddress,
                      "netId":-2,
                      "passphrase":"",
                      "groupName":"",
                      "goBand":0,
                  }
                  wifi.p2pConnect(config);
              }
          }
      });
  }
  wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
  
  var recvP2pPersistentGroupChangeFunc = result => {
      console.info("p2p persistent group change receive event");
  
      wifi.getCurrentGroup((err, data) => {
          if (err) {
              console.error('failed to get current group: ' + JSON.stringify(err));
              return;
          }
          console.info("get current group: " + JSON.stringify(data));
      });
  }
  wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
  
  setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000);
  setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
  setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
  setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
  console.info("start discover devices -> " + wifi.startDiscoverDevices());
  ```

## wifi.p2pCancelConnect<sup>8+</sup>

p2pCancelConnect(): boolean;

Cancels this P2P connection.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## wifi.startDiscoverDevices<sup>8+</sup>

startDiscoverDevices(): boolean;

Starts to discover devices.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## wifi.stopDiscoverDevices<sup>8+</sup>

stopDiscoverDevices(): boolean;

Stops discovering devices.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## wifi.on('wifiStateChange')<sup>7+</sup>

on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
853 854 855

Registers the WLAN state change events.

A
annie_wangli 已提交
856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiStateChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN state.|

- Enumerates the WLAN states.
  | **Value**| **Description**|
  | -------- | -------- |
  | 0 | Deactivated|
  | 1 | Activated|
  | 2 | Activating|
  | 3 | Deactivating|


## wifi.off('wifiStateChange')<sup>7+</sup>

off(type: "wifiStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
880 881 882

Unregisters the WLAN state change events.

A
annie_wangli 已提交
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiStateChange**.|
  | 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.|

- Example
  ```js
  import wifi from '@ohos.wifi';
  
  var WIFI_POWER_STATE = "wifiStateChange";
  var recvPowerNotifyFunc = result => {
      console.info("Receive power state change event: " + result);
  }
  
  // Register event
  wifi.on(WIFI_POWER_STATE, recvPowerNotifyFunc);
  
  // Unregister event
  wifi.off(WIFI_POWER_STATE, recvPowerNotifyFunc);
  ```


## wifi.on('wifiConnectionChange')<sup>7+</sup>

on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
915 916 917

Registers the WLAN connection state change events.

A
annie_wangli 已提交
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN connection state.|

- Enumerates the WLAN connection states.
  | **Value**| **Description**|
  | -------- | -------- |
  | 0 | Disconnected|
  | 1 | Connected|


## wifi.off('wifiConnectionChange')<sup>7+</sup>

off(type: "wifiConnectionChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
940 941 942

Unregisters the WLAN connection state change events.

A
annie_wangli 已提交
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to report the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|


## wifi.on('wifiScanStateChange')<sup>7+</sup>

on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
959 960 961

Registers the WLAN scan state change events.

A
annie_wangli 已提交
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiScanStateChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN scan state.|

- Enumerates the WLAN scan states.
  | **Value**| **Description**|
  | -------- | -------- |
  | 0 | Scan failed|
  | 1 | Scan successful|


## wifi.off('wifiScanStateChange')<sup>7+</sup>

off(type: "wifiScanStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
984 985 986

Unregisters the WLAN scan state change events.

A
annie_wangli 已提交
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters

| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiScanStateChange**.|
| 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.|


## wifi.on('wifiRssiChange')<sup>7+</sup>

on(type: "wifiRssiChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1004 1005 1006

Registers the RSSI state change events.

A
annie_wangli 已提交
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the RSSI, in dBm.|


## wifi.off('wifiRssiChange')<sup>7+</sup>

off(type: "wifiRssiChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1023 1024 1025

Unregisters the RSSI state change events.

A
annie_wangli 已提交
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.STA

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the RSSI, in dBm. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|


## wifi.on('hotspotStateChange')<sup>7+</sup>

on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1042 1043 1044

Registers the hotspot state change events.

A
annie_wangli 已提交
1045 1046 1047 1048
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
A
annie_wangli 已提交
1049
  SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the hotspot state.|

- Enumerates the hotspot states.
  | **Value**| **Description**|
  | -------- | -------- |
  | 0 | Deactivated|
  | 1 | Activated|
  | 2 | Activating|
  | 3 | Deactivating|


## wifi.off('hotspotStateChange')<sup>7+</sup>

off(type: "hotspotStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1069 1070 1071

Unregisters the hotspot state change events.

A
annie_wangli 已提交
1072 1073 1074 1075
- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
A
annie_wangli 已提交
1076
  SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
  | 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.|


## wifi.on('p2pStateChange')<sup>8+</sup>

on(type: "p2pStateChange", callback: Callback&lt;number&gt;): void

Registers the P2P status change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pStateChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P state.|

- Enumerates the P2P states.
  | **Value**| **Description**|
  | -------- | -------- |
  | 1 | Available|
  | 2 | Opening|
  | 3 | Opened|
  | 4 | Closing|
  | 5 | Closed|

## wifi.off('p2pStateChange')<sup>8+</sup>

off(type: "p2pStateChange", callback?: Callback&lt;number&gt;): void

Unregisters the P2P state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pStateChange**.|
  | 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.|


  ## wifi.on('p2pConnectionChange')<sup>8+</sup>

on(type: "p2pConnectionChange", callback: Callback&lt;WifiP2pLinkedInfo&gt;): void

Registers the P2P connection state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
  | callback | Callback&lt;[WifiP2pLinkedInfo](#WifiP2pLinkedInfo)&gt; | Yes| Callback invoked to return the P2P connection state.|


## wifi.off('p2pConnectionChange')<sup>8+</sup>

off(type: "p2pConnectionChange", callback?: Callback&lt;WifiP2pLinkedInfo&gt;): void

Unregisters the P2P connection state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
  | 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.|


## wifi.on('p2pDeviceChange')<sup>8+</sup>

on(type: "p2pDeviceChange", callback: Callback&lt;WifiP2pDevice&gt;): void

Registers the P2P device state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice](#WifiP2pDevice)&gt; | Yes| Callback invoked to return the P2P device state.|


## wifi.off('p2pDeviceChange')<sup>8+</sup>

off(type: "p2pDeviceChange", callback?: Callback&lt;WifiP2pDevice&gt;): void

Unregisters the P2P device state change events.

- Required permissions:
  ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice](#WifiP2pDevice)&gt; | No| Callback used to return the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|


## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>

on(type: "p2pPeerDeviceChange", callback: Callback&lt;WifiP2pDevice[]&gt;): void

Registers the P2P peer device state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice[]](#WifiP2pDevice)&gt; | Yes| Callback invoked to return the P2P peer device state.|


## wifi.off('p2pPeerDeviceChange')<sup>8+</sup>

off(type: "p2pPeerDeviceChange", callback?: Callback&lt;WifiP2pDevice[]&gt;): void

Unregisters the P2P peer device state change events.

- Required permissions:
  ohos.permission.LOCATION

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
A
annie_wangli 已提交
1242
  | 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.|
A
annie_wangli 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315


## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>

on(type: "p2pPersistentGroupChange", callback: Callback&lt;void&gt;): void

Registers the P2P persistent group state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
  | callback | Callback&lt;void&gt; | Yes| Callback invoked to return the P2P persistent group state.|


## wifi.off('p2pPersistentGroupChange')<sup>8+</sup>

off(type: "p2pPersistentGroupChange", callback?: Callback&lt;void&gt;): void

Unregisters the P2P persistent group state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
  | 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.|


## wifi.on('p2pDiscoveryChange')<sup>8+</sup>

on(type: "p2pDiscoveryChange", callback: Callback&lt;number&gt;): void

Registers the P2P discovered device state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO

- System capability:
  SystemCapability.Communication.WiFi.P2P

- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the state of the P2P discovered device.|

- Enumerates the states of P2P discovered devices.
  | **Value**| **Description**|
  | -------- | -------- |
  | 0 | Initial state|
  | 1 | Discovered|


## wifi.off('p2pDiscoveryChange')<sup>8+</sup>

off(type: "p2pDiscoveryChange", callback?: Callback&lt;number&gt;): void

Unregisters the P2P discovered device state change events.

- Required permissions:
  ohos.permission.GET_WIFI_INFO
W
wusongqing 已提交
1316

A
annie_wangli 已提交
1317 1318
- System capability:
  SystemCapability.Communication.WiFi.P2P
W
wusongqing 已提交
1319

A
annie_wangli 已提交
1320 1321 1322 1323 1324
- Parameters
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the state of the P2P discovered device. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|