js-apis-wifi.md 72.0 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 31 32 33 34 35 36 37
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 50 51
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


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 253 254 255 256 257 258 259
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; | Scan result obtained.|


## 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 305 306


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

Enumerate the IP address types.

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 419 420 421 422 423 424 425 426 427 428 429 430 431
  | **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.|


## 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 436 437
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|

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


## 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 518 519
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|

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

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


## 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 542 543 544 545
  | **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.|


## 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
  | **Type**| **Description**|
  | -------- | -------- |
A
Annie_wang 已提交
564
  | 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 600 601 602 603
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Candidate network configuration obtained.|


## 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 617 618 619 620 621 622 623
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | networkId | number | Yes| ID of the candidate network configuration.|


## 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 636 637
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | networkId | number | Yes| Network configuration ID.|

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

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


## 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 661 662 663
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.|

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

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


## 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 850 851 852 853 854 855 856
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|


## 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
  | **Type**| **Description**|
  | -------- | -------- |
A
Annie_wang 已提交
868
  | 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 902 903
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
  | featureId | number | Yes| Feature ID.|

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

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


## 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 927 928 929 930 931 932 933 934 935 936 937 938 939
  | **Type**| **Description**|
  | -------- | -------- |
  | string[] | MAC address obtained.|


## 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 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
  | **Type**| **Description**|
  | -------- | -------- |
  | [IpInfo](#ipinfo7) | IP information obtained.|


## 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 978 979 980 981 982 983 984
  | **Type**| **Description**|
  | -------- | -------- |
  | string | Country code obtained.|


## 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 997 998 999 1000 1001 1002 1003
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 1016 1017 1018 1019 1020 1021 1022
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 1035 1036 1037 1038
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.|


## 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 1053 1054 1055
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.|

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

A
Annie_wang 已提交
1057 1058
  | **Type**| **Description**|
  | -------- | -------- |
A
Annie_wang 已提交
1059
  | 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 1079 1080
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | netId | number | Yes| ID of the network configuration to disable.|

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

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


## 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 1104 1105 1106 1107 1108 1109
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 1122 1123 1124
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | id | number | Yes| ID of the network configuration to remove.|

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

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


## 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 1148 1149 1150 1151 1152 1153 1154
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 1167 1168 1169 1170 1171 1172 1173
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 1186 1187 1188 1189 1190
  | **Type**| **Description**|
  | -------- | -------- |
  | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|


## 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 1285 1286 1287 1288 1289 1290
  | **Type**| **Description**|
  | -------- | -------- |
  | &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | Connected stations obtained.|


## 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 1317
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Promise used to return the P2P link information obtained.|

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 1492
  | 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_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 1515
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

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
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1577
  | 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 1702 1703 1704 1705 1706 1707 1708 1709
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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
  | **Name**| **Type**| Mandatory| **Description**|
  | -------- | -------- | -------- | -------- |
A
Annie_wang 已提交
1721
  | 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 1728 1729 1730 1731 1732 1733 1734
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|


## 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 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
  | Type| Description|
  | -------- | -------- |
  | Promise&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt;&nbsp;&gt; | Promise used to return the group information obtained.|


## 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 1785 1786 1787 1788 1789 1790 1791 1792
  | 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.|


## 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 1804 1805
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | devName | string | Yes| Device name to set.|

**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 1833 1834 1835 1836
**WLAN states** 

| **Value**| **Description**|
| -------- | -------- |
| 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 1854
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiStateChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1855

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


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

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

Registers the WLAN connection state change events.

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

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

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

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

A
Annie_wang 已提交
1890 1891 1892 1893 1894 1895
**WLAN connection states**

| **Value**| **Description**|
| -------- | -------- |
| 0 | Disconnected|
| 1 | Connected|
A
annie_wangli 已提交
1896 1897 1898 1899 1900


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

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

Unregisters the WLAN connection state change events.

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

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

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

A
Annie_wang 已提交
1910 1911 1912 1913
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1914 1915 1916 1917 1918


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

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

Registers the WLAN scan state change events.

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

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

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

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

A
Annie_wang 已提交
1933 1934 1935 1936 1937 1938
**WLAN scan states**

| **Value**| **Description**|
| -------- | -------- |
| 0 | Scan failed|
| 1 | Scan successful|
A
annie_wangli 已提交
1939 1940 1941 1942 1943


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

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

Unregisters the WLAN scan state change events.

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

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

A
Annie_wang 已提交
1951
**Parameters**
A
annie_wangli 已提交
1952 1953 1954 1955 1956 1957 1958 1959 1960 1961

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


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

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

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

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

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

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

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


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

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

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

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

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

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

A
Annie_wang 已提交
1989 1990 1991 1992
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **wifiRssiChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
1993 1994 1995 1996 1997


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

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

Registers the hotspot state change events.

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

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

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

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

A
Annie_wang 已提交
2012 2013 2014 2015 2016 2017 2018 2019
**Hotspot states**

| **Value**| **Description**|
| -------- | -------- |
| 0 | Deactivated|
| 1 | Activated|
| 2 | Activating|
| 3 | Deactivating|
A
annie_wangli 已提交
2020 2021 2022 2023 2024


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

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

Unregisters the hotspot state change events.

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

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

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

A
Annie_wang 已提交
2034 2035 2036 2037
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **hotspotStateChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the hotspot state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2038 2039 2040 2041 2042 2043


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

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

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

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

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

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

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

A
Annie_wang 已提交
2057 2058 2059 2060 2061 2062 2063 2064 2065
**P2P states**

| **Value**| **Description**|
| -------- | -------- |
| 1 | Available|
| 2 | Opening|
| 3 | Opened|
| 4 | Closing|
| 5 | Closed|
A
annie_wangli 已提交
2066 2067 2068 2069 2070 2071 2072

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

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

Unregisters the P2P state change events.

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

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

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

A
Annie_wang 已提交
2079 2080 2081 2082
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pStateChange**.|
  | callback | Callback&lt;number&gt; | No| Callback used to return the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2083 2084 2085 2086 2087 2088 2089 2090


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

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

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

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


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

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

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

A
Annie_wang 已提交
2115 2116 2117 2118
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | No| Callback used to return the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2119 2120 2121 2122 2123 2124 2125 2126


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

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

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

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


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

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

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

A
Annie_wang 已提交
2151 2152 2153 2154
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | No| Callback used to return the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2155 2156 2157 2158 2159 2160 2161 2162


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

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

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

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


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

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

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

A
Annie_wang 已提交
2187 2188 2189 2190
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
  | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | No| Callback used to return the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2191 2192 2193 2194 2195 2196 2197 2198


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

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

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

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


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

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

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

A
Annie_wang 已提交
2223 2224 2225 2226
  | **Name**| **Type**| **Mandatory**| **Description**|
  | -------- | -------- | -------- | -------- |
  | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
  | callback | Callback&lt;void&gt; | No| Callback used to return the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
A
annie_wangli 已提交
2227 2228 2229 2230 2231 2232


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

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

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

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

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

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

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

A
Annie_wang 已提交
2246 2247 2248 2249 2250 2251
**P2P discovered device states**

| **Value**| **Description**|
| -------- | -------- |
| 0 | Initial state|
| 1 | Discovered|
A
annie_wangli 已提交
2252 2253 2254 2255 2256 2257


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

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

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

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

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

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

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