js-apis-wifi.md 61.4 KB
Newer Older
A
Annie_wang 已提交
1 2
# @ohos.wifi (WLAN)

A
Annie_wang 已提交
3
The **WLAN** module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with other devices over WLAN.
W
wusongqing 已提交
4

A
Annie_wang 已提交
5 6
> **NOTE**
>
A
annie_wangli 已提交
7
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
8 9


A
annie_wangli 已提交
10 11 12
## Modules to Import

```js
Z
zengyawen 已提交
13
import wifi from '@ohos.wifi';
W
wusongqing 已提交
14 15
```

A
Annie_wang 已提交
16 17 18 19 20
## wifi.enableWifi

enableWifi(): boolean

Enables WLAN.
A
Annie_wang 已提交
21 22

**System API**: This is a system API.
A
Annie_wang 已提交
23 24 25 26 27 28

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
29

A
Annie_wang 已提交
30 31 32
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
33 34 35 36 37 38 39


## wifi.disableWifi

disableWifi(): boolean

Disables WLAN.
A
Annie_wang 已提交
40 41

**System API**: This is a system API.
A
Annie_wang 已提交
42 43 44 45 46 47

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
48

A
Annie_wang 已提交
49 50 51
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
52 53


A
annie_wangli 已提交
54
## wifi.isWifiActive
W
wusongqing 已提交
55

A
annie_wangli 已提交
56
isWifiActive(): boolean
W
wusongqing 已提交
57

A
Annie_wang 已提交
58
Checks whether WLAN is enabled.
W
wusongqing 已提交
59

A
Annie_wang 已提交
60
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
61

A
Annie_wang 已提交
62
**System capability**: SystemCapability.Communication.WiFi.STA
W
wusongqing 已提交
63

A
Annie_wang 已提交
64
**Return value**
A
Annie_wang 已提交
65

A
Annie_wang 已提交
66 67 68
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.|
W
wusongqing 已提交
69 70


A
annie_wangli 已提交
71
## wifi.scan
Z
zengyawen 已提交
72

A
annie_wangli 已提交
73
scan(): boolean
Z
zengyawen 已提交
74 75 76

Starts a scan for WLAN.

A
Annie_wang 已提交
77
**Required permissions**: **ohos.permission.SET_WIFI_INFO** and **ohos.permission.LOCATION**
Z
zengyawen 已提交
78

A
Annie_wang 已提交
79
**System capability**: SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
80

A
Annie_wang 已提交
81
**Return value**
A
Annie_wang 已提交
82

A
Annie_wang 已提交
83 84 85
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
86 87


A
annie_wangli 已提交
88 89 90
## wifi.getScanInfos

getScanInfos(): Promise<Array<WifiScanInfo>>
Z
zengyawen 已提交
91

A
Annie_wang 已提交
92
Obtains the scan result. This API uses a promise to return the result.
Z
zengyawen 已提交
93

A
Annie_wang 已提交
94
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION)
A
annie_wangli 已提交
95

A
Annie_wang 已提交
96
**System capability**: SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
97

A
Annie_wang 已提交
98
**Return value**
A
Annie_wang 已提交
99

A
Annie_wang 已提交
100 101 102
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | Promise used to return the detected hotspots.|
Z
zengyawen 已提交
103 104


A
annie_wangli 已提交
105
## wifi.getScanInfos
Z
zengyawen 已提交
106

A
annie_wangli 已提交
107
getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void
Z
zengyawen 已提交
108

A
Annie_wang 已提交
109
Obtains the scan result. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
110

A
Annie_wang 已提交
111
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION)
A
annie_wangli 已提交
112

A
Annie_wang 已提交
113
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
114

A
Annie_wang 已提交
115
**Parameters**
A
Annie_wang 已提交
116

A
Annie_wang 已提交
117 118 119
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
A
annie_wangli 已提交
120

A
Annie_wang 已提交
121
**Example**
A
annie_wangli 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
  ```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.

A
Annie_wang 已提交
168 169
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
170

A
Annie_wang 已提交
171 172 173 174 175 176 177 178 179 180 181
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| Service set identifier (SSID) of the hotspot, in UTF-8 format.|
| bssid | string | Yes| No| Basic service set identifier (BSSID) of the hotspot.|
| capabilities | string | Yes| No| Hotspot capabilities.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| WLAN security type.|
| rssi | number | Yes| No| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
| band | number | Yes| No| Frequency band of the WLAN access point (AP).|
| frequency | number | Yes| No| Frequency of the WLAN AP.|
| channelWidth | number | Yes| No| Channel width of the WLAN AP.|
| timestamp | number | Yes| No| Timestamp.|
W
wusongqing 已提交
182 183


A
annie_wangli 已提交
184
## WifiSecurityType
W
wusongqing 已提交
185

A
annie_wangli 已提交
186
Enumerates the WLAN security types.
W
wusongqing 已提交
187

A
Annie_wang 已提交
188 189
**System capability**: SystemCapability.Communication.WiFi.Core

A
Annie_wang 已提交
190

A
Annie_wang 已提交
191
| **Name**| **Value**| **Description**|
A
annie_wangli 已提交
192
| -------- | -------- | -------- |
A
Annie_wang 已提交
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
| 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).|


## wifi.getScanInfosSync<sup>9+</sup>

getScanInfosSync(): &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;

Obtains the scan result. This API returns the result synchronously.

**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
211

A
Annie_wang 已提交
212 213 214
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; | Scan result obtained.|
A
Annie_wang 已提交
215 216 217 218 219 220 221


## wifi.addDeviceConfig

addDeviceConfig(config: WifiDeviceConfig): Promise&lt;number&gt;

Adds network configuration. This API uses a promise to return the result.
A
Annie_wang 已提交
222 223

**System API**: This is a system API.
A
Annie_wang 已提交
224 225 226 227

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG

**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
228

A
Annie_wang 已提交
229
**Parameters**
A
Annie_wang 已提交
230

A
Annie_wang 已提交
231 232 233
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
A
annie_wangli 已提交
234

A
Annie_wang 已提交
235
**Return value**
A
Annie_wang 已提交
236

A
Annie_wang 已提交
237 238
  | **Type**| **Description**|
  | -------- | -------- |
A
Annie_wang 已提交
239
  | Promise&lt;number&gt; | Promise used to return the WLAN configuration ID. If **-1** is returned, the network configuration fails to be added.|
A
annie_wangli 已提交
240 241 242 243 244

## WifiDeviceConfig

Represents the WLAN configuration.

A
Annie_wang 已提交
245 246
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
247

A
Annie_wang 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.|
| bssid | string | Yes| No| BSSID of the hotspot.|
| preSharedKey | string | Yes| No| PSK of the hotspot.|
| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.|
| creatorUid | number | Yes| No| ID of the creator.<br> **System API**: This is a system API.|
| disableReason | number | Yes| No| Reason for disabling WLAN.<br> **System API**: This is a system API.|
| netId | number | Yes| No| Network ID.<br> **System API**: This is a system API.|
| randomMacType | number | Yes| No| Random MAC type.<br> **System API**: This is a system API.|
| randomMacAddr | string | Yes| No| Random MAC address.<br> **System API**: This is a system API.|
| ipType | [IpType](#iptype7) | Yes| No| IP address type.<br> **System API**: This is a system API.|
| staticIp | [IpConfig](#ipconfig7) | Yes| No| Static IP address configuration.<br> **System API**: This is a system API.|
A
Annie_wang 已提交
262 263 264 265


## IpType<sup>7+</sup>

A
Annie_wang 已提交
266
Enumerates the IP address types.
A
Annie_wang 已提交
267

A
Annie_wang 已提交
268 269
**System API**: This is a system API.

A
Annie_wang 已提交
270 271
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
272

A
Annie_wang 已提交
273
| Name| Value| Description|
A
Annie_wang 已提交
274 275 276 277 278 279 280 281 282 283
| -------- | -------- | -------- |
| STATIC | 0 | Static IP address.|
| DHCP | 1 | IP address allocated by DHCP.|
| UNKNOWN | 2 | Not specified.|


## IpConfig<sup>7+</sup>

Represents IP configuration information.

A
Annie_wang 已提交
284 285
**System API**: This is a system API.

A
Annie_wang 已提交
286 287
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
288 289 290 291 292 293
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| ipAddress | number | Yes| No| IP address.|
| gateway | number | Yes| No| Gateway.|
| dnsServers | number[] | Yes| No| Domain name server (DNS) information.|
| domains | Array&lt;string&gt; | Yes| No| Domain information.|
A
Annie_wang 已提交
294 295 296 297 298 299 300


## wifi.addDeviceConfig

addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;number&gt;): void

Adds network configuration. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
301 302

**System API**: This is a system API.
A
Annie_wang 已提交
303 304 305 306 307 308

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
309

A
Annie_wang 已提交
310 311 312 313
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the network configuration ID. If **data** is **-1**, the operation has failed. If **err** is not **0**, an error has occurred.|
A
Annie_wang 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326


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

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

Adds the configuration of an untrusted network. This API uses a promise to return the result.

**Required permissions**: ohos.permission.SET_WIFI_INFO

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
327

A
Annie_wang 已提交
328 329 330
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
A
Annie_wang 已提交
331 332

**Return value**
A
Annie_wang 已提交
333

A
Annie_wang 已提交
334 335 336
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
A
annie_wangli 已提交
337 338 339 340 341 342


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

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

A
Annie_wang 已提交
343
Adds the configuration of an untrusted network. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
344

A
Annie_wang 已提交
345
**Required permissions**: ohos.permission.SET_WIFI_INFO
A
annie_wangli 已提交
346

A
Annie_wang 已提交
347
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
348

A
Annie_wang 已提交
349
**Parameters**
A
Annie_wang 已提交
350

A
Annie_wang 已提交
351 352 353 354
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is **true**. If the operation fails, **data** is **false**. If **err** is not **0**, an error has occurred.|
A
annie_wangli 已提交
355 356 357 358 359 360


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

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

A
Annie_wang 已提交
361
Removes the configuration of an untrusted network. This API uses a promise to return the result.
A
annie_wangli 已提交
362

A
Annie_wang 已提交
363
**Required permissions**: ohos.permission.SET_WIFI_INFO
A
annie_wangli 已提交
364

A
Annie_wang 已提交
365
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
366

A
Annie_wang 已提交
367
**Parameters**
A
Annie_wang 已提交
368

A
Annie_wang 已提交
369 370
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
371
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.|
A
annie_wangli 已提交
372

A
Annie_wang 已提交
373
**Return value**
A
Annie_wang 已提交
374

A
Annie_wang 已提交
375 376 377
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
A
annie_wangli 已提交
378 379 380 381 382 383


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

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

A
Annie_wang 已提交
384
Removes the configuration of an untrusted network. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
385

A
Annie_wang 已提交
386
**Required permissions**: ohos.permission.SET_WIFI_INFO
W
wusongqing 已提交
387

A
Annie_wang 已提交
388
**System capability**: SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
389

A
Annie_wang 已提交
390
**Parameters**
A
Annie_wang 已提交
391

A
Annie_wang 已提交
392 393
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
394
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.|
A
Annie_wang 已提交
395
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is **true**. If the operation fails, **data** is **false**. If **err** is not **0**, an error has occurred.|
A
Annie_wang 已提交
396 397 398 399 400 401 402


## wifi.connectToNetwork

connectToNetwork(networkId: number): boolean

Connects to the specified network.
A
Annie_wang 已提交
403 404

**System API**: This is a system API.
A
Annie_wang 已提交
405 406 407 408 409 410

**Required permissions**: ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
411

A
Annie_wang 已提交
412 413 414
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | networkId | number | Yes| Network configuration ID.|
A
Annie_wang 已提交
415 416

**Return value**
A
Annie_wang 已提交
417

A
Annie_wang 已提交
418 419 420
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
421 422 423 424 425 426 427 428


## wifi.connectToDevice

connectToDevice(config: WifiDeviceConfig): boolean

Connects to the specified network.

A
Annie_wang 已提交
429 430 431
**System API**: This is a system API.

**Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permissio.MANAGE_WIFI_CONNECTION (available only to system applications)
A
Annie_wang 已提交
432 433 434 435 436

**System capability**:
  SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
437

A
Annie_wang 已提交
438 439
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
440
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.|
A
Annie_wang 已提交
441 442

**Return value**
A
Annie_wang 已提交
443

A
Annie_wang 已提交
444 445 446
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
447 448 449 450 451 452


## wifi.disconnect

disconnect(): boolean

A
Annie_wang 已提交
453
Disconnects the network.
A
Annie_wang 已提交
454

A
Annie_wang 已提交
455 456 457
**System API**: This is a system API.

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
A
Annie_wang 已提交
458 459 460 461 462

**System capability**:
  SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
463

A
Annie_wang 已提交
464 465 466
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
467 468


A
annie_wangli 已提交
469 470 471 472
## wifi.getSignalLevel

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

A
Annie_wang 已提交
473
Obtains the WLAN signal level.
A
annie_wangli 已提交
474

A
Annie_wang 已提交
475
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
476

A
Annie_wang 已提交
477
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
478

A
Annie_wang 已提交
479
**Parameters**
A
Annie_wang 已提交
480

A
Annie_wang 已提交
481 482 483 484
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | rssi | number | Yes| RSSI of the hotspot, in dBm.|
  | band | number | Yes| Frequency band of the WLAN AP.|
A
annie_wangli 已提交
485

A
Annie_wang 已提交
486
**Return value**
A
Annie_wang 已提交
487

A
Annie_wang 已提交
488 489 490
  | **Type**| **Description**|
  | -------- | -------- |
  | number | Signal level obtained. The value range is [0, 4].|
A
annie_wangli 已提交
491 492 493 494 495


## wifi.getLinkedInfo

getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
Z
zengyawen 已提交
496

A
Annie_wang 已提交
497
Obtains WLAN connection information. This API uses a promise to return the result.
Z
zengyawen 已提交
498

A
Annie_wang 已提交
499
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
500

A
Annie_wang 已提交
501
**System capability**: SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
502

A
Annie_wang 已提交
503
**Return value**
A
Annie_wang 已提交
504

A
Annie_wang 已提交
505 506
  | Type| Description|
  | -------- | -------- |
A
Annie_wang 已提交
507
  | Promise&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Promise used to return the WLAN connection information.|
Z
zengyawen 已提交
508 509


A
annie_wangli 已提交
510
## wifi.getLinkedInfo
Z
zengyawen 已提交
511

A
annie_wangli 已提交
512
getLinkedInfo(callback: AsyncCallback&lt;WifiLinkedInfo&gt;): void
Z
zengyawen 已提交
513

A
Annie_wang 已提交
514
Obtains WLAN connection information. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
515

A
Annie_wang 已提交
516
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
517

A
Annie_wang 已提交
518
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
519

A
Annie_wang 已提交
520
**Parameters**
A
Annie_wang 已提交
521

A
Annie_wang 已提交
522 523 524
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the WLAN connection information obtained. If **err** is not **0**, an error has occurred.|
A
annie_wangli 已提交
525

A
Annie_wang 已提交
526
**Example**
A
annie_wangli 已提交
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
  ```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.

A
Annie_wang 已提交
550 551
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.|
| bssid | string | Yes| No| BSSID of the hotspot.|
| networkId | number | Yes| No| Network configuration ID.<br> **System API**: This is a system API.|
| rssi | number | Yes| No| RSSI of the hotspot, in dBm.|
| band | number | Yes| No| Frequency band of the WLAN AP.|
| linkSpeed | number | Yes| No| Speed of the WLAN AP.|
| frequency | number | Yes| No| Frequency of the WLAN AP.|
| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.|
| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.|
| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.|
| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.|
| macAddress | string | Yes| No| MAC address of the device.|
| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.|
| suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br> **System API**: This is a system API.|
| connState | [ConnState](#connstate) | Yes| No| WLAN connection state.|
A
annie_wangli 已提交
569 570 571


## ConnState
Z
zengyawen 已提交
572 573 574

Enumerates the WLAN connection states.

A
Annie_wang 已提交
575 576
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
577
| Name| Value| Description|
A
annie_wangli 已提交
578 579 580 581 582 583 584 585
| -------- | -------- | -------- |
| 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.|
A
Annie_wang 已提交
586
| UNKNOWN | 7 | Failed to set up the WLAN connection.|
Z
zengyawen 已提交
587 588


A
Annie_wang 已提交
589 590 591 592
## SuppState

Enumerates the supplicant states.

A
Annie_wang 已提交
593 594
**System API**: This is a system API.

A
Annie_wang 已提交
595 596
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
597
| Name| Value| Description|
A
Annie_wang 已提交
598 599 600 601 602 603 604 605 606 607 608
| -------- | -------- | -------- |
| DISCONNECTED | 0 | The supplicant is disconnected from the AP.|
| INTERFACE_DISABLED | 1 | The network interface is disabled.|
| INACTIVE | 2 | The supplicant is inactive.|
| SCANNING | 3 | The supplicant is scanning for a WLAN connection.|
| AUTHENTICATING | 4 | The supplicant is being authenticated.|
| ASSOCIATING | 5 | The supplicant is being associated with an AP.|
| ASSOCIATED | 6 | The supplicant is associated with an AP.|
| FOUR_WAY_HANDSHAKE | 7 | A four-way handshake is being performed for the supplicant.|
| GROUP_HANDSHAKE | 8 | A group handshake is being performed for the supplicant.|
| COMPLETED | 9 | The authentication is complete.|
A
Annie_wang 已提交
609
| UNINITIALIZED | 10 | The supplicant failed to set up the connection.|
A
Annie_wang 已提交
610 611 612
| INVALID | 11 | Invalid value.|


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

A
annie_wangli 已提交
615 616 617
isConnected(): boolean

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

A
Annie_wang 已提交
619
**Required permissions**: ohos.permission.GET_WIFI_INFO
Z
zengyawen 已提交
620

A
Annie_wang 已提交
621
**System capability**: SystemCapability.Communication.WiFi.STA
Z
zengyawen 已提交
622

A
Annie_wang 已提交
623
**Return value**
A
Annie_wang 已提交
624

A
Annie_wang 已提交
625 626 627
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|
A
Annie_wang 已提交
628 629 630 631 632 633 634


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

getSupportedFeatures(): number

Obtains the features supported by this device.
A
Annie_wang 已提交
635 636

**System API**: This is a system API.
A
Annie_wang 已提交
637 638 639 640 641 642

**Required permissions**: ohos.permission.GET_WIFI_INFO

**System capability**: SystemCapability.Communication.WiFi.Core

**Return value**
A
Annie_wang 已提交
643

A
Annie_wang 已提交
644 645 646
  | **Type**| **Description**|
  | -------- | -------- |
  | number | Feature value. |
A
Annie_wang 已提交
647 648 649 650

**Feature IDs**

| Value| Description|
A
Annie_wang 已提交
651
| -------- | -------- |
A
Annie_wang 已提交
652 653 654 655 656 657 658 659 660 661
| 0x0001 | WLAN infrastructure mode|
| 0x0002 | 5 GHz feature|
| 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 Suite B |
| 0x20000000 | Enhanced open feature|
A
annie_wangli 已提交
662 663 664 665 666


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

isFeatureSupported(featureId: number): boolean
Z
zengyawen 已提交
667 668 669

Checks whether the device supports the specified WLAN feature.

A
Annie_wang 已提交
670 671 672 673 674 675
**Required permissions**: ohos.permission.GET_WIFI_INFO

**System capability**: SystemCapability.Communication.WiFi.Core

**Parameters**

A
Annie_wang 已提交
676

A
Annie_wang 已提交
677 678 679
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | featureId | number | Yes| Feature ID.|
A
Annie_wang 已提交
680 681

**Return value**
A
Annie_wang 已提交
682

A
Annie_wang 已提交
683 684 685
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
A
Annie_wang 已提交
686 687 688 689 690 691 692


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

getDeviceMacAddress(): string[]

Obtains the device MAC address.
A
Annie_wang 已提交
693 694

**System API**: This is a system API.
A
Annie_wang 已提交
695 696 697 698 699 700

**Required permissions**: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
701

A
Annie_wang 已提交
702 703 704
  | **Type**| **Description**|
  | -------- | -------- |
  | string[] | MAC address obtained.|
A
Annie_wang 已提交
705 706 707 708 709 710 711 712 713 714 715 716 717


## 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**
A
Annie_wang 已提交
718

A
Annie_wang 已提交
719 720 721
  | **Type**| **Description**|
  | -------- | -------- |
  | [IpInfo](#ipinfo7) | IP information obtained.|
A
Annie_wang 已提交
722 723 724 725 726 727 728 729


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

Represents IP information.

**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
730 731 732 733 734 735 736 737 738
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| ipAddress | number | Yes| No| IP address.|
| gateway | number | Yes| No| Gateway.|
| netmask | number | Yes| No| Subnet mask.|
| primaryDns | number | Yes| No| IP address of the preferred DNS server.|
| secondDns | number | Yes| No| IP address of the alternate DNS server.|
| serverIp | number | Yes| No| IP address of the DHCP server.|
| leaseDuration | number | Yes| No| Lease duration of the IP address.|
A
Annie_wang 已提交
739 740 741 742 743 744 745 746 747 748 749 750 751


## 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**
A
Annie_wang 已提交
752

A
Annie_wang 已提交
753 754 755
  | **Type**| **Description**|
  | -------- | -------- |
  | string | Country code obtained.|
A
Annie_wang 已提交
756 757 758 759 760 761 762


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

reassociate(): boolean

Re-associates with the network.
A
Annie_wang 已提交
763 764

**System API**: This is a system API.
A
Annie_wang 已提交
765 766 767 768 769 770

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
771

A
Annie_wang 已提交
772 773 774
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
775 776 777 778 779 780 781


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

reconnect(): boolean

Reconnects to the network.
A
Annie_wang 已提交
782 783

**System API**: This is a system API.
A
Annie_wang 已提交
784 785 786 787 788 789

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
790

A
Annie_wang 已提交
791 792 793
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
794 795 796 797 798 799 800


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

getDeviceConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt;

Obtains network configuration.
A
Annie_wang 已提交
801 802

**System API**: This is a system API.
A
Annie_wang 已提交
803 804 805 806 807 808

**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.GET_WIFI_CONFIG

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
809

A
Annie_wang 已提交
810 811 812
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.|
A
Annie_wang 已提交
813 814 815 816


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

A
Annie_wang 已提交
817
updateNetwork(config: WifiDeviceConfig): number
A
Annie_wang 已提交
818 819

Updates network configuration.
A
Annie_wang 已提交
820 821

**System API**: This is a system API.
A
Annie_wang 已提交
822 823 824 825 826 827

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
828

A
Annie_wang 已提交
829 830
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
831
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.|
A
Annie_wang 已提交
832 833

**Return value**
A
Annie_wang 已提交
834

A
Annie_wang 已提交
835 836 837
  | **Type**| **Description**|
  | -------- | -------- |
  | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.|
A
Annie_wang 已提交
838 839 840 841 842 843 844


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

disableNetwork(netId: number): boolean

Disables network configuration.
A
Annie_wang 已提交
845 846

**System API**: This is a system API.
A
Annie_wang 已提交
847 848 849 850 851 852

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
853

A
Annie_wang 已提交
854 855 856
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | netId | number | Yes| ID of the network configuration to disable.|
A
Annie_wang 已提交
857 858

**Return value**
A
Annie_wang 已提交
859

A
Annie_wang 已提交
860 861 862
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
863 864 865 866 867 868 869


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

removeAllNetwork(): boolean

Removes the configuration of all networks.
A
Annie_wang 已提交
870 871

**System API**: This is a system API.
A
Annie_wang 已提交
872 873 874 875 876 877

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Return value**
A
Annie_wang 已提交
878

A
Annie_wang 已提交
879 880 881
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
882 883 884 885 886 887


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

removeDevice(id: number): boolean

A
Annie_wang 已提交
888
Removes the specified network configuration.
A
Annie_wang 已提交
889 890

**System API**: This is a system API.
A
Annie_wang 已提交
891 892 893 894 895 896

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.STA

**Parameters**
A
Annie_wang 已提交
897

A
Annie_wang 已提交
898 899
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
900
| id | number | Yes| ID of the network configuration to remove.|
A
Annie_wang 已提交
901 902

**Return value**
A
Annie_wang 已提交
903

A
Annie_wang 已提交
904 905 906
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
907 908 909 910 911 912 913


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

enableHotspot(): boolean

Enables this hotspot.
A
Annie_wang 已提交
914 915

**System API**: This is a system API.
A
Annie_wang 已提交
916 917 918 919 920 921

**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.AP.Core

**Return value**
A
Annie_wang 已提交
922

A
Annie_wang 已提交
923 924 925
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
926 927 928 929 930 931 932


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

disableHotspot(): boolean

Disables this hotspot.
A
Annie_wang 已提交
933 934

**System API**: This is a system API.
A
Annie_wang 已提交
935 936 937 938 939 940

**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.AP.Core

**Return value**
A
Annie_wang 已提交
941

A
Annie_wang 已提交
942 943 944
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
945 946 947 948 949 950 951


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

isHotspotDualBandSupported(): boolean

Checks whether the hotspot supports dual band.
A
Annie_wang 已提交
952 953

**System API**: This is a system API.
A
Annie_wang 已提交
954 955 956 957 958 959

**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)

**System capability**: SystemCapability.Communication.WiFi.AP.Core

**Return value**
A
Annie_wang 已提交
960

A
Annie_wang 已提交
961 962 963
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
A
Annie_wang 已提交
964 965 966 967 968


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

isHotspotActive(): boolean
A
annie_wangli 已提交
969

A
Annie_wang 已提交
970
Checks whether this hotspot is active.
A
Annie_wang 已提交
971 972

**System API**: This is a system API.
A
Annie_wang 已提交
973

A
Annie_wang 已提交
974
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
975

A
Annie_wang 已提交
976
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
977

A
Annie_wang 已提交
978
**Return value**
A
Annie_wang 已提交
979

A
Annie_wang 已提交
980 981 982
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.|
A
Annie_wang 已提交
983

A
annie_wangli 已提交
984

A
Annie_wang 已提交
985
## wifi.setHotspotConfig<sup>7+</sup>
A
annie_wangli 已提交
986

A
Annie_wang 已提交
987
setHotspotConfig(config: HotspotConfig): boolean
A
annie_wangli 已提交
988

A
Annie_wang 已提交
989
Sets hotspot configuration.
A
Annie_wang 已提交
990 991

**System API**: This is a system API.
A
annie_wangli 已提交
992

A
Annie_wang 已提交
993
**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
A
annie_wangli 已提交
994

A
Annie_wang 已提交
995
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
996

A
Annie_wang 已提交
997
**Parameters**
A
Annie_wang 已提交
998

A
Annie_wang 已提交
999 1000 1001
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [HotspotConfig](#hotspotconfig7) | Yes| Hotspot configuration to set.|
A
annie_wangli 已提交
1002

A
Annie_wang 已提交
1003
**Return value**
A
Annie_wang 已提交
1004

A
Annie_wang 已提交
1005 1006 1007
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1008 1009


A
Annie_wang 已提交
1010
## HotspotConfig<sup>7+</sup>
A
annie_wangli 已提交
1011

A
Annie_wang 已提交
1012 1013
Represents the hotspot configuration.

A
Annie_wang 已提交
1014 1015
**System API**: This is a system API.

A
Annie_wang 已提交
1016
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1017

A
Annie_wang 已提交
1018 1019 1020 1021 1022 1023 1024
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.|
| band | number | Yes| No| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.|
| preSharedKey | string | Yes| No| PSK of the hotspot.|
| maxConn | number | Yes| No| Maximum number of connections allowed.|
A
annie_wangli 已提交
1025 1026


A
Annie_wang 已提交
1027
## wifi.getHotspotConfig<sup>7+</sup>
A
annie_wangli 已提交
1028

A
Annie_wang 已提交
1029
getHotspotConfig(): HotspotConfig
A
annie_wangli 已提交
1030

A
Annie_wang 已提交
1031
obtains hotspot configuration.
A
Annie_wang 已提交
1032 1033

**System API**: This is a system API.
A
annie_wangli 已提交
1034

A
Annie_wang 已提交
1035
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
A
annie_wangli 已提交
1036

A
Annie_wang 已提交
1037
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1038

A
Annie_wang 已提交
1039
**Return value**
A
Annie_wang 已提交
1040

A
Annie_wang 已提交
1041 1042 1043
  | **Type**| **Description**|
  | -------- | -------- |
  | [HotspotConfig](#hotspotconfig7) | Hotspot configuration obtained.|
A
annie_wangli 已提交
1044 1045


A
Annie_wang 已提交
1046
## wifi.getStations<sup>7+</sup>
A
annie_wangli 已提交
1047

A
Annie_wang 已提交
1048
getStations(): &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt;
A
annie_wangli 已提交
1049

A
Annie_wang 已提交
1050
Obtains information about the connected stations.
A
Annie_wang 已提交
1051 1052

**System API**: This is a system API.
A
annie_wangli 已提交
1053

A
Annie_wang 已提交
1054
**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
A
annie_wangli 已提交
1055

A
Annie_wang 已提交
1056
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1057

A
Annie_wang 已提交
1058
**Return value**
A
Annie_wang 已提交
1059

A
Annie_wang 已提交
1060 1061 1062
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | Connected stations obtained.|
A
Annie_wang 已提交
1063 1064 1065 1066 1067 1068


## StationInfo<sup>7+</sup>

Represents the station information.

A
Annie_wang 已提交
1069 1070
**System API**: This is a system API.

A
Annie_wang 已提交
1071 1072
**System capability**: SystemCapability.Communication.WiFi.AP.Core

A
Annie_wang 已提交
1073 1074 1075 1076 1077
| **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| name | string | Yes| No| Device name.|
| macAddress | string | Yes| No| MAC address.|
| ipAddress | string | Yes| No| IP address.|
A
annie_wangli 已提交
1078 1079 1080 1081


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

A
Annie_wang 已提交
1082
getP2pLinkedInfo(): Promise&lt;WifiP2pLinkedInfo&gt;
A
annie_wangli 已提交
1083

A
Annie_wang 已提交
1084
Obtains P2P link information. This API uses a promise to return the result.
A
annie_wangli 已提交
1085

A
Annie_wang 已提交
1086
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1087

A
Annie_wang 已提交
1088
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1089

A
Annie_wang 已提交
1090
**Return value**
A
Annie_wang 已提交
1091

A
Annie_wang 已提交
1092 1093 1094
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Promise used to return the P2P link information obtained.|
A
Annie_wang 已提交
1095

A
annie_wangli 已提交
1096 1097 1098 1099


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

A
Annie_wang 已提交
1100 1101 1102
Represents the P2P link information.

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1103

A
Annie_wang 已提交
1104 1105 1106 1107 1108
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| connectState | [P2pConnectState](#p2pconnectstate8) | Yes| No| P2P connection state.|
| isGroupOwner | boolean | Yes| No| Whether the device is the group owner.|
| groupOwnerAddr | string | Yes| No| MAC address of the group.
A
annie_wangli 已提交
1109 1110 1111 1112 1113 1114


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

Enumerates the P2P connection states.

A
Annie_wang 已提交
1115 1116
**System capability**: SystemCapability.Communication.WiFi.P2P

A
Annie_wang 已提交
1117
| Name| Value| Description|
A
annie_wangli 已提交
1118
| -------- | -------- | -------- |
A
Annie_wang 已提交
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
| DISCONNECTED | 0 | Disconnected.|
| CONNECTED | 1 | Connected.|


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

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

Obtains P2P link information. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_WIFI_INFO

**System capability**: SystemCapability.Communication.WiFi.P2P

**Parameters**
A
Annie_wang 已提交
1134

A
Annie_wang 已提交
1135 1136 1137
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the P2P link information. If **err** is not **0**, an error has occurred.|
A
annie_wangli 已提交
1138 1139 1140 1141 1142 1143


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

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

A
Annie_wang 已提交
1144
Obtains the current P2P group information. This API uses a promise to return the result.
A
annie_wangli 已提交
1145

A
Annie_wang 已提交
1146
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1147

A
Annie_wang 已提交
1148
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1149

A
Annie_wang 已提交
1150
**Return value**
A
Annie_wang 已提交
1151

A
Annie_wang 已提交
1152 1153
  | Type| Description|
  | -------- | -------- |
A
Annie_wang 已提交
1154
  | Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt; | Promise used to return the P2P group information obtained.|
A
annie_wangli 已提交
1155 1156 1157 1158 1159 1160


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

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

A
Annie_wang 已提交
1161
Obtains the current P2P group information. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
1162

A
Annie_wang 已提交
1163
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1164

A
Annie_wang 已提交
1165
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1166

A
Annie_wang 已提交
1167
**Parameters**
A
Annie_wang 已提交
1168

A
Annie_wang 已提交
1169 1170 1171
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the group information obtained. If **err** is not **0**, an error has occurred.|
A
Annie_wang 已提交
1172 1173


A
Annie_wang 已提交
1174 1175 1176
## wifi.getP2pPeerDevices<sup>8+</sup>

getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;
A
Annie_wang 已提交
1177

A
Annie_wang 已提交
1178
Obtains the peer device list in the P2P connection. This API uses a promise to return the result.
A
Annie_wang 已提交
1179 1180 1181 1182 1183 1184

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

**System capability**: SystemCapability.Communication.WiFi.P2P

**Return value**
A
Annie_wang 已提交
1185

A
Annie_wang 已提交
1186 1187 1188
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Promise used to return the peer device list.|
A
Annie_wang 已提交
1189 1190


A
Annie_wang 已提交
1191
## wifi.getP2pPeerDevices<sup>8+</sup>
A
Annie_wang 已提交
1192

A
Annie_wang 已提交
1193 1194
getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void

A
Annie_wang 已提交
1195
Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1196 1197 1198 1199

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

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1200

A
Annie_wang 已提交
1201
**Parameters**
A
Annie_wang 已提交
1202

A
Annie_wang 已提交
1203 1204 1205
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the peer device list obtained. If **err** is not **0**, an error has occurred.|
A
annie_wangli 已提交
1206 1207 1208 1209 1210 1211


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

Represents the P2P device information.

A
Annie_wang 已提交
1212 1213
**System capability**: SystemCapability.Communication.WiFi.P2P

A
Annie_wang 已提交
1214 1215 1216 1217 1218 1219 1220
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| deviceName | string | Yes| No| Device name.|
| deviceAddress | string | Yes| No| MAC address of the device.|
| primaryDeviceType | string | Yes| No| Type of the primary device.|
| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus8) | Yes| No| Device status.|
| groupCapabilitys | number | Yes| No| Group capabilities.|
A
annie_wangli 已提交
1221 1222


A
Annie_wang 已提交
1223
## P2pDeviceStatus<sup>8+</sup>
A
annie_wangli 已提交
1224

A
Annie_wang 已提交
1225
Enumerates the P2P device states.
A
annie_wangli 已提交
1226

A
Annie_wang 已提交
1227
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1228

A
Annie_wang 已提交
1229
| Name| Value| Description|
A
Annie_wang 已提交
1230 1231 1232 1233 1234 1235
| -------- | -------- | -------- |
| CONNECTED | 0 | Connected.|
| INVITED | 1 | Invited.|
| FAILED | 2 | Failed.|
| AVAILABLE | 3 | Available.|
| UNAVAILABLE | 4 | Unavailable.|
A
annie_wangli 已提交
1236

A
Annie_wang 已提交
1237

A
annie_wangli 已提交
1238 1239
## wifi.createGroup<sup>8+</sup>

A
Annie_wang 已提交
1240
createGroup(config: WifiP2PConfig): boolean
A
annie_wangli 已提交
1241 1242 1243

Creates a P2P group.

A
Annie_wang 已提交
1244 1245 1246
**Required permissions**: ohos.permission.GET_WIFI_INFO

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1247

A
Annie_wang 已提交
1248
**Parameters**
A
annie_wangli 已提交
1249

A
Annie_wang 已提交
1250 1251 1252
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| Group configuration.|
A
annie_wangli 已提交
1253

A
Annie_wang 已提交
1254
**Return value**
A
Annie_wang 已提交
1255

A
Annie_wang 已提交
1256 1257 1258
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1259

A
annie_wangli 已提交
1260 1261 1262

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

A
Annie_wang 已提交
1263
Represents P2P group configuration.
A
annie_wangli 已提交
1264

A
Annie_wang 已提交
1265 1266
**System capability**: SystemCapability.Communication.WiFi.P2P

A
Annie_wang 已提交
1267 1268 1269 1270 1271 1272 1273
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| deviceAddress | string | Yes| No| Device address.|
| netId | number | Yes| No| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.|
| passphrase | string | Yes| No| Passphrase of the group.|
| groupName | string | Yes| No| Name of the group.|
| goBand | [GroupOwnerBand](#groupownerband8) | Yes| No| Frequency band of the group.|
A
annie_wangli 已提交
1274 1275 1276 1277


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

A
Annie_wang 已提交
1278 1279 1280
Enumerates the P2P group frequency bands.

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1281

A
Annie_wang 已提交
1282
| Name| Value| Description|
A
annie_wangli 已提交
1283
| -------- | -------- | -------- |
A
Annie_wang 已提交
1284 1285 1286 1287
| GO_BAND_AUTO | 0 | Auto.|
| GO_BAND_2GHZ | 1 | 2 GHz.|
| GO_BAND_5GHZ | 2 | 5 GHz.|

A
annie_wangli 已提交
1288 1289 1290

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

A
Annie_wang 已提交
1291
removeGroup(): boolean
A
annie_wangli 已提交
1292

A
Annie_wang 已提交
1293
Removes this P2P group.
A
annie_wangli 已提交
1294

A
Annie_wang 已提交
1295
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1296

A
Annie_wang 已提交
1297
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1298

A
Annie_wang 已提交
1299
**Return value**
A
Annie_wang 已提交
1300

A
Annie_wang 已提交
1301 1302 1303
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1304 1305 1306 1307


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

A
Annie_wang 已提交
1308
p2pConnect(config: WifiP2PConfig): boolean
A
annie_wangli 已提交
1309 1310 1311

Sets up a P2P connection.

A
Annie_wang 已提交
1312
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1313

A
Annie_wang 已提交
1314 1315 1316
**System capability**: SystemCapability.Communication.WiFi.P2P

**Parameters**
A
annie_wangli 已提交
1317

A
Annie_wang 已提交
1318

A
Annie_wang 已提交
1319 1320 1321
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| P2P group configuration.|
A
annie_wangli 已提交
1322

A
Annie_wang 已提交
1323
**Return value**
A
Annie_wang 已提交
1324

A
Annie_wang 已提交
1325 1326 1327
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1328 1329


A
Annie_wang 已提交
1330
**Example**
A
annie_wangli 已提交
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  ```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);
  
A
Annie_wang 已提交
1377
  var recvP2pPersistentGroupChangeFunc = () => {
A
annie_wangli 已提交
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
      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>

A
Annie_wang 已提交
1399
p2pCancelConnect(): boolean
A
annie_wangli 已提交
1400 1401 1402

Cancels this P2P connection.

A
Annie_wang 已提交
1403
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1404

A
Annie_wang 已提交
1405
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1406

A
Annie_wang 已提交
1407
**Return value**
A
Annie_wang 已提交
1408

A
Annie_wang 已提交
1409 1410 1411
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1412 1413 1414 1415


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

A
Annie_wang 已提交
1416
startDiscoverDevices(): boolean
A
annie_wangli 已提交
1417 1418 1419

Starts to discover devices.

A
Annie_wang 已提交
1420
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1421

A
Annie_wang 已提交
1422
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1423

A
Annie_wang 已提交
1424
**Return value**
A
Annie_wang 已提交
1425

A
Annie_wang 已提交
1426 1427 1428
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1429 1430 1431 1432


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

A
Annie_wang 已提交
1433
stopDiscoverDevices(): boolean
A
annie_wangli 已提交
1434 1435 1436

Stops discovering devices.

A
Annie_wang 已提交
1437
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1438

A
Annie_wang 已提交
1439
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1440

A
Annie_wang 已提交
1441
**Return value**
A
Annie_wang 已提交
1442

A
Annie_wang 已提交
1443 1444 1445
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1446 1447 1448 1449 1450 1451 1452 1453


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

deletePersistentGroup(netId: number): boolean

Deletes a persistent group.

A
Annie_wang 已提交
1454 1455 1456
**System API**: This is a system API.

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
A
Annie_wang 已提交
1457 1458 1459 1460 1461

**System capability**: SystemCapability.Communication.WiFi.P2P

**Parameters**

A
Annie_wang 已提交
1462

A
Annie_wang 已提交
1463 1464 1465
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | netId | number | Yes| ID of the group to delete.|
A
Annie_wang 已提交
1466 1467

**Return value**
A
Annie_wang 已提交
1468

A
Annie_wang 已提交
1469 1470 1471
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1472 1473 1474 1475 1476 1477 1478 1479


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

Represents the P2P group information.

**System capability**: SystemCapability.Communication.WiFi.P2P

A
Annie_wang 已提交
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| isP2pGo | boolean | Yes| No| Whether the device is the group owner.|
| ownerInfo | [WifiP2pDevice](#wifip2pdevice8) | Yes| No| Device information of the group.|
| passphrase | string | Yes| No| Passphrase of the group.|
| interface | string | Yes| No| Interface name.|
| groupName | string | Yes| No| Group name.|
| networkId | number | Yes| No| Network ID.|
| frequency | number | Yes| No| Frequency of the group.|
| clientDevices | [WifiP2pDevice[]](#wifip2pdevice8) | Yes| No| List of connected devices.|
| goIpAddress | string | Yes| No| IP address of the group.|
A
Annie_wang 已提交
1491 1492 1493 1494 1495 1496 1497 1498


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

setDeviceName(devName: string): boolean

Sets the device name.

A
Annie_wang 已提交
1499 1500 1501
**System API**: This is a system API.

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
A
Annie_wang 已提交
1502 1503 1504 1505

**System capability**: SystemCapability.Communication.WiFi.P2P

**Parameters**
A
Annie_wang 已提交
1506

A
Annie_wang 已提交
1507 1508 1509
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | devName | string | Yes| Device name to set.|
A
Annie_wang 已提交
1510 1511

**Return value**
A
Annie_wang 已提交
1512

A
Annie_wang 已提交
1513 1514 1515
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1516 1517 1518 1519 1520


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

on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1521 1522 1523

Registers the WLAN state change events.

A
Annie_wang 已提交
1524
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1525

A
Annie_wang 已提交
1526
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1527

A
Annie_wang 已提交
1528
**Parameters**
A
Annie_wang 已提交
1529

A
Annie_wang 已提交
1530 1531 1532 1533
  | **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.|
A
annie_wangli 已提交
1534

A
Annie_wang 已提交
1535 1536 1537 1538
**WLAN states** 

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1539 1540 1541 1542
| 0 | Deactivated|
| 1 | Activated|
| 2 | Activating|
| 3 | Deactivating|
A
annie_wangli 已提交
1543 1544 1545 1546 1547


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

off(type: "wifiStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1548 1549 1550

Unregisters the WLAN state change events.

A
Annie_wang 已提交
1551
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1552

A
Annie_wang 已提交
1553
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1554

A
Annie_wang 已提交
1555
**Parameters**
A
Annie_wang 已提交
1556

A
Annie_wang 已提交
1557 1558 1559
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiStateChange**.|
A
Annie_wang 已提交
1560
  | callback | Callback&lt;number&gt; | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1561

A
Annie_wang 已提交
1562
**Example**
A
annie_wangli 已提交
1563 1564 1565 1566 1567 1568 1569
  ```js
  import wifi from '@ohos.wifi';
  
  var recvPowerNotifyFunc = result => {
      console.info("Receive power state change event: " + result);
  }
  
A
Annie_wang 已提交
1570
  // Register an event.
A
Annie_wang 已提交
1571
  wifi.on("wifiStateChange", recvPowerNotifyFunc);
A
annie_wangli 已提交
1572
  
A
Annie_wang 已提交
1573
  // Unregister an event.
A
Annie_wang 已提交
1574
  wifi.off("wifiStateChange", recvPowerNotifyFunc);
A
annie_wangli 已提交
1575 1576 1577 1578 1579 1580
  ```


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

on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1581 1582 1583

Registers the WLAN connection state change events.

A
Annie_wang 已提交
1584
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1585

A
Annie_wang 已提交
1586
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1587

A
Annie_wang 已提交
1588
**Parameters**
A
Annie_wang 已提交
1589

A
Annie_wang 已提交
1590 1591 1592 1593
  | **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.|
A
annie_wangli 已提交
1594

A
Annie_wang 已提交
1595 1596 1597 1598
**WLAN connection states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1599 1600
| 0 | Disconnected.|
| 1 | Connected.|
A
annie_wangli 已提交
1601 1602 1603 1604 1605


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

off(type: "wifiConnectionChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1606 1607 1608

Unregisters the WLAN connection state change events.

A
Annie_wang 已提交
1609
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1610

A
Annie_wang 已提交
1611
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1612

A
Annie_wang 已提交
1613
**Parameters**
A
Annie_wang 已提交
1614

A
Annie_wang 已提交
1615 1616 1617
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
A
Annie_wang 已提交
1618
  | callback | Callback&lt;number&gt; | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1619 1620 1621 1622 1623


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

on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1624 1625 1626

Registers the WLAN scan state change events.

A
Annie_wang 已提交
1627
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1628

A
Annie_wang 已提交
1629
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1630

A
Annie_wang 已提交
1631
**Parameters**
A
Annie_wang 已提交
1632

A
Annie_wang 已提交
1633 1634 1635 1636
  | **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.|
A
annie_wangli 已提交
1637

A
Annie_wang 已提交
1638 1639 1640 1641
**WLAN scan states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1642 1643
| 0 | Scan failed.|
| 1 | Scan successful.|
A
annie_wangli 已提交
1644 1645 1646 1647 1648


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

off(type: "wifiScanStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1649 1650 1651

Unregisters the WLAN scan state change events.

A
Annie_wang 已提交
1652
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1653

A
Annie_wang 已提交
1654
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1655

A
Annie_wang 已提交
1656
**Parameters**
A
annie_wangli 已提交
1657 1658 1659 1660

| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiScanStateChange**.|
A
Annie_wang 已提交
1661
| callback | Callback&lt;number&gt; | No| Callback for the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1662 1663 1664 1665 1666


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

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

A
Annie_wang 已提交
1668
Registers the RSSI change events.
Z
zengyawen 已提交
1669

A
Annie_wang 已提交
1670
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1671

A
Annie_wang 已提交
1672
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1673

A
Annie_wang 已提交
1674
**Parameters**
A
Annie_wang 已提交
1675

A
Annie_wang 已提交
1676 1677 1678 1679
  | **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.|
A
annie_wangli 已提交
1680 1681 1682 1683 1684


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

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

A
Annie_wang 已提交
1686
Unregisters the RSSI change events.
Z
zengyawen 已提交
1687

A
Annie_wang 已提交
1688
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1689

A
Annie_wang 已提交
1690
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1691

A
Annie_wang 已提交
1692
**Parameters**
A
Annie_wang 已提交
1693

A
Annie_wang 已提交
1694 1695 1696
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
A
Annie_wang 已提交
1697
| callback | Callback&lt;number&gt; | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1698 1699 1700 1701 1702


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

on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1703 1704 1705

Registers the hotspot state change events.

A
Annie_wang 已提交
1706
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1707

A
Annie_wang 已提交
1708
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1709

A
Annie_wang 已提交
1710
**Parameters**
A
Annie_wang 已提交
1711

A
Annie_wang 已提交
1712 1713 1714 1715
  | **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.|
A
annie_wangli 已提交
1716

A
Annie_wang 已提交
1717 1718 1719 1720
**Hotspot states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1721 1722 1723 1724
| 0 | Deactivated|
| 1 | Activated|
| 2 | Activating|
| 3 | Deactivating|
A
annie_wangli 已提交
1725 1726 1727 1728 1729


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

off(type: "hotspotStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1730 1731 1732

Unregisters the hotspot state change events.

A
Annie_wang 已提交
1733
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1734

A
Annie_wang 已提交
1735
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1736

A
Annie_wang 已提交
1737
**Parameters**
A
Annie_wang 已提交
1738

A
Annie_wang 已提交
1739 1740 1741
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
A
Annie_wang 已提交
1742
| callback | Callback&lt;number&gt; | No| Callback for the hotspot state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1743 1744 1745 1746 1747 1748


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

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

A
Annie_wang 已提交
1749
Registers the P2P state change events.
A
annie_wangli 已提交
1750

A
Annie_wang 已提交
1751
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1752

A
Annie_wang 已提交
1753
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1754

A
Annie_wang 已提交
1755
**Parameters**
A
Annie_wang 已提交
1756

A
Annie_wang 已提交
1757 1758 1759 1760
  | **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.|
A
annie_wangli 已提交
1761

A
Annie_wang 已提交
1762 1763 1764 1765
**P2P states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1766 1767 1768 1769 1770
| 1 | Available|
| 2 | Opening|
| 3 | Opened|
| 4 | Closing|
| 5 | Closed|
A
annie_wangli 已提交
1771 1772 1773 1774 1775 1776 1777

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

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

Unregisters the P2P state change events.

A
Annie_wang 已提交
1778
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1779

A
Annie_wang 已提交
1780
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1781

A
Annie_wang 已提交
1782
**Parameters**
A
Annie_wang 已提交
1783

A
Annie_wang 已提交
1784 1785 1786
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pStateChange**.|
A
Annie_wang 已提交
1787
| callback | Callback&lt;number&gt; | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1788 1789 1790 1791 1792 1793 1794 1795


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

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

Registers the P2P connection state change events.

A
Annie_wang 已提交
1796
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1797

A
Annie_wang 已提交
1798
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1799

A
Annie_wang 已提交
1800
**Parameters**
A
Annie_wang 已提交
1801

A
Annie_wang 已提交
1802 1803 1804 1805
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Yes| Callback invoked to return the P2P connection state.|
A
annie_wangli 已提交
1806 1807 1808 1809 1810 1811 1812 1813


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

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

Unregisters the P2P connection state change events.

A
Annie_wang 已提交
1814
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1815

A
Annie_wang 已提交
1816
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1817

A
Annie_wang 已提交
1818
**Parameters**
A
Annie_wang 已提交
1819

A
Annie_wang 已提交
1820 1821 1822
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
A
Annie_wang 已提交
1823
| callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1824 1825 1826 1827 1828 1829 1830 1831


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

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

Registers the P2P device state change events.

A
Annie_wang 已提交
1832
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1833

A
Annie_wang 已提交
1834
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1835

A
Annie_wang 已提交
1836
**Parameters**
A
Annie_wang 已提交
1837

A
Annie_wang 已提交
1838 1839 1840 1841
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | Yes| Callback invoked to return the P2P device state.|
A
annie_wangli 已提交
1842 1843 1844 1845 1846 1847 1848 1849


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

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

Unregisters the P2P device state change events.

A
Annie_wang 已提交
1850
**Required permissions**: ohos.permission.LOCATION
A
annie_wangli 已提交
1851

A
Annie_wang 已提交
1852
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1853

A
Annie_wang 已提交
1854
**Parameters**
A
Annie_wang 已提交
1855

A
Annie_wang 已提交
1856 1857 1858
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
A
Annie_wang 已提交
1859
| callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1860 1861 1862 1863 1864 1865 1866 1867


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

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

Registers the P2P peer device state change events.

A
Annie_wang 已提交
1868
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
1869

A
Annie_wang 已提交
1870
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1871

A
Annie_wang 已提交
1872
**Parameters**
A
Annie_wang 已提交
1873

A
Annie_wang 已提交
1874 1875 1876
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
A
Annie_wang 已提交
1877
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Yes| Callback invoked to return the P2P peer device state.|
A
annie_wangli 已提交
1878 1879 1880 1881 1882 1883 1884 1885


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

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

Unregisters the P2P peer device state change events.

A
Annie_wang 已提交
1886
**Required permissions**: ohos.permission.LOCATION
A
annie_wangli 已提交
1887

A
Annie_wang 已提交
1888
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1889

A
Annie_wang 已提交
1890
**Parameters**
A
Annie_wang 已提交
1891

A
Annie_wang 已提交
1892 1893 1894
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
A
Annie_wang 已提交
1895
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1896 1897 1898 1899 1900 1901 1902 1903


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

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

Registers the P2P persistent group state change events.

A
Annie_wang 已提交
1904
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1905

A
Annie_wang 已提交
1906
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1907

A
Annie_wang 已提交
1908
**Parameters**
A
Annie_wang 已提交
1909

A
Annie_wang 已提交
1910 1911 1912 1913
  | **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.|
A
annie_wangli 已提交
1914 1915 1916 1917 1918 1919 1920 1921


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

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

Unregisters the P2P persistent group state change events.

A
Annie_wang 已提交
1922
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1923

A
Annie_wang 已提交
1924
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1925

A
Annie_wang 已提交
1926
**Parameters**
A
Annie_wang 已提交
1927

A
Annie_wang 已提交
1928 1929 1930
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
A
Annie_wang 已提交
1931
| callback | Callback&lt;void&gt; | No| Callback for the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1932 1933 1934 1935 1936 1937


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

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

A
Annie_wang 已提交
1938
Registers the P2P device discovery state change events.
A
annie_wangli 已提交
1939

A
Annie_wang 已提交
1940
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1941

A
Annie_wang 已提交
1942
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1943

A
Annie_wang 已提交
1944
**Parameters**
A
Annie_wang 已提交
1945

A
Annie_wang 已提交
1946 1947 1948 1949
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
  | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P device discovery state.|
A
annie_wangli 已提交
1950

A
Annie_wang 已提交
1951 1952 1953 1954
**P2P discovered device states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1955 1956
| 0 | Initial state.|
| 1 | Discovered.|
A
annie_wangli 已提交
1957 1958 1959 1960 1961 1962


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

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

A
Annie_wang 已提交
1963
Unregisters the P2P device discovery state change events.
A
annie_wangli 已提交
1964

A
Annie_wang 已提交
1965
**Required permissions**: ohos.permission.GET_WIFI_INFO
W
wusongqing 已提交
1966

A
Annie_wang 已提交
1967
**System capability**: SystemCapability.Communication.WiFi.P2P
W
wusongqing 已提交
1968

A
Annie_wang 已提交
1969
**Parameters**
A
Annie_wang 已提交
1970

A
Annie_wang 已提交
1971 1972 1973
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
A
Annie_wang 已提交
1974
| callback | Callback&lt;number&gt; | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|