js-apis-wifi.md 71.9 KB
Newer Older
A
annie_wangli 已提交
1
# WLAN
A
Annie_wang 已提交
2
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 已提交
3

A
Annie_wang 已提交
4
> **NOTE**<br>
A
annie_wangli 已提交
5
> 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 已提交
6 7


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

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

A
Annie_wang 已提交
14 15 16 17 18
## wifi.enableWifi

enableWifi(): boolean

Enables WLAN.
A
Annie_wang 已提交
19 20

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

**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 已提交
27

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


## wifi.disableWifi

disableWifi(): boolean

Disables WLAN.
A
Annie_wang 已提交
38 39

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

**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 已提交
46

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


A
annie_wangli 已提交
52
## wifi.isWifiActive
W
wusongqing 已提交
53

A
annie_wangli 已提交
54
isWifiActive(): boolean
W
wusongqing 已提交
55

A
Annie_wang 已提交
56
Checks whether WLAN is enabled.
W
wusongqing 已提交
57

A
Annie_wang 已提交
58
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
59

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

A
Annie_wang 已提交
62
**Return value**
A
Annie_wang 已提交
63

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


A
annie_wangli 已提交
69
## wifi.scan
Z
zengyawen 已提交
70

A
annie_wangli 已提交
71
scan(): boolean
Z
zengyawen 已提交
72 73 74

Starts a scan for WLAN.

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

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

A
Annie_wang 已提交
79
**Return value**
A
Annie_wang 已提交
80

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


A
annie_wangli 已提交
86 87 88
## wifi.getScanInfos

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

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

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

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

A
Annie_wang 已提交
96
**Return value**
A
Annie_wang 已提交
97

A
Annie_wang 已提交
98 99 100
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the detected hotspots.|
Z
zengyawen 已提交
101 102


A
annie_wangli 已提交
103
## wifi.getScanInfos
Z
zengyawen 已提交
104

A
annie_wangli 已提交
105
getScanInfos(callback: AsyncCallback&lt;Array&lt;WifiScanInfo&gt;&gt;): void
Z
zengyawen 已提交
106

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

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

A
Annie_wang 已提交
111
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
112

A
Annie_wang 已提交
113
**Parameters**
A
Annie_wang 已提交
114

A
Annie_wang 已提交
115 116 117
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&gt; | 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 已提交
118

A
Annie_wang 已提交
119
**Example**
A
annie_wangli 已提交
120 121 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
  ```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 已提交
166 167
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
168

A
annie_wangli 已提交
169 170
| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
171
| ssid | string | Read only| Service set identifier (SSID) of the hotspot, in UTF-8 format.|
A
annie_wangli 已提交
172 173
| bssid | string | Read only| Basic service set identifier (BSSID) of the hotspot.|
| capabilities | string | Read only| Hotspot capabilities.|
A
Annie_wang 已提交
174
| securityType | [WifiSecurityType](#wifisecuritytype) | Read only| WLAN security type.|
A
Annie_wang 已提交
175
| rssi | number | Read only| Received signal strength indicator (RSSI) of the hotspot, in dBm.|
A
annie_wangli 已提交
176 177
| band | number | Read only| Frequency band of the WLAN access point (AP).|
| frequency | number | Read only| Frequency of the WLAN AP.|
A
Annie_wang 已提交
178
| channelWidth | number | Read only| Channel width of the WLAN AP.|
A
Annie_wang 已提交
179 180
| centerFrequency0<sup>9+</sup> | number | Read only| Center frequency of the hotspot.|
| centerFrequency1<sup>9+</sup> | number | Read only| Center frequency of the hotspot. If the hotspot uses two non-overlapping WLAN channels, two center frequencies, namely **centerFrequency0** and **centerFrequency1**, are returned.|
A
Annie_wang 已提交
181
| infoElems<sup>9+</sup> | Array&lt;[WifiInfoElem](#wifiinfoelem9)&gt; | Read only| Information elements.|
A
annie_wangli 已提交
182
| timestamp | number | Read only| Timestamp.|
W
wusongqing 已提交
183 184


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

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

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

A
Annie_wang 已提交
191

A
annie_wangli 已提交
192 193
| **Name**| **Default Value**| **Description**|
| -------- | -------- | -------- |
A
Annie_wang 已提交
194 195 196 197 198 199 200 201 202 203
| 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_SEC_TYPE_EAP<sup>9+</sup> | 5 | Extensible Authentication protocol (EAP).|
| WIFI_SEC_TYPE_EAP_SUITE_B<sup>9+</sup> | 6 | Suite B 192-bit encryption.|
| WIFI_SEC_TYPE_OWE<sup>9+</sup> | 7 | Opportunistic Wireless Encryption (OWE).|
| WIFI_SEC_TYPE_WAPI_CERT<sup>9+</sup> | 8 | WLAN Authentication and Privacy Infrastructure (WAPI) in certificate-based mode (WAPI-CERT).|
| WIFI_SEC_TYPE_WAPI_PSK<sup>9+</sup> | 9 | WAPI-PSK.|
W
wusongqing 已提交
204 205


A
Annie_wang 已提交
206
## WifiInfoElem<sup>9+</sup>
A
annie_wangli 已提交
207

A
Annie_wang 已提交
208
Represents a WLAN information element.
A
annie_wangli 已提交
209

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

A
Annie_wang 已提交
212
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
213

A
Annie_wang 已提交
214

A
Annie_wang 已提交
215 216 217 218
| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| eid | number | Read only| ID of the information element.|
| content | Uint8Array | Read only| Content of the information element.|
A
annie_wangli 已提交
219

A
Annie_wang 已提交
220 221 222

## WifiChannelWidth<sup>9+</sup>

A
Annie_wang 已提交
223
Enumerates the WLAN channel widths.
A
Annie_wang 已提交
224 225 226

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

A
Annie_wang 已提交
227

A
Annie_wang 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
| **Name**| **Default Value**| **Description**|
| -------- | -------- | -------- |
| WIDTH_20MHZ | 0 | 20 MHz.|
| WIDTH_40MHZ | 1 | 40 MHz.|
| WIDTH_80MHZ | 2 | 80 MHz.|
| WIDTH_160MHZ | 3 | 160 MHz.|
| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>.|
| WIDTH_INVALID | 5 | Invalid value.|


## 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 已提交
249

A
Annie_wang 已提交
250 251 252
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; | Scan result obtained.|
A
Annie_wang 已提交
253 254 255 256 257 258 259


## wifi.addDeviceConfig

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

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

**System API**: This is a system API.
A
Annie_wang 已提交
262 263 264 265

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

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

A
Annie_wang 已提交
267
**Parameters**
A
Annie_wang 已提交
268

A
Annie_wang 已提交
269 270 271
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
A
annie_wangli 已提交
272

A
Annie_wang 已提交
273
**Return value**
A
Annie_wang 已提交
274

A
Annie_wang 已提交
275 276 277
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;number&gt; | Promise used to return the WLAN configuration ID. If **-1** is returned, the operation has failed.|
A
annie_wangli 已提交
278 279 280 281 282

## WifiDeviceConfig

Represents the WLAN configuration.

A
Annie_wang 已提交
283 284
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
285

A
annie_wangli 已提交
286 287
| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
288
| ssid | string | Read only| SSID of the hotspot, in UTF-8 format.|
A
annie_wangli 已提交
289
| bssid | string | Read only| BSSID of the hotspot.|
A
Annie_wang 已提交
290
| preSharedKey | string | Read only| PSK of the hotspot.|
A
Annie_wang 已提交
291
| isHiddenSsid | boolean | Read only| Whether the network is hidden.|
A
Annie_wang 已提交
292
| securityType | [WifiSecurityType](#wifisecuritytype) | Read only| Security type.|
A
Annie_wang 已提交
293 294 295 296 297 298 299 300
| creatorUid | number | Read only| ID of the creator.<br> **System API**: This is a system API.|
| disableReason | number | Read only| Reason for disabling WLAN.<br> **System API**: This is a system API.|
| netId | number | Read only| Network ID.<br> **System API**: This is a system API.|
| randomMacType | number | Read only| Random MAC type.<br> **System API**: This is a system API.|
| randomMacAddr | string | Read only| Random MAC address.<br> **System API**: This is a system API.|
| ipType | [IpType](#iptype7) | Read only| IP address type.<br> **System API**: This is a system API.|
| staticIp | [IpConfig](#ipconfig7) | Read only| Static IP address configuration.<br> **System API**: This is a system API.|
| eapConfig<sup>9+</sup> | [WifiEapConfig](#wifieapconfig9) | Read only| EAP configuration.<br> **System API**: This is a system API.|
A
Annie_wang 已提交
301 302 303 304


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

A
Annie_wang 已提交
305
Enumerates the IP address types.
A
Annie_wang 已提交
306

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

A
Annie_wang 已提交
309 310
**System capability**: SystemCapability.Communication.WiFi.STA

A
Annie_wang 已提交
311

A
Annie_wang 已提交
312 313 314 315 316 317 318 319 320 321 322
| Name| Default Value| Description|
| -------- | -------- | -------- |
| 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 已提交
323 324
**System API**: This is a system API.

A
Annie_wang 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337 338
**System capability**: SystemCapability.Communication.WiFi.STA

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| ipAddress | number | Read only| IP address.|
| gateway | number | Read only| Gateway.|
| dnsServers | number[] | Read only| Domain name server (DNS) information.|
| domains | Array&lt;string&gt; | Read only| Domain information.|


## WifiEapConfig<sup>9+</sup>

Represents EAP configuration information.

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

A
Annie_wang 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
**System capability**: SystemCapability.Communication.WiFi.STA

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| eapMethod | [EapMethod](#eapmethod9) | Read only| EAP authentication method.|
| phase2Method | [Phase2Method](#phase2method9) | Read only| Phase 2 authentication method.|
| identity | string | Read only| Identity Information.|
| anonymousIdentity | string | Read only| Anonymous identity.|
| password | string | Read only| Password.|
| caCertAliases | string | Read only| CA certificate alias.|
| caPath | string | Read only| CA certificate path.|
| clientCertAliases | string | Read only| Client certificate alias.|
| altSubjectMatch | string | Read only| A string to match the alternate subject.|
| domainSuffixMatch | string | Read only| A string to match the domain suffix.|
| realm | string | Read only| Realm for the passpoint credential.|
| plmn | string | Read only| Public land mobile network (PLMN) of the passpoint credential provider.|
| eapSubId | number | Read only| Sub-ID of the SIM card.|


## EapMethod<sup>9+</sup>

Enumerates the EAP authentication methods.

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

A
Annie_wang 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
**System capability**: SystemCapability.Communication.WiFi.STA

| Name| Default Value| Description|
| -------- | -------- | -------- |
| EAP_NONE | 0 | Not specified.|
| EAP_PEAP | 1 | PEAP.|
| EAP_TLS | 2 | TLS.|
| EAP_TTLS | 3 | TTLS.|
| EAP_PWD | 4 | Password.|
| EAP_SIM | 5 | SIM.|
| EAP_AKA | 6 | AKA.|
| EAP_AKA_PRIME | 7 | AKA Prime.|
| EAP_UNAUTH_TLS | 8 | UNAUTH TLS.|


## Phase2Method<sup>9+</sup>

Enumerates the Phase 2 authentication methods.

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

A
Annie_wang 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
**System capability**: SystemCapability.Communication.WiFi.STA

| Name| Default Value| Description|
| -------- | -------- | -------- |
| PHASE2_NONE | 0 | Not specified.|
| PHASE2_PAP | 1 | PAP.|
| PHASE2_MSCHAP | 2 | MS-CHAP.|
| PHASE2_MSCHAPV2 | 3 | MS-CHAPv2.|
| PHASE2_GTC | 4 | GTC .|
| PHASE2_SIM | 5 | SIM.|
| PHASE2_AKA | 6 | AKA.|
| PHASE2_AKA_PRIME | 7 | AKA Prime.|


## 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 已提交
406 407

**System API**: This is a system API.
A
Annie_wang 已提交
408 409 410 411 412 413

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

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

**Parameters**
A
Annie_wang 已提交
414

A
Annie_wang 已提交
415 416 417 418
  | **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 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431


## 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 已提交
432

A
Annie_wang 已提交
433 434 435
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
A
Annie_wang 已提交
436 437

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

A
Annie_wang 已提交
439 440 441
  | **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 已提交
442 443 444 445 446 447


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

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

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

A
Annie_wang 已提交
450
**Required permissions**: ohos.permission.SET_WIFI_INFO
A
annie_wangli 已提交
451

A
Annie_wang 已提交
452
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
453

A
Annie_wang 已提交
454
**Parameters**
A
Annie_wang 已提交
455

A
Annie_wang 已提交
456 457 458 459
  | **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 已提交
460 461 462 463 464 465


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

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

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

A
Annie_wang 已提交
468
**Required permissions**: ohos.permission.SET_WIFI_INFO
A
annie_wangli 已提交
469

A
Annie_wang 已提交
470
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
471

A
Annie_wang 已提交
472
**Parameters**
A
Annie_wang 已提交
473

A
Annie_wang 已提交
474 475
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
476
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.|
A
annie_wangli 已提交
477

A
Annie_wang 已提交
478
**Return value**
A
Annie_wang 已提交
479

A
Annie_wang 已提交
480 481 482
  | **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 已提交
483 484 485 486 487 488


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

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

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

A
Annie_wang 已提交
491
**Required permissions**: ohos.permission.SET_WIFI_INFO
W
wusongqing 已提交
492

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

A
Annie_wang 已提交
495
**Parameters**
A
Annie_wang 已提交
496

A
Annie_wang 已提交
497 498
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
499
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.|
A
Annie_wang 已提交
500
  | 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 已提交
501 502 503 504 505 506 507 508 509 510 511 512 513


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

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

Adds the configuration of a candidate 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 已提交
514

A
Annie_wang 已提交
515 516 517
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
A
Annie_wang 已提交
518 519

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

A
Annie_wang 已提交
521 522 523
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;number&gt; | Promise used to return the network configuration ID.|
A
Annie_wang 已提交
524 525 526 527 528 529 530 531 532 533 534 535 536


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

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

Adds the configuration of a candidate network. This API uses an asynchronous callback to return the result.

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

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

**Parameters**
A
Annie_wang 已提交
537

A
Annie_wang 已提交
538 539 540 541
  | **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 已提交
542 543 544 545


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

A
Annie_wang 已提交
546
removeCandidateConfig(networkId: number): Promise&lt;void&gt;
A
Annie_wang 已提交
547 548 549 550 551 552 553 554

Removes the configuration of a candidate 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 已提交
555

A
Annie_wang 已提交
556 557
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
558
| networkId | number | Yes| ID of the network configuration to remove.|
A
Annie_wang 已提交
559 560

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

A
Annie_wang 已提交
562 563 564
  | **Type**| **Description**|
  | -------- | -------- |
  | Promise&lt;void&gt; | Promise used to return the result.|
A
Annie_wang 已提交
565 566 567 568


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

A
Annie_wang 已提交
569
removeCandidateConfig(networkId: number, callback: AsyncCallback&lt;void&gt;): void
A
Annie_wang 已提交
570 571 572 573 574 575 576 577

Removes the configuration of a candidate network. This API uses an asynchronous callback to return the result.

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

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

**Parameters**
A
Annie_wang 已提交
578

A
Annie_wang 已提交
579 580
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
581 582
| networkId | number | Yes| ID of the network configuration to remove.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback invoked to return the result. If the operation is successful, the value of **err** is **0**. If **err** is not **0**, an error has occurred.|
A
Annie_wang 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595


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

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

Obtains candidate network configuration.

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

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

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

A
Annie_wang 已提交
597 598 599
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Candidate network configuration obtained.|
A
Annie_wang 已提交
600 601 602 603


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

A
Annie_wang 已提交
604
connectToCandidateConfig(networkId: number): void
A
Annie_wang 已提交
605 606 607 608 609 610 611 612

Connects to a candidate network.

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

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

**Parameters**
A
Annie_wang 已提交
613

A
Annie_wang 已提交
614 615 616
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | networkId | number | Yes| ID of the candidate network configuration.|
A
Annie_wang 已提交
617 618 619 620 621 622 623


## wifi.connectToNetwork

connectToNetwork(networkId: number): boolean

Connects to the specified network.
A
Annie_wang 已提交
624 625

**System API**: This is a system API.
A
Annie_wang 已提交
626 627 628 629 630 631

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

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

**Parameters**
A
Annie_wang 已提交
632

A
Annie_wang 已提交
633 634 635
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | networkId | number | Yes| Network configuration ID.|
A
Annie_wang 已提交
636 637

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

A
Annie_wang 已提交
639 640 641
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
642 643 644 645 646 647 648 649


## wifi.connectToDevice

connectToDevice(config: WifiDeviceConfig): boolean

Connects to the specified network.

A
Annie_wang 已提交
650 651 652
**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 已提交
653 654 655 656 657

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

**Parameters**
A
Annie_wang 已提交
658

A
Annie_wang 已提交
659 660
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
661
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.|
A
Annie_wang 已提交
662 663

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

A
Annie_wang 已提交
665 666 667
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
668 669 670 671 672 673


## wifi.disconnect

disconnect(): boolean

A
Annie_wang 已提交
674
Disconnects the network.
A
Annie_wang 已提交
675

A
Annie_wang 已提交
676 677 678
**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 已提交
679 680 681 682 683

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

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

A
Annie_wang 已提交
685 686 687
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
Z
zengyawen 已提交
688 689


A
annie_wangli 已提交
690 691 692 693
## wifi.getSignalLevel

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

A
Annie_wang 已提交
694
Obtains the WLAN signal level.
A
annie_wangli 已提交
695

A
Annie_wang 已提交
696
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
697

A
Annie_wang 已提交
698
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
699

A
Annie_wang 已提交
700
**Parameters**
A
Annie_wang 已提交
701

A
Annie_wang 已提交
702 703 704 705
  | **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 已提交
706

A
Annie_wang 已提交
707
**Return value**
A
Annie_wang 已提交
708

A
Annie_wang 已提交
709 710 711
  | **Type**| **Description**|
  | -------- | -------- |
  | number | Signal level obtained. The value range is [0, 4].|
A
annie_wangli 已提交
712 713 714 715 716


## wifi.getLinkedInfo

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

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

A
Annie_wang 已提交
720
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
721

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

A
Annie_wang 已提交
724
**Return value**
A
Annie_wang 已提交
725

A
Annie_wang 已提交
726 727 728
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Promise used to return the WLAN connection information obtained.|
Z
zengyawen 已提交
729 730


A
annie_wangli 已提交
731
## wifi.getLinkedInfo
Z
zengyawen 已提交
732

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

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

A
Annie_wang 已提交
737
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
738

A
Annie_wang 已提交
739
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
740

A
Annie_wang 已提交
741
**Parameters**
A
Annie_wang 已提交
742

A
Annie_wang 已提交
743 744 745
  | 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 已提交
746

A
Annie_wang 已提交
747
**Example**
A
annie_wangli 已提交
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
  ```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 已提交
771 772
**System capability**: SystemCapability.Communication.WiFi.STA

A
annie_wangli 已提交
773 774
| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
775
| ssid | string | Read only| SSID of the hotspot, in UTF-8 format.|
A
annie_wangli 已提交
776
| bssid | string | Read only| BSSID of the hotspot.|
A
Annie_wang 已提交
777
| networkId | number | Read only| Network configuration ID.<br> **System API**: This is a system API.|
A
Annie_wang 已提交
778
| rssi | number | Read only| RSSI of the hotspot, in dBm.|
A
annie_wangli 已提交
779 780 781
| 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.|
A
Annie_wang 已提交
782
| isHidden | boolean | Read only| Whether to hide the WLAN AP.|
A
Annie_wang 已提交
783
| isRestricted | boolean | Read only| Whether to restrict data volume at the WLAN AP.|
A
Annie_wang 已提交
784 785
| chload | number | Read only| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.|
| snr | number | Read only| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.|
A
Annie_wang 已提交
786
| macType<sup>9+</sup> | number | Read only| MAC address type.|
A
annie_wangli 已提交
787 788
| macAddress | string | Read only| MAC address of the device.|
| ipAddress | number | Read only| IP address of the device that sets up the WLAN connection.|
A
Annie_wang 已提交
789
| suppState | [SuppState](#suppstate) | Read only| Supplicant state.<br> **System API**: This is a system API.|
A
Annie_wang 已提交
790
| connState | [ConnState](#connstate) | Read only| WLAN connection state.|
A
annie_wangli 已提交
791 792 793


## ConnState
Z
zengyawen 已提交
794 795 796

Enumerates the WLAN connection states.

A
Annie_wang 已提交
797 798
**System capability**: SystemCapability.Communication.WiFi.STA

A
annie_wangli 已提交
799 800 801 802 803 804 805 806 807
| 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.|
A
Annie_wang 已提交
808
| UNKNOWN | 7 | Failed to set up the WLAN connection.|
Z
zengyawen 已提交
809 810


A
Annie_wang 已提交
811 812 813 814
## SuppState

Enumerates the supplicant states.

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

A
Annie_wang 已提交
817 818 819 820 821 822 823 824 825 826 827 828 829 830
**System capability**: SystemCapability.Communication.WiFi.STA

| Name| Default Value| Description|
| -------- | -------- | -------- |
| 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 已提交
831
| UNINITIALIZED | 10 | The supplicant failed to set up the connection.|
A
Annie_wang 已提交
832 833 834
| INVALID | 11 | Invalid value.|


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

A
annie_wangli 已提交
837 838 839
isConnected(): boolean

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

A
Annie_wang 已提交
841
**Required permissions**: ohos.permission.GET_WIFI_INFO
Z
zengyawen 已提交
842

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

A
Annie_wang 已提交
845
**Return value**
A
Annie_wang 已提交
846

A
Annie_wang 已提交
847 848 849
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|
A
Annie_wang 已提交
850 851 852 853 854 855 856


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

getSupportedFeatures(): number

Obtains the features supported by this device.
A
Annie_wang 已提交
857 858

**System API**: This is a system API.
A
Annie_wang 已提交
859 860 861 862 863 864

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

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

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

A
Annie_wang 已提交
866 867 868
  | **Type**| **Description**|
  | -------- | -------- |
  | number | Feature value. |
A
Annie_wang 已提交
869 870 871 872

**Feature IDs**

| Value| Description|
A
Annie_wang 已提交
873
| -------- | -------- |
A
Annie_wang 已提交
874 875 876 877 878 879 880 881 882 883
| 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 已提交
884 885 886 887 888


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

isFeatureSupported(featureId: number): boolean
Z
zengyawen 已提交
889 890 891

Checks whether the device supports the specified WLAN feature.

A
Annie_wang 已提交
892 893 894 895 896 897
**Required permissions**: ohos.permission.GET_WIFI_INFO

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

**Parameters**

A
Annie_wang 已提交
898

A
Annie_wang 已提交
899 900 901
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | featureId | number | Yes| Feature ID.|
A
Annie_wang 已提交
902 903

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

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


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

getDeviceMacAddress(): string[]

Obtains the device MAC address.
A
Annie_wang 已提交
915 916

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

**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 已提交
923

A
Annie_wang 已提交
924 925 926
  | **Type**| **Description**|
  | -------- | -------- |
  | string[] | MAC address obtained.|
A
Annie_wang 已提交
927 928 929 930 931 932 933 934 935 936 937 938 939


## 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 已提交
940

A
Annie_wang 已提交
941 942 943
  | **Type**| **Description**|
  | -------- | -------- |
  | [IpInfo](#ipinfo7) | IP information obtained.|
A
Annie_wang 已提交
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973


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

Represents IP information.

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

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| 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.|


## 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 已提交
974

A
Annie_wang 已提交
975 976 977
  | **Type**| **Description**|
  | -------- | -------- |
  | string | Country code obtained.|
A
Annie_wang 已提交
978 979 980 981 982 983 984


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

reassociate(): boolean

Re-associates with the network.
A
Annie_wang 已提交
985 986

**System API**: This is a system API.
A
Annie_wang 已提交
987 988 989 990 991 992

**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 已提交
993

A
Annie_wang 已提交
994 995 996
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
997 998 999 1000 1001 1002 1003


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

reconnect(): boolean

Reconnects to the network.
A
Annie_wang 已提交
1004 1005

**System API**: This is a system API.
A
Annie_wang 已提交
1006 1007 1008 1009 1010 1011

**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 已提交
1012

A
Annie_wang 已提交
1013 1014 1015
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1016 1017 1018 1019 1020 1021 1022


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

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

Obtains network configuration.
A
Annie_wang 已提交
1023 1024

**System API**: This is a system API.
A
Annie_wang 已提交
1025 1026 1027 1028 1029 1030

**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 已提交
1031

A
Annie_wang 已提交
1032 1033 1034
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.|
A
Annie_wang 已提交
1035 1036 1037 1038


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

A
Annie_wang 已提交
1039
updateNetwork(config: WifiDeviceConfig): number
A
Annie_wang 已提交
1040 1041

Updates network configuration.
A
Annie_wang 已提交
1042 1043

**System API**: This is a system API.
A
Annie_wang 已提交
1044 1045 1046 1047 1048 1049

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

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

**Parameters**
A
Annie_wang 已提交
1050

A
Annie_wang 已提交
1051 1052
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1053
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.|
A
Annie_wang 已提交
1054 1055

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

A
Annie_wang 已提交
1057 1058 1059
  | **Type**| **Description**|
  | -------- | -------- |
  | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.|
A
Annie_wang 已提交
1060 1061 1062 1063 1064 1065 1066


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

disableNetwork(netId: number): boolean

Disables network configuration.
A
Annie_wang 已提交
1067 1068

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

**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 已提交
1075

A
Annie_wang 已提交
1076 1077 1078
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | netId | number | Yes| ID of the network configuration to disable.|
A
Annie_wang 已提交
1079 1080

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

A
Annie_wang 已提交
1082 1083 1084
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1085 1086 1087 1088 1089 1090 1091


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

removeAllNetwork(): boolean

Removes the configuration of all networks.
A
Annie_wang 已提交
1092 1093

**System API**: This is a system API.
A
Annie_wang 已提交
1094 1095 1096 1097 1098 1099

**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 已提交
1100

A
Annie_wang 已提交
1101 1102 1103
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1104 1105 1106 1107 1108 1109


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

removeDevice(id: number): boolean

A
Annie_wang 已提交
1110
Removes the specified network configuration.
A
Annie_wang 已提交
1111 1112

**System API**: This is a system API.
A
Annie_wang 已提交
1113 1114 1115 1116 1117 1118

**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 已提交
1119

A
Annie_wang 已提交
1120 1121
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1122
| id | number | Yes| ID of the network configuration to remove.|
A
Annie_wang 已提交
1123 1124

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

A
Annie_wang 已提交
1126 1127 1128
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1129 1130 1131 1132 1133 1134 1135


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

enableHotspot(): boolean

Enables this hotspot.
A
Annie_wang 已提交
1136 1137

**System API**: This is a system API.
A
Annie_wang 已提交
1138 1139 1140 1141 1142 1143

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

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

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

A
Annie_wang 已提交
1145 1146 1147
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1148 1149 1150 1151 1152 1153 1154


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

disableHotspot(): boolean

Disables this hotspot.
A
Annie_wang 已提交
1155 1156

**System API**: This is a system API.
A
Annie_wang 已提交
1157 1158 1159 1160 1161 1162

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

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

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

A
Annie_wang 已提交
1164 1165 1166
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1167 1168 1169 1170 1171 1172 1173


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

isHotspotDualBandSupported(): boolean

Checks whether the hotspot supports dual band.
A
Annie_wang 已提交
1174 1175

**System API**: This is a system API.
A
Annie_wang 已提交
1176 1177 1178 1179 1180 1181

**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 已提交
1182

A
Annie_wang 已提交
1183 1184 1185
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
A
Annie_wang 已提交
1186 1187 1188 1189 1190


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

isHotspotActive(): boolean
A
annie_wangli 已提交
1191

A
Annie_wang 已提交
1192
Checks whether this hotspot is active.
A
Annie_wang 已提交
1193 1194

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

A
Annie_wang 已提交
1196
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1197

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

A
Annie_wang 已提交
1200
**Return value**
A
Annie_wang 已提交
1201

A
Annie_wang 已提交
1202 1203 1204
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.|
A
Annie_wang 已提交
1205

A
annie_wangli 已提交
1206

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

A
Annie_wang 已提交
1209
setHotspotConfig(config: HotspotConfig): boolean
A
annie_wangli 已提交
1210

A
Annie_wang 已提交
1211
Sets hotspot configuration.
A
Annie_wang 已提交
1212 1213

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

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

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

A
Annie_wang 已提交
1219
**Parameters**
A
Annie_wang 已提交
1220

A
Annie_wang 已提交
1221 1222 1223
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [HotspotConfig](#hotspotconfig7) | Yes| Hotspot configuration to set.|
A
annie_wangli 已提交
1224

A
Annie_wang 已提交
1225
**Return value**
A
Annie_wang 已提交
1226

A
Annie_wang 已提交
1227 1228 1229
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1230 1231


A
Annie_wang 已提交
1232
## HotspotConfig<sup>7+</sup>
A
annie_wangli 已提交
1233

A
Annie_wang 已提交
1234 1235
Represents the hotspot configuration.

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

A
Annie_wang 已提交
1238
**System capability**: SystemCapability.Communication.WiFi.AP.Core
A
annie_wangli 已提交
1239 1240 1241

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1242
| ssid | string | Read only| SSID of the hotspot, in UTF-8 format.|
A
Annie_wang 已提交
1243 1244
| securityType | [WifiSecurityType](#wifisecuritytype) | Read only| Security type.|
| band | number | Read only| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.|
A
Annie_wang 已提交
1245
| preSharedKey | string | Read only| PSK of the hotspot.|
A
Annie_wang 已提交
1246
| maxConn | number | Read only| Maximum number of connections allowed.|
A
annie_wangli 已提交
1247 1248


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

A
Annie_wang 已提交
1251
getHotspotConfig(): HotspotConfig
A
annie_wangli 已提交
1252

A
Annie_wang 已提交
1253
obtains hotspot configuration.
A
Annie_wang 已提交
1254 1255

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

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

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

A
Annie_wang 已提交
1261
**Return value**
A
Annie_wang 已提交
1262

A
Annie_wang 已提交
1263 1264 1265
  | **Type**| **Description**|
  | -------- | -------- |
  | [HotspotConfig](#hotspotconfig7) | Hotspot configuration obtained.|
A
annie_wangli 已提交
1266 1267


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

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

A
Annie_wang 已提交
1272
Obtains information about the connected stations.
A
Annie_wang 已提交
1273 1274

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

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

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

A
Annie_wang 已提交
1280
**Return value**
A
Annie_wang 已提交
1281

A
Annie_wang 已提交
1282 1283 1284
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | Connected stations obtained.|
A
Annie_wang 已提交
1285 1286 1287 1288 1289 1290


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

Represents the station information.

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

A
Annie_wang 已提交
1293 1294 1295 1296 1297 1298 1299
**System capability**: SystemCapability.Communication.WiFi.AP.Core

| **Name**| **Type**| **Readable/Writable**| **Description**|
| -------- | -------- | -------- | -------- |
| name | string | Read only| Device name.|
| macAddress | string | Read only| MAC address.|
| ipAddress | string | Read only| IP address.|
A
annie_wangli 已提交
1300 1301 1302 1303


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

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

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

A
Annie_wang 已提交
1308
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1309

A
Annie_wang 已提交
1310
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1311

A
Annie_wang 已提交
1312
**Return value**
A
Annie_wang 已提交
1313

A
Annie_wang 已提交
1314 1315 1316
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Promise used to return the P2P link information obtained.|
A
Annie_wang 已提交
1317

A
annie_wangli 已提交
1318 1319 1320 1321


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

A
Annie_wang 已提交
1322 1323 1324
Represents the P2P link information.

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1325 1326 1327

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1328 1329 1330
| connectState | [P2pConnectState](#p2pconnectstate8) | Read only| P2P connection state.|
| isGroupOwner | boolean | Read only| Whether the device is the group owner.|
| groupOwnerAddr | string | Read only| MAC address of the group.
A
annie_wangli 已提交
1331 1332 1333 1334 1335 1336


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

Enumerates the P2P connection states.

A
Annie_wang 已提交
1337 1338
**System capability**: SystemCapability.Communication.WiFi.P2P

A
annie_wangli 已提交
1339 1340
| Name| Default Value| Description|
| -------- | -------- | -------- |
A
Annie_wang 已提交
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
| 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 已提交
1356

A
Annie_wang 已提交
1357 1358 1359
  | 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 已提交
1360 1361 1362 1363 1364 1365


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

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

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

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

A
Annie_wang 已提交
1370
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1371

A
Annie_wang 已提交
1372
**Return value**
A
Annie_wang 已提交
1373

A
Annie_wang 已提交
1374 1375 1376
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt; | Promise used to return the group information obtained.|
A
annie_wangli 已提交
1377 1378 1379 1380 1381 1382


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

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

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

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

A
Annie_wang 已提交
1387
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1388

A
Annie_wang 已提交
1389
**Parameters**
A
Annie_wang 已提交
1390

A
Annie_wang 已提交
1391 1392 1393
  | 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 已提交
1394 1395


A
Annie_wang 已提交
1396 1397 1398
## wifi.getP2pPeerDevices<sup>8+</sup>

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

A
Annie_wang 已提交
1400
Obtains the peer device list in the P2P connection. This API uses a promise to return the result.
A
Annie_wang 已提交
1401 1402 1403 1404 1405 1406

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

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

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

A
Annie_wang 已提交
1408 1409 1410
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Promise used to return the peer device list.|
A
Annie_wang 已提交
1411 1412


A
Annie_wang 已提交
1413
## wifi.getP2pPeerDevices<sup>8+</sup>
A
Annie_wang 已提交
1414

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

A
Annie_wang 已提交
1417
Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1418 1419 1420 1421

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

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

A
Annie_wang 已提交
1423
**Parameters**
A
Annie_wang 已提交
1424

A
Annie_wang 已提交
1425 1426 1427
  | 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 已提交
1428 1429 1430 1431 1432 1433


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

Represents the P2P device information.

A
Annie_wang 已提交
1434 1435
**System capability**: SystemCapability.Communication.WiFi.P2P

A
annie_wangli 已提交
1436 1437 1438 1439 1440
| 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.|
A
Annie_wang 已提交
1441
| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus8) | Read only| Device status.|
A
Annie_wang 已提交
1442
| groupCapabilitys | number | Read only| Group capabilities.|
A
annie_wangli 已提交
1443 1444


A
Annie_wang 已提交
1445
## P2pDeviceStatus<sup>8+</sup>
A
annie_wangli 已提交
1446

A
Annie_wang 已提交
1447
Enumerates the P2P device states.
A
annie_wangli 已提交
1448

A
Annie_wang 已提交
1449
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1450

A
Annie_wang 已提交
1451 1452 1453 1454 1455 1456 1457
| Name| Default Value| Description|
| -------- | -------- | -------- |
| CONNECTED | 0 | Connected.|
| INVITED | 1 | Invited.|
| FAILED | 2 | Failed.|
| AVAILABLE | 3 | Available.|
| UNAVAILABLE | 4 | Unavailable.|
A
annie_wangli 已提交
1458

A
Annie_wang 已提交
1459 1460 1461 1462 1463

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

getP2pLocalDevice(): Promise&lt;WifiP2pDevice&gt;

A
Annie_wang 已提交
1464
Obtains the local device information in the P2P connection. This API uses a promise to return the result.
A
Annie_wang 已提交
1465 1466 1467 1468 1469 1470

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

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

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

A
Annie_wang 已提交
1472 1473 1474
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | Promise used to return the local device information obtained.|
A
Annie_wang 已提交
1475 1476


A
Annie_wang 已提交
1477
## wifi.getP2pLocalDevice<sup>9+</sup>
A
Annie_wang 已提交
1478 1479 1480

getP2pLocalDevice(callback: AsyncCallback&lt;WifiP2pDevice&gt;): void

A
Annie_wang 已提交
1481
Obtains the local device information in the P2P connection. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
1482 1483 1484 1485

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

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

A
Annie_wang 已提交
1487
**Parameters**
A
Annie_wang 已提交
1488

A
Annie_wang 已提交
1489 1490 1491
  | 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 local device information obtained. If **err** is not **0**, an error has occurred.|
A
Annie_wang 已提交
1492

A
annie_wangli 已提交
1493 1494 1495

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

A
Annie_wang 已提交
1496
createGroup(config: WifiP2PConfig): boolean
A
annie_wangli 已提交
1497 1498 1499

Creates a P2P group.

A
Annie_wang 已提交
1500 1501 1502
**Required permissions**: ohos.permission.GET_WIFI_INFO

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

A
Annie_wang 已提交
1504
**Parameters**
A
annie_wangli 已提交
1505

A
Annie_wang 已提交
1506 1507 1508
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| Group configuration.|
A
annie_wangli 已提交
1509

A
Annie_wang 已提交
1510
**Return value**
A
Annie_wang 已提交
1511

A
Annie_wang 已提交
1512 1513 1514
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1515

A
annie_wangli 已提交
1516 1517 1518

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

A
Annie_wang 已提交
1519
Represents P2P group configuration.
A
annie_wangli 已提交
1520

A
Annie_wang 已提交
1521 1522
**System capability**: SystemCapability.Communication.WiFi.P2P

A
annie_wangli 已提交
1523 1524 1525
| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| deviceAddress | string | Read only| Device address.|
A
Annie_wang 已提交
1526 1527
| netId | number | Read only| Network ID. The value **-1** indicates a temporary group, and **-2** indicates a persistent group.|
| passphrase | string | Read only| Passphrase of the group.|
A
annie_wangli 已提交
1528
| groupName | string | Read only| Name of the group.|
A
Annie_wang 已提交
1529
| goBand | [GroupOwnerBand](#groupownerband8) | Read only| Frequency band of the group.|
A
annie_wangli 已提交
1530 1531 1532 1533


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

A
Annie_wang 已提交
1534 1535 1536
Enumerates the P2P group frequency bands.

**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1537 1538 1539

| Name| Default Value| Description|
| -------- | -------- | -------- |
A
Annie_wang 已提交
1540 1541 1542 1543
| GO_BAND_AUTO | 0 | Auto.|
| GO_BAND_2GHZ | 1 | 2 GHz.|
| GO_BAND_5GHZ | 2 | 5 GHz.|

A
annie_wangli 已提交
1544 1545 1546

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

A
Annie_wang 已提交
1547
removeGroup(): boolean
A
annie_wangli 已提交
1548

A
Annie_wang 已提交
1549
Removes this P2P group.
A
annie_wangli 已提交
1550

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

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

A
Annie_wang 已提交
1555
**Return value**
A
Annie_wang 已提交
1556

A
Annie_wang 已提交
1557 1558 1559
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1560 1561 1562 1563


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

A
Annie_wang 已提交
1564
p2pConnect(config: WifiP2PConfig): boolean
A
annie_wangli 已提交
1565 1566 1567

Sets up a P2P connection.

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

A
Annie_wang 已提交
1570 1571 1572
**System capability**: SystemCapability.Communication.WiFi.P2P

**Parameters**
A
annie_wangli 已提交
1573

A
Annie_wang 已提交
1574

A
Annie_wang 已提交
1575 1576 1577
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiP2PConfig](#wifip2pconfig8) | Yes| P2P group configuration.|
A
annie_wangli 已提交
1578

A
Annie_wang 已提交
1579
**Return value**
A
Annie_wang 已提交
1580

A
Annie_wang 已提交
1581 1582 1583
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1584 1585


A
Annie_wang 已提交
1586
**Example**
A
annie_wangli 已提交
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
  ```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 已提交
1633
  var recvP2pPersistentGroupChangeFunc = () => {
A
annie_wangli 已提交
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654
      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 已提交
1655
p2pCancelConnect(): boolean
A
annie_wangli 已提交
1656 1657 1658

Cancels this P2P connection.

A
Annie_wang 已提交
1659
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1660

A
Annie_wang 已提交
1661
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1662

A
Annie_wang 已提交
1663
**Return value**
A
Annie_wang 已提交
1664

A
Annie_wang 已提交
1665 1666 1667
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1668 1669 1670 1671


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

A
Annie_wang 已提交
1672
startDiscoverDevices(): boolean
A
annie_wangli 已提交
1673 1674 1675

Starts to discover devices.

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

A
Annie_wang 已提交
1678
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1679

A
Annie_wang 已提交
1680
**Return value**
A
Annie_wang 已提交
1681

A
Annie_wang 已提交
1682 1683 1684
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1685 1686 1687 1688


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

A
Annie_wang 已提交
1689
stopDiscoverDevices(): boolean
A
annie_wangli 已提交
1690 1691 1692

Stops discovering devices.

A
Annie_wang 已提交
1693
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1694

A
Annie_wang 已提交
1695
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
1696

A
Annie_wang 已提交
1697
**Return value**
A
Annie_wang 已提交
1698

A
Annie_wang 已提交
1699 1700 1701
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1702 1703 1704 1705 1706 1707 1708 1709


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

deletePersistentGroup(netId: number): boolean

Deletes a persistent group.

A
Annie_wang 已提交
1710 1711 1712
**System API**: This is a system API.

**Required permissions**: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
A
Annie_wang 已提交
1713 1714 1715 1716 1717

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

**Parameters**

A
Annie_wang 已提交
1718

A
Annie_wang 已提交
1719 1720 1721
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | netId | number | Yes| ID of the group to delete.|
A
Annie_wang 已提交
1722 1723

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

A
Annie_wang 已提交
1725 1726 1727
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
Annie_wang 已提交
1728 1729 1730 1731 1732 1733 1734


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

getP2pGroups(): Promise&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;

Obtains information about all P2P groups. This API uses a promise to return the result.
A
Annie_wang 已提交
1735 1736

**System API**: This is a system API.
A
Annie_wang 已提交
1737 1738 1739 1740 1741 1742

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

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

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

A
Annie_wang 已提交
1744 1745 1746
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt;&nbsp;&gt; | Promise used to return the group information obtained.|
A
Annie_wang 已提交
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773


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

Represents the P2P group information.

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

| Name| Type| Readable/Writable| Description|
| -------- | -------- | -------- | -------- |
| isP2pGo | boolean | Read only| Whether the device is the group owner.|
| ownerInfo | [WifiP2pDevice](#wifip2pdevice8) | Read only| Device information of the group.|
| passphrase | string | Read only| Passphrase 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[]](#wifip2pdevice8) | Read only| List of connected devices.|
| goIpAddress | string | Read only| IP address of the group.|


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

getP2pGroups(callback: AsyncCallback&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;): void

Obtains information about all P2P groups. This API uses an asynchronous callback to return the result.

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

A
Annie_wang 已提交
1776 1777 1778 1779 1780
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION

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

**Parameters**
A
Annie_wang 已提交
1781

A
Annie_wang 已提交
1782 1783 1784
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt;&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 已提交
1785 1786 1787 1788 1789 1790 1791 1792


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

setDeviceName(devName: string): boolean

Sets the device name.

A
Annie_wang 已提交
1793 1794 1795
**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 已提交
1796 1797 1798 1799

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

**Parameters**
A
Annie_wang 已提交
1800

A
Annie_wang 已提交
1801 1802 1803
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | devName | string | Yes| Device name to set.|
A
Annie_wang 已提交
1804 1805

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

A
Annie_wang 已提交
1807 1808 1809
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
A
annie_wangli 已提交
1810 1811 1812 1813 1814


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

on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1815 1816 1817

Registers the WLAN state change events.

A
Annie_wang 已提交
1818
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1819

A
Annie_wang 已提交
1820
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1821

A
Annie_wang 已提交
1822
**Parameters**
A
Annie_wang 已提交
1823

A
Annie_wang 已提交
1824 1825 1826 1827
  | **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 已提交
1828

A
Annie_wang 已提交
1829 1830 1831 1832
**WLAN states** 

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1833 1834 1835 1836
| 0 | Deactivated. |
| 1 | Activated. |
| 2 | Activating. |
| 3 | Deactivating. |
A
annie_wangli 已提交
1837 1838 1839 1840 1841


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

off(type: "wifiStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1842 1843 1844

Unregisters the WLAN state change events.

A
Annie_wang 已提交
1845
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1846

A
Annie_wang 已提交
1847
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1848

A
Annie_wang 已提交
1849
**Parameters**
A
Annie_wang 已提交
1850

A
Annie_wang 已提交
1851 1852 1853
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiStateChange**.|
A
Annie_wang 已提交
1854
  | 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 已提交
1855

A
Annie_wang 已提交
1856
**Example**
A
annie_wangli 已提交
1857 1858 1859 1860 1861 1862 1863
  ```js
  import wifi from '@ohos.wifi';
  
  var recvPowerNotifyFunc = result => {
      console.info("Receive power state change event: " + result);
  }
  
A
Annie_wang 已提交
1864
  // Register an event.
A
Annie_wang 已提交
1865
  wifi.on("wifiStateChange", recvPowerNotifyFunc);
A
annie_wangli 已提交
1866
  
A
Annie_wang 已提交
1867
  // Unregister an event.
A
Annie_wang 已提交
1868
  wifi.off("wifiStateChange", recvPowerNotifyFunc);
A
annie_wangli 已提交
1869 1870 1871 1872 1873 1874
  ```


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

on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1875 1876 1877

Registers the WLAN connection state change events.

A
Annie_wang 已提交
1878
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1879

A
Annie_wang 已提交
1880
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1881

A
Annie_wang 已提交
1882
**Parameters**
A
Annie_wang 已提交
1883

A
Annie_wang 已提交
1884 1885 1886 1887
  | **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 已提交
1888

A
Annie_wang 已提交
1889 1890 1891 1892
**WLAN connection states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1893 1894
| 0 | Disconnected.|
| 1 | Connected.|
A
annie_wangli 已提交
1895 1896 1897 1898 1899


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

off(type: "wifiConnectionChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1900 1901 1902

Unregisters the WLAN connection state change events.

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

A
Annie_wang 已提交
1905
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1906

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

A
Annie_wang 已提交
1909 1910 1911
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
A
Annie_wang 已提交
1912
  | 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 已提交
1913 1914 1915 1916 1917


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

on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1918 1919 1920

Registers the WLAN scan state change events.

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

A
Annie_wang 已提交
1923
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1924

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

A
Annie_wang 已提交
1927 1928 1929 1930
  | **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 已提交
1931

A
Annie_wang 已提交
1932 1933 1934 1935
**WLAN scan states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
1936 1937
| 0 | Scan failed.|
| 1 | Scan successful.|
A
annie_wangli 已提交
1938 1939 1940 1941 1942


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

off(type: "wifiScanStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1943 1944 1945

Unregisters the WLAN scan state change events.

A
Annie_wang 已提交
1946
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1947

A
Annie_wang 已提交
1948
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1949

A
Annie_wang 已提交
1950
**Parameters**
A
annie_wangli 已提交
1951 1952 1953 1954

| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiScanStateChange**.|
A
Annie_wang 已提交
1955
| 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 已提交
1956 1957 1958 1959 1960


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

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

A
Annie_wang 已提交
1962
Registers the RSSI change events.
Z
zengyawen 已提交
1963

A
Annie_wang 已提交
1964
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1965

A
Annie_wang 已提交
1966
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1967

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

A
Annie_wang 已提交
1970 1971 1972 1973
  | **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 已提交
1974 1975 1976 1977 1978


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

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

A
Annie_wang 已提交
1980
Unregisters the RSSI change events.
Z
zengyawen 已提交
1981

A
Annie_wang 已提交
1982
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
1983

A
Annie_wang 已提交
1984
**System capability**: SystemCapability.Communication.WiFi.STA
A
annie_wangli 已提交
1985

A
Annie_wang 已提交
1986
**Parameters**
A
Annie_wang 已提交
1987

A
Annie_wang 已提交
1988 1989 1990
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
A
Annie_wang 已提交
1991
| 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 已提交
1992 1993 1994 1995 1996


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

on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
Z
zengyawen 已提交
1997 1998 1999

Registers the hotspot state change events.

A
Annie_wang 已提交
2000
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2001

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

A
Annie_wang 已提交
2004
**Parameters**
A
Annie_wang 已提交
2005

A
Annie_wang 已提交
2006 2007 2008 2009
  | **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 已提交
2010

A
Annie_wang 已提交
2011 2012 2013 2014
**Hotspot states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
2015 2016 2017 2018
| 0 | Deactivated. |
| 1 | Activated. |
| 2 | Activating. |
| 3 | Deactivating. |
A
annie_wangli 已提交
2019 2020 2021 2022 2023


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

off(type: "hotspotStateChange", callback?: Callback&lt;number&gt;): void
Z
zengyawen 已提交
2024 2025 2026

Unregisters the hotspot state change events.

A
Annie_wang 已提交
2027
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2028

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

A
Annie_wang 已提交
2031
**Parameters**
A
Annie_wang 已提交
2032

A
Annie_wang 已提交
2033 2034 2035
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
A
Annie_wang 已提交
2036
| 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 已提交
2037 2038 2039 2040 2041 2042


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

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

A
Annie_wang 已提交
2043
Registers the P2P state change events.
A
annie_wangli 已提交
2044

A
Annie_wang 已提交
2045
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2046

A
Annie_wang 已提交
2047
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2048

A
Annie_wang 已提交
2049
**Parameters**
A
Annie_wang 已提交
2050

A
Annie_wang 已提交
2051 2052 2053 2054
  | **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 已提交
2055

A
Annie_wang 已提交
2056 2057 2058 2059
**P2P states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
2060 2061 2062 2063 2064
| 1 | Available. |
| 2 | Opening. |
| 3 | Opened. |
| 4 | Closing. |
| 5 | Closed. |
A
annie_wangli 已提交
2065 2066 2067 2068 2069 2070 2071

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

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

Unregisters the P2P state change events.

A
Annie_wang 已提交
2072
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2073

A
Annie_wang 已提交
2074
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2075

A
Annie_wang 已提交
2076
**Parameters**
A
Annie_wang 已提交
2077

A
Annie_wang 已提交
2078 2079 2080
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pStateChange**.|
A
Annie_wang 已提交
2081
| 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 已提交
2082 2083 2084 2085 2086 2087 2088 2089


  ## 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 已提交
2090
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2091

A
Annie_wang 已提交
2092
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2093

A
Annie_wang 已提交
2094
**Parameters**
A
Annie_wang 已提交
2095

A
Annie_wang 已提交
2096 2097 2098 2099
  | **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 已提交
2100 2101 2102 2103 2104 2105 2106 2107


## 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 已提交
2108
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2109

A
Annie_wang 已提交
2110
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2111

A
Annie_wang 已提交
2112
**Parameters**
A
Annie_wang 已提交
2113

A
Annie_wang 已提交
2114 2115 2116
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
A
Annie_wang 已提交
2117
| 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 已提交
2118 2119 2120 2121 2122 2123 2124 2125


## 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 已提交
2126
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
2127

A
Annie_wang 已提交
2128
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2129

A
Annie_wang 已提交
2130
**Parameters**
A
Annie_wang 已提交
2131

A
Annie_wang 已提交
2132 2133 2134 2135
  | **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 已提交
2136 2137 2138 2139 2140 2141 2142 2143


## 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 已提交
2144
**Required permissions**: ohos.permission.LOCATION
A
annie_wangli 已提交
2145

A
Annie_wang 已提交
2146
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2147

A
Annie_wang 已提交
2148
**Parameters**
A
Annie_wang 已提交
2149

A
Annie_wang 已提交
2150 2151 2152
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
A
Annie_wang 已提交
2153
| 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 已提交
2154 2155 2156 2157 2158 2159 2160 2161


## 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 已提交
2162
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION
A
annie_wangli 已提交
2163

A
Annie_wang 已提交
2164
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2165

A
Annie_wang 已提交
2166
**Parameters**
A
Annie_wang 已提交
2167

A
Annie_wang 已提交
2168 2169 2170
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
A
Annie_wang 已提交
2171
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Yes| Callback invoked to return the P2P peer device state.|
A
annie_wangli 已提交
2172 2173 2174 2175 2176 2177 2178 2179


## 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 已提交
2180
**Required permissions**: ohos.permission.LOCATION
A
annie_wangli 已提交
2181

A
Annie_wang 已提交
2182
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2183

A
Annie_wang 已提交
2184
**Parameters**
A
Annie_wang 已提交
2185

A
Annie_wang 已提交
2186 2187 2188
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
A
Annie_wang 已提交
2189
| 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 已提交
2190 2191 2192 2193 2194 2195 2196 2197


## 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 已提交
2198
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2199

A
Annie_wang 已提交
2200
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2201

A
Annie_wang 已提交
2202
**Parameters**
A
Annie_wang 已提交
2203

A
Annie_wang 已提交
2204 2205 2206 2207
  | **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 已提交
2208 2209 2210 2211 2212 2213 2214 2215


## 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 已提交
2216
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2217

A
Annie_wang 已提交
2218
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2219

A
Annie_wang 已提交
2220
**Parameters**
A
Annie_wang 已提交
2221

A
Annie_wang 已提交
2222 2223 2224
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
A
Annie_wang 已提交
2225
| 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 已提交
2226 2227 2228 2229 2230 2231


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

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

A
Annie_wang 已提交
2232
Registers the P2P device discovery state change events.
A
annie_wangli 已提交
2233

A
Annie_wang 已提交
2234
**Required permissions**: ohos.permission.GET_WIFI_INFO
A
annie_wangli 已提交
2235

A
Annie_wang 已提交
2236
**System capability**: SystemCapability.Communication.WiFi.P2P
A
annie_wangli 已提交
2237

A
Annie_wang 已提交
2238
**Parameters**
A
Annie_wang 已提交
2239

A
Annie_wang 已提交
2240 2241 2242 2243
  | **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 已提交
2244

A
Annie_wang 已提交
2245 2246 2247 2248
**P2P discovered device states**

| **Value**| **Description**|
| -------- | -------- |
A
Annie_wang 已提交
2249 2250
| 0 | Initial state.|
| 1 | Discovered.|
A
annie_wangli 已提交
2251 2252 2253 2254 2255 2256


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

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

A
Annie_wang 已提交
2257
Unregisters the P2P device discovery state change events.
A
annie_wangli 已提交
2258

A
Annie_wang 已提交
2259
**Required permissions**: ohos.permission.GET_WIFI_INFO
W
wusongqing 已提交
2260

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

A
Annie_wang 已提交
2263
**Parameters**
A
Annie_wang 已提交
2264

A
Annie_wang 已提交
2265 2266 2267
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
A
Annie_wang 已提交
2268
| 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.|