提交 3f8df44d 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 3e766c2e
...@@ -31,6 +31,17 @@ Enables WLAN. ...@@ -31,6 +31,17 @@ Enables WLAN.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.enableWifi();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableWifi ## wifi.disableWifi
...@@ -50,6 +61,18 @@ Disables WLAN. ...@@ -50,6 +61,18 @@ Disables WLAN.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.disableWifi();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isWifiActive ## wifi.isWifiActive
...@@ -67,6 +90,18 @@ Checks whether WLAN is enabled. ...@@ -67,6 +90,18 @@ Checks whether WLAN is enabled.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let isActivate = wifi.isActivate();
console.info("isActivate:" + isActivate);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.scan ## wifi.scan
...@@ -84,6 +119,17 @@ Starts a scan for WLAN. ...@@ -84,6 +119,17 @@ Starts a scan for WLAN.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.scan();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getScanInfos ## wifi.getScanInfos
...@@ -119,10 +165,11 @@ Obtains the scan result. This API uses an asynchronous callback to return the re ...@@ -119,10 +165,11 @@ Obtains the scan result. This API uses an asynchronous callback to return the re
| 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.| | 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.|
**Example** **Example**
```js
import wifi from '@ohos.wifi';
wifi.getScanInfos((err, result) => { ```js
import wifi from '@ohos.wifi';
wifi.getScanInfos((err, result) => {
if (err) { if (err) {
console.error("get scan info error"); console.error("get scan info error");
return; return;
...@@ -141,9 +188,9 @@ Obtains the scan result. This API uses an asynchronous callback to return the re ...@@ -141,9 +188,9 @@ Obtains the scan result. This API uses an asynchronous callback to return the re
console.info("channelWidth: " + result[i].channelWidth); console.info("channelWidth: " + result[i].channelWidth);
console.info("timestamp: " + result[i].timestamp); console.info("timestamp: " + result[i].timestamp);
} }
}); });
wifi.getScanInfos().then(result => { wifi.getScanInfos().then(result => {
var len = Object.keys(result).length; var len = Object.keys(result).length;
console.log("wifi received scan info: " + len); console.log("wifi received scan info: " + len);
for (var i = 0; i < len; ++i) { for (var i = 0; i < len; ++i) {
...@@ -157,8 +204,8 @@ Obtains the scan result. This API uses an asynchronous callback to return the re ...@@ -157,8 +204,8 @@ Obtains the scan result. This API uses an asynchronous callback to return the re
console.info("channelWidth: " + result[i].channelWidth); console.info("channelWidth: " + result[i].channelWidth);
console.info("timestamp: " + result[i].timestamp); console.info("timestamp: " + result[i].timestamp);
} }
}); });
``` ```
## WifiScanInfo ## WifiScanInfo
...@@ -238,6 +285,25 @@ Adds network configuration. This API uses a promise to return the result. ...@@ -238,6 +285,25 @@ Adds network configuration. This API uses a promise to return the result.
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the WLAN configuration ID. If **-1** is returned, the network configuration fails to be added.| | Promise&lt;number&gt; | Promise used to return the WLAN configuration ID. If **-1** is returned, the network configuration fails to be added.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifi.addDeviceConfig(config).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiDeviceConfig ## WifiDeviceConfig
Represents the WLAN configuration. Represents the WLAN configuration.
...@@ -252,13 +318,13 @@ Represents the WLAN configuration. ...@@ -252,13 +318,13 @@ Represents the WLAN configuration.
| preSharedKey | string | Yes| No| PSK of the hotspot.| | preSharedKey | string | Yes| No| PSK of the hotspot.|
| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.| | isHiddenSsid | boolean | Yes| No| Whether the network is hidden.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| | securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.|
| creatorUid | number | Yes| No| ID of the creator.<br> **System API**: This is a system API.| | creatorUid | number | Yes| No| ID of the creator.<br>**System API**: This is a system API.|
| disableReason | number | Yes| No| Reason for disabling WLAN.<br> **System API**: This is a system API.| | disableReason | number | Yes| No| Reason for disabling WLAN.<br>**System API**: This is a system API.|
| netId | number | Yes| No| Network ID.<br> **System API**: This is a system API.| | netId | number | Yes| No| Network ID.<br>**System API**: This is a system API.|
| randomMacType | number | Yes| No| Random MAC type.<br> **System API**: This is a system API.| | randomMacType | number | Yes| No| Random MAC type.<br>**System API**: This is a system API.|
| randomMacAddr | string | Yes| No| Random MAC address.<br> **System API**: This is a system API.| | randomMacAddr | string | Yes| No| Random MAC address.<br>**System API**: This is a system API.|
| ipType | [IpType](#iptype7) | Yes| No| IP address type.<br> **System API**: This is a system API.| | ipType | [IpType](#iptype7) | Yes| No| IP address type.<br>**System API**: This is a system API.|
| staticIp | [IpConfig](#ipconfig7) | Yes| No| Static IP address configuration.<br> **System API**: This is a system API.| | staticIp | [IpConfig](#ipconfig7) | Yes| No| Static IP address configuration.<br>**System API**: This is a system API.|
## IpType<sup>7+</sup> ## IpType<sup>7+</sup>
...@@ -312,7 +378,24 @@ Adds network configuration. This API uses an asynchronous callback to return the ...@@ -312,7 +378,24 @@ Adds network configuration. This API uses an asynchronous callback to return the
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifi.addDeviceConfig(config,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.addUntrustedConfig<sup>7+</sup> ## wifi.addUntrustedConfig<sup>7+</sup>
addUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt; addUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;
...@@ -335,6 +418,23 @@ Adds the configuration of an untrusted network. This API uses a promise to retur ...@@ -335,6 +418,23 @@ Adds the configuration of an untrusted network. This API uses a promise to retur
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifi.addUntrustedConfig(config).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.addUntrustedConfig<sup>7+</sup> ## wifi.addUntrustedConfig<sup>7+</sup>
...@@ -353,6 +453,23 @@ Adds the configuration of an untrusted network. This API uses an asynchronous ca ...@@ -353,6 +453,23 @@ Adds the configuration of an untrusted network. This API uses an asynchronous ca
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifi.addUntrustedConfig(config,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeUntrustedConfig<sup>7+</sup> ## wifi.removeUntrustedConfig<sup>7+</sup>
...@@ -376,6 +493,21 @@ Removes the configuration of an untrusted network. This API uses a promise to re ...@@ -376,6 +493,21 @@ Removes the configuration of an untrusted network. This API uses a promise to re
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let networkId = 0;
wifi.removeUntrustedConfig(networkId).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeUntrustedConfig<sup>7+</sup> ## wifi.removeUntrustedConfig<sup>7+</sup>
...@@ -394,6 +526,19 @@ Removes the configuration of an untrusted network. This API uses an asynchronous ...@@ -394,6 +526,19 @@ Removes the configuration of an untrusted network. This API uses an asynchronous
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to remove.| | 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let networkId = 0;
wifi.removeUntrustedConfig(networkId,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.connectToNetwork ## wifi.connectToNetwork
...@@ -419,6 +564,18 @@ Connects to the specified network. ...@@ -419,6 +564,18 @@ Connects to the specified network.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let networkId = 0;
wifi.connectToNetwork(networkId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.connectToDevice ## wifi.connectToDevice
...@@ -445,6 +602,22 @@ Connects to the specified network. ...@@ -445,6 +602,22 @@ Connects to the specified network.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
wifi.connectToDevice(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disconnect ## wifi.disconnect
...@@ -465,6 +638,16 @@ Disconnects the network. ...@@ -465,6 +638,16 @@ Disconnects the network.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.disconnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getSignalLevel ## wifi.getSignalLevel
...@@ -489,6 +672,20 @@ Obtains the WLAN signal level. ...@@ -489,6 +672,20 @@ Obtains the WLAN signal level.
| -------- | -------- | | -------- | -------- |
| number | Signal level obtained. The value range is [0, 4].| | number | Signal level obtained. The value range is [0, 4].|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let rssi = 0;
let band = 0;
let level = wifi.getSignalLevel(rssi,band);
console.info("lelvel:" + JSON.stringify(lelvel));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getLinkedInfo ## wifi.getLinkedInfo
...@@ -524,23 +721,23 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r ...@@ -524,23 +721,23 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r
| 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.| | 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.|
**Example** **Example**
```js ```js
import wifi from '@ohos.wifi'; import wifi from '@ohos.wifi';
wifi.getLinkedInfo((err, data) => { wifi.getLinkedInfo((err, data) => {
if (err) { if (err) {
console.error("get linked info error"); console.error("get linked info error");
return; return;
} }
console.info("get wifi linked info: " + JSON.stringify(data)); console.info("get wifi linked info: " + JSON.stringify(data));
}); });
wifi.getLinkedInfo().then(data => { wifi.getLinkedInfo().then(data => {
console.info("get wifi linked info: " + JSON.stringify(data)); console.info("get wifi linked info: " + JSON.stringify(data));
}).catch(error => { }).catch(error => {
console.info("get linked info error"); console.info("get linked info error");
}); });
``` ```
## WifiLinkedInfo ## WifiLinkedInfo
...@@ -553,18 +750,18 @@ Represents the WLAN connection information. ...@@ -553,18 +750,18 @@ Represents the WLAN connection information.
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| | ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.|
| bssid | string | Yes| No| BSSID of the hotspot.| | bssid | string | Yes| No| BSSID of the hotspot.|
| networkId | number | Yes| No| Network configuration ID.<br> **System API**: This is a system API.| | networkId | number | Yes| No| Network configuration ID.<br>**System API**: This is a system API.|
| rssi | number | Yes| No| RSSI of the hotspot, in dBm.| | rssi | number | Yes| No| RSSI of the hotspot, in dBm.|
| band | number | Yes| No| Frequency band of the WLAN AP.| | band | number | Yes| No| Frequency band of the WLAN AP.|
| linkSpeed | number | Yes| No| Speed of the WLAN AP.| | linkSpeed | number | Yes| No| Speed of the WLAN AP.|
| frequency | number | Yes| No| Frequency of the WLAN AP.| | frequency | number | Yes| No| Frequency of the WLAN AP.|
| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.| | isHidden | boolean | Yes| No| Whether to hide the WLAN AP.|
| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.| | isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.|
| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.| | chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br>**System API**: This is a system API.|
| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.| | snr | number | Yes| No| Signal-to-noise ratio (SNR).<br>**System API**: This is a system API.|
| macAddress | string | Yes| No| MAC address of the device.| | macAddress | string | Yes| No| MAC address of the device.|
| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.| | ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.|
| suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br> **System API**: This is a system API.| | suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br>**System API**: This is a system API.|
| connState | [ConnState](#connstate) | Yes| No| WLAN connection state.| | connState | [ConnState](#connstate) | Yes| No| WLAN connection state.|
...@@ -684,6 +881,19 @@ Checks whether the device supports the specified WLAN feature. ...@@ -684,6 +881,19 @@ Checks whether the device supports the specified WLAN feature.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let featureId = 0;
let ret = wifi.isFeatureSupported(featureId);
console.info("isFeatureSupported:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getDeviceMacAddress<sup>7+</sup> ## wifi.getDeviceMacAddress<sup>7+</sup>
...@@ -703,6 +913,18 @@ Obtains the device MAC address. ...@@ -703,6 +913,18 @@ Obtains the device MAC address.
| -------- | -------- | | -------- | -------- |
| string[] | MAC address obtained.| | string[] | MAC address obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let ret = wifi.getDeviceMacAddress();
console.info("deviceMacAddress:" + JSON.stringify(ret));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getIpInfo<sup>7+</sup> ## wifi.getIpInfo<sup>7+</sup>
...@@ -720,6 +942,17 @@ Obtains IP information. ...@@ -720,6 +942,17 @@ Obtains IP information.
| -------- | -------- | | -------- | -------- |
| [IpInfo](#ipinfo7) | IP information obtained.| | [IpInfo](#ipinfo7) | IP information obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let info = wifi.getIpInfo();
console.info("info:" + JSON.stringify(info));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## IpInfo<sup>7+</sup> ## IpInfo<sup>7+</sup>
...@@ -754,6 +987,17 @@ Obtains the country code. ...@@ -754,6 +987,17 @@ Obtains the country code.
| -------- | -------- | | -------- | -------- |
| string | Country code obtained.| | string | Country code obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let code = wifi.getCountryCode();
console.info("code:" + code);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.reassociate<sup>7+</sup> ## wifi.reassociate<sup>7+</sup>
...@@ -773,6 +1017,16 @@ Re-associates with the network. ...@@ -773,6 +1017,16 @@ Re-associates with the network.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.reassociate();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.reconnect<sup>7+</sup> ## wifi.reconnect<sup>7+</sup>
...@@ -792,6 +1046,16 @@ Reconnects to the network. ...@@ -792,6 +1046,16 @@ Reconnects to the network.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.reconnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getDeviceConfigs<sup>7+</sup> ## wifi.getDeviceConfigs<sup>7+</sup>
...@@ -811,6 +1075,17 @@ Obtains network configuration. ...@@ -811,6 +1075,17 @@ Obtains network configuration.
| -------- | -------- | | -------- | -------- |
| &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.| | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let configs = wifi.getDeviceConfigs();
console.info("configs:" + JSON.stringify(configs));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.updateNetwork<sup>7+</sup> ## wifi.updateNetwork<sup>7+</sup>
...@@ -836,6 +1111,22 @@ Updates network configuration. ...@@ -836,6 +1111,22 @@ Updates network configuration.
| -------- | -------- | | -------- | -------- |
| number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
let ret = wifi.updateNetwork(config);
console.error("ret:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableNetwork<sup>7+</sup> ## wifi.disableNetwork<sup>7+</sup>
...@@ -861,6 +1152,17 @@ Disables network configuration. ...@@ -861,6 +1152,17 @@ Disables network configuration.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let netId = 0;
wifi.disableNetwork(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeAllNetwork<sup>7+</sup> ## wifi.removeAllNetwork<sup>7+</sup>
...@@ -880,6 +1182,16 @@ Removes the configuration of all networks. ...@@ -880,6 +1182,16 @@ Removes the configuration of all networks.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.removeAllNetwork();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeDevice<sup>7+</sup> ## wifi.removeDevice<sup>7+</sup>
...@@ -905,6 +1217,17 @@ Removes the specified network configuration. ...@@ -905,6 +1217,17 @@ Removes the specified network configuration.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let id = 0;
wifi.removeDevice(id);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.enableHotspot<sup>7+</sup> ## wifi.enableHotspot<sup>7+</sup>
...@@ -924,6 +1247,16 @@ Enables this hotspot. ...@@ -924,6 +1247,16 @@ Enables this hotspot.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.enableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableHotspot<sup>7+</sup> ## wifi.disableHotspot<sup>7+</sup>
...@@ -943,6 +1276,16 @@ Disables this hotspot. ...@@ -943,6 +1276,16 @@ Disables this hotspot.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifiManager';
try {
wifiManager.disableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isHotspotDualBandSupported<sup>7+</sup> ## wifi.isHotspotDualBandSupported<sup>7+</sup>
...@@ -962,6 +1305,17 @@ Checks whether the hotspot supports dual band. ...@@ -962,6 +1305,17 @@ Checks whether the hotspot supports dual band.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let ret = wifi.isHotspotDualBandSupported();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isHotspotActive<sup>7+</sup> ## wifi.isHotspotActive<sup>7+</sup>
...@@ -981,6 +1335,17 @@ Checks whether this hotspot is active. ...@@ -981,6 +1335,17 @@ Checks whether this hotspot is active.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let ret = wifi.isHotspotActive();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.setHotspotConfig<sup>7+</sup> ## wifi.setHotspotConfig<sup>7+</sup>
...@@ -1006,6 +1371,25 @@ Sets hotspot configuration. ...@@ -1006,6 +1371,25 @@ Sets hotspot configuration.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
ssid: "****",
securityType: 3,
band: 0,
channel: 0,
preSharedKey: "****",
maxConn: 0
}
let ret = wifi.setHotspotConfig();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## HotspotConfig<sup>7+</sup> ## HotspotConfig<sup>7+</sup>
...@@ -1042,6 +1426,17 @@ obtains hotspot configuration. ...@@ -1042,6 +1426,17 @@ obtains hotspot configuration.
| -------- | -------- | | -------- | -------- |
| [HotspotConfig](#hotspotconfig7) | Hotspot configuration obtained.| | [HotspotConfig](#hotspotconfig7) | Hotspot configuration obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = wifi.getHotspotConfig();
console.info("result:" + JSON.stringify(config));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getStations<sup>7+</sup> ## wifi.getStations<sup>7+</sup>
...@@ -1061,6 +1456,17 @@ Obtains information about the connected stations. ...@@ -1061,6 +1456,17 @@ Obtains information about the connected stations.
| -------- | -------- | | -------- | -------- |
| &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | Connected stations obtained.| | &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | Connected stations obtained.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let stations = wifi.getStations();
console.info("result:" + JSON.stringify(stations));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## StationInfo<sup>7+</sup> ## StationInfo<sup>7+</sup>
...@@ -1136,6 +1542,22 @@ Obtains P2P link information. This API uses an asynchronous callback to return t ...@@ -1136,6 +1542,22 @@ Obtains P2P link information. This API uses an asynchronous callback to return t
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifi';
wifi.getP2pLinkedInfo((err, data) => {
if (err) {
console.error("get p2p linked info error");
return;
}
console.info("get wifi p2p linked info: " + JSON.stringify(data));
});
wifi.getP2pLinkedInfo().then(data => {
console.info("get wifi p2p linked info: " + JSON.stringify(data));
});
```
## wifi.getCurrentGroup<sup>8+</sup> ## wifi.getCurrentGroup<sup>8+</sup>
...@@ -1170,6 +1592,22 @@ Obtains the current P2P group information. This API uses an asynchronous callbac ...@@ -1170,6 +1592,22 @@ Obtains the current P2P group information. This API uses an asynchronous callbac
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifi';
wifi.getCurrentGroup((err, data) => {
if (err) {
console.error("get current P2P group error");
return;
}
console.info("get current P2P group: " + JSON.stringify(data));
});
wifi.getCurrentGroup().then(data => {
console.info("get current P2P group: " + JSON.stringify(data));
});
```
## wifi.getP2pPeerDevices<sup>8+</sup> ## wifi.getP2pPeerDevices<sup>8+</sup>
...@@ -1204,6 +1642,22 @@ Obtains the peer device list in the P2P connection. This API uses an asynchronou ...@@ -1204,6 +1642,22 @@ Obtains the peer device list in the P2P connection. This API uses an asynchronou
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| 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.| | 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.|
**Example**
```js
import wifi from '@ohos.wifiManager';
wifi.getP2pPeerDevices((err, data) => {
if (err) {
console.error("get P2P peer devices error");
return;
}
console.info("get P2P peer devices: " + JSON.stringify(data));
});
wifi.getP2pPeerDevices().then(data => {
console.info("get P2P peer devices: " + JSON.stringify(data));
});
```
## WifiP2pDevice<sup>8+</sup> ## WifiP2pDevice<sup>8+</sup>
...@@ -1257,6 +1711,24 @@ Creates a P2P group. ...@@ -1257,6 +1711,24 @@ Creates a P2P group.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let config = {
deviceAddress: "****",
netId: 0,
passphrase: "*****",
groupName: "****",
goBand: 0
}
wifi.createGroup(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiP2PConfig<sup>8+</sup> ## WifiP2PConfig<sup>8+</sup>
...@@ -1302,6 +1774,16 @@ Removes this P2P group. ...@@ -1302,6 +1774,16 @@ Removes this P2P group.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.removeGroup();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.p2pConnect<sup>8+</sup> ## wifi.p2pConnect<sup>8+</sup>
...@@ -1328,10 +1810,10 @@ Sets up a P2P connection. ...@@ -1328,10 +1810,10 @@ Sets up a P2P connection.
**Example** **Example**
```js ```js
import wifi from '@ohos.wifi'; import wifi from '@ohos.wifi';
var recvP2pConnectionChangeFunc = result => { var recvP2pConnectionChangeFunc = result => {
console.info("p2p connection change receive event: " + JSON.stringify(result)); console.info("p2p connection change receive event: " + JSON.stringify(result));
wifi.getP2pLinkedInfo((err, data) => { wifi.getP2pLinkedInfo((err, data) => {
if (err) { if (err) {
...@@ -1340,15 +1822,15 @@ Sets up a P2P connection. ...@@ -1340,15 +1822,15 @@ Sets up a P2P connection.
} }
console.info("get getP2pLinkedInfo: " + JSON.stringify(data)); console.info("get getP2pLinkedInfo: " + JSON.stringify(data));
}); });
} }
wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc); wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
var recvP2pDeviceChangeFunc = result => { var recvP2pDeviceChangeFunc = result => {
console.info("p2p device change receive event: " + JSON.stringify(result)); console.info("p2p device change receive event: " + JSON.stringify(result));
} }
wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc); wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
var recvP2pPeerDeviceChangeFunc = result => { var recvP2pPeerDeviceChangeFunc = result => {
console.info("p2p peer device change receive event: " + JSON.stringify(result)); console.info("p2p peer device change receive event: " + JSON.stringify(result));
wifi.getP2pPeerDevices((err, data) => { wifi.getP2pPeerDevices((err, data) => {
if (err) { if (err) {
...@@ -1371,10 +1853,10 @@ Sets up a P2P connection. ...@@ -1371,10 +1853,10 @@ Sets up a P2P connection.
} }
} }
}); });
} }
wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc); wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
var recvP2pPersistentGroupChangeFunc = () => { var recvP2pPersistentGroupChangeFunc = () => {
console.info("p2p persistent group change receive event"); console.info("p2p persistent group change receive event");
wifi.getCurrentGroup((err, data) => { wifi.getCurrentGroup((err, data) => {
...@@ -1384,15 +1866,15 @@ Sets up a P2P connection. ...@@ -1384,15 +1866,15 @@ Sets up a P2P connection.
} }
console.info("get current group: " + JSON.stringify(data)); console.info("get current group: " + JSON.stringify(data));
}); });
} }
wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc); wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000);
setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
console.info("start discover devices -> " + wifi.startDiscoverDevices()); console.info("start discover devices -> " + wifi.startDiscoverDevices());
``` ```
## wifi.p2pCancelConnect<sup>8+</sup> ## wifi.p2pCancelConnect<sup>8+</sup>
...@@ -1410,6 +1892,16 @@ Cancels this P2P connection. ...@@ -1410,6 +1892,16 @@ Cancels this P2P connection.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.p2pCancelConnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.startDiscoverDevices<sup>8+</sup> ## wifi.startDiscoverDevices<sup>8+</sup>
...@@ -1427,6 +1919,16 @@ Starts to discover devices. ...@@ -1427,6 +1919,16 @@ Starts to discover devices.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.startDiscoverDevices();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.stopDiscoverDevices<sup>8+</sup> ## wifi.stopDiscoverDevices<sup>8+</sup>
...@@ -1444,6 +1946,16 @@ Stops discovering devices. ...@@ -1444,6 +1946,16 @@ Stops discovering devices.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
wifi.stopDiscoverDevices();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.deletePersistentGroup<sup>8+</sup> ## wifi.deletePersistentGroup<sup>8+</sup>
...@@ -1470,6 +1982,17 @@ Deletes a persistent group. ...@@ -1470,6 +1982,17 @@ Deletes a persistent group.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let netId = 0;
wifi.deletePersistentGroup(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiP2pGroupInfo<sup>8+</sup> ## WifiP2pGroupInfo<sup>8+</sup>
...@@ -1514,6 +2037,17 @@ Sets the device name. ...@@ -1514,6 +2037,17 @@ Sets the device name.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
import wifi from '@ohos.wifi';
try {
let name = "****";
wifi.setDeviceName(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.on('wifiStateChange')<sup>7+</sup> ## wifi.on('wifiStateChange')<sup>7+</sup>
...@@ -1560,19 +2094,19 @@ Unregisters the WLAN state change events. ...@@ -1560,19 +2094,19 @@ Unregisters the WLAN state change events.
| callback | Callback&lt;number&gt; | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example** **Example**
```js ```js
import wifi from '@ohos.wifi'; import wifi from '@ohos.wifi';
var recvPowerNotifyFunc = result => { var recvPowerNotifyFunc = result => {
console.info("Receive power state change event: " + result); console.info("Receive power state change event: " + result);
} }
// Register an event. // Register an event.
wifi.on("wifiStateChange", recvPowerNotifyFunc); wifi.on("wifiStateChange", recvPowerNotifyFunc);
// Unregister an event. // Unregister an event.
wifi.off("wifiStateChange", recvPowerNotifyFunc); wifi.off("wifiStateChange", recvPowerNotifyFunc);
``` ```
## wifi.on('wifiConnectionChange')<sup>7+</sup> ## wifi.on('wifiConnectionChange')<sup>7+</sup>
...@@ -1617,6 +2151,20 @@ Unregisters the WLAN connection state change events. ...@@ -1617,6 +2151,20 @@ Unregisters the WLAN connection state change events.
| type | string | Yes| Event type. The value is **wifiConnectionChange**.| | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvWifiConnectionChangeFunc = result => {
console.info("Receive wifi connection change event: " + result);
}
// Register an event.
wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc);
// Unregister an event.
wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc);
```
## wifi.on('wifiScanStateChange')<sup>7+</sup> ## wifi.on('wifiScanStateChange')<sup>7+</sup>
...@@ -1660,6 +2208,20 @@ Unregisters the WLAN scan state change events. ...@@ -1660,6 +2208,20 @@ Unregisters the WLAN scan state change events.
| type | string | Yes| Event type. The value is **wifiScanStateChange**.| | type | string | Yes| Event type. The value is **wifiScanStateChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the WLAN scan state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvWifiScanStateChangeFunc = result => {
console.info("Receive Wifi scan state change event: " + result);
}
// Register an event.
wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc);
// Unregister an event.
wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc);
```
## wifi.on('wifiRssiChange')<sup>7+</sup> ## wifi.on('wifiRssiChange')<sup>7+</sup>
...@@ -1696,7 +2258,20 @@ Unregisters the RSSI change events. ...@@ -1696,7 +2258,20 @@ Unregisters the RSSI change events.
| type | string | Yes| Event type. The value is **wifiRssiChange**.| | type | string | Yes| Event type. The value is **wifiRssiChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvWifiRssiChangeFunc = result => {
console.info("Receive wifi rssi change event: " + result);
}
// Register an event.
wifi.on("wifiRssiChange", recvWifiRssiChangeFunc);
// Unregister an event.
wifi.off("wifiRssiChange", recvWifiRssiChangeFunc);
```
## wifi.on('hotspotStateChange')<sup>7+</sup> ## wifi.on('hotspotStateChange')<sup>7+</sup>
on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
...@@ -1723,6 +2298,20 @@ Registers the hotspot state change events. ...@@ -1723,6 +2298,20 @@ Registers the hotspot state change events.
| 2 | Activating| | 2 | Activating|
| 3 | Deactivating| | 3 | Deactivating|
**Example**
```js
import wifi from '@ohos.wifi';
var recvHotspotStateChangeFunc = result => {
console.info("Receive hotspot state change event: " + result);
}
// Register an event.
wifi.on("hotspotStateChange", recvHotspotStateChangeFunc);
// Unregister an event.
wifi.off("hotspotStateChange", recvHotspotStateChangeFunc);
```
## wifi.off('hotspotStateChange')<sup>7+</sup> ## wifi.off('hotspotStateChange')<sup>7+</sup>
...@@ -1786,6 +2375,20 @@ Unregisters the P2P state change events. ...@@ -1786,6 +2375,20 @@ Unregisters the P2P state change events.
| type | string | Yes| Event type. The value is **p2pStateChange**.| | type | string | Yes| Event type. The value is **p2pStateChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pStateChangeFunc = result => {
console.info("Receive p2p state change event: " + result);
}
// Register an event.
wifi.on("p2pStateChange", recvP2pStateChangeFunc);
// Unregister an event.
wifi.off("p2pStateChange", recvP2pStateChangeFunc);
```
## wifi.on('p2pConnectionChange')<sup>8+</sup> ## wifi.on('p2pConnectionChange')<sup>8+</sup>
...@@ -1822,6 +2425,20 @@ Unregisters the P2P connection state change events. ...@@ -1822,6 +2425,20 @@ Unregisters the P2P connection state change events.
| type | string | Yes| Event type. The value is **p2pConnectionChange**.| | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pConnectionChangeFunc = result => {
console.info("Receive p2p connection change event: " + result);
}
// Register an event.
wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
// Unregister an event.
wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);
```
## wifi.on('p2pDeviceChange')<sup>8+</sup> ## wifi.on('p2pDeviceChange')<sup>8+</sup>
...@@ -1858,6 +2475,20 @@ Unregisters the P2P device state change events. ...@@ -1858,6 +2475,20 @@ Unregisters the P2P device state change events.
| type | string | Yes| Event type. The value is **p2pDeviceChange**.| | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pDeviceChangeFunc = result => {
console.info("Receive recv p2p device change event: " + result);
}
// Register an event.
wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
// Unregister an event.
wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);
```
## wifi.on('p2pPeerDeviceChange')<sup>8+</sup> ## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>
...@@ -1894,6 +2525,20 @@ Unregisters the P2P peer device state change events. ...@@ -1894,6 +2525,20 @@ Unregisters the P2P peer device state change events.
| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pPeerDeviceChangeFunc = result => {
console.info("Receive recv p2p peer device change event: " + result);
}
// Register an event.
wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
// Unregister an event.
wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
```
## wifi.on('p2pPersistentGroupChange')<sup>8+</sup> ## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>
...@@ -1930,6 +2575,21 @@ Unregisters the P2P persistent group state change events. ...@@ -1930,6 +2575,21 @@ Unregisters the P2P persistent group state change events.
| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| callback | Callback&lt;void&gt; | No| Callback for the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;void&gt; | No| Callback for the P2P persistent group state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pPersistentGroupChangeFunc = result => {
console.info("Receive recv p2p persistent group change event: " + result);
}
// Register an event.
wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
// Unregister an event.
wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
```
## wifi.on('p2pDiscoveryChange')<sup>8+</sup> ## wifi.on('p2pDiscoveryChange')<sup>8+</sup>
...@@ -1972,3 +2632,18 @@ Unregisters the P2P device discovery state change events. ...@@ -1972,3 +2632,18 @@ Unregisters the P2P device discovery state change events.
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvP2pDiscoveryChangeFunc = result => {
console.info("Receive recv p2p discovery change event: " + result);
}
// Register an event.
wifi.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
// Unregister an event.
wifi.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
```
...@@ -26,18 +26,29 @@ Enables WLAN. ...@@ -26,18 +26,29 @@ Enables WLAN.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.enableWifi();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableWifi<sup>9+</sup> ## wifi.disableWifi<sup>9+</sup>
...@@ -53,18 +64,30 @@ Disables WLAN. ...@@ -53,18 +64,30 @@ Disables WLAN.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.disableWifi();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isWifiActive<sup>9+</sup> ## wifi.isWifiActive<sup>9+</sup>
isWifiActive(): boolean isWifiActive(): boolean
...@@ -77,132 +100,119 @@ Checks whether WLAN is enabled. ...@@ -77,132 +100,119 @@ Checks whether WLAN is enabled.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.| | boolean | Returns **true** if WLAN is enabled; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let isActivate = wifiManager.isActivate();
console.info("isActivate:" + isActivate);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.scan<sup>9+</sup> ## wifi.scan<sup>9+</sup>
scan(): void scan(): void
Starts a scan for WLAN. Starts a scan for WLAN.
**Required permissions**: **ohos.permission.SET_WIFI_INFO** and **ohos.permission.LOCATION** **Required permissions**: ohos.permission.SET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.getScanResults<sup>9+</sup> **Example**
getScanResults(): Promise&lt;Array&lt;WifiScanInfo&gt;&gt;
Obtains the scan result. This API uses a promise to return the result.
**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**
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the hotspots detected.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). ```
import wifi from '@ohos.wifiManager';
| **Type**| **Description**| try {
| -------- | -------- | wifiManager.scan();
| 2501000 | Operation failed.| }catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getScanResults<sup>9+</sup> ## wifi.getScanInfoList<sup>9+</sup>
getScanResults(callback: AsyncCallback&lt;Array&lt;WifiScanInfo&gt;&gt;): void getScanInfoList(): Array&lt;WifiScanInfo&gt;;
Obtains the scan result. This API uses an asynchronous callback to return the result. Obtains the scan result.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_PEERS_MAC (or ohos.permission.LOCATION) **Required permissions**: ohos.permission.GET_WIFI_INFO and (ohos.permission.GET_WIFI_PEERS_MAC or (ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION))
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
**Parameters** **Return value**
| **Name**| **Type**| **Mandatory**| **Description**| | **Type**| **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.| | Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; | Returns the hotspots detected.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example** **Example**
```js
import wifi from '@ohos.wifi';
wifi.getScanInfos((err, result) => { ```
if (err) { import wifi from '@ohos.wifiManager';
console.error("get scan info error");
return;
}
var len = Object.keys(result).length; try {
let scanInfoList = wifiManager.getScanInfoList();
console.info("scanInfoList:" + JSON.stringify(scanInfoList));
let len = Object.keys(result).length;
console.log("wifi received scan info: " + len); console.log("wifi received scan info: " + len);
if(len > 0){
for (var i = 0; i < len; ++i) { for (var i = 0; i < len; ++i) {
console.info("ssid: " + result[i].ssid); console.info("ssid: " + scanInfoList[i].ssid);
console.info("bssid: " + result[i].bssid); console.info("bssid: " + scanInfoList[i].bssid);
console.info("capabilities: " + result[i].capabilities); console.info("capabilities: " + scanInfoList[i].capabilities);
console.info("securityType: " + result[i].securityType); console.info("securityType: " + scanInfoList[i].securityType);
console.info("rssi: " + result[i].rssi); console.info("rssi: " + scanInfoList[i].rssi);
console.info("band: " + result[i].band); console.info("band: " + scanInfoList[i].band);
console.info("frequency: " + result[i].frequency); console.info("frequency: " + scanInfoList[i].frequency);
console.info("channelWidth: " + result[i].channelWidth); console.info("channelWidth: " + scanInfoList[i].channelWidth);
console.info("timestamp: " + result[i].timestamp); console.info("timestamp: " + scanInfoList[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);
} }
}); }catch(error){
``` console.error("failed:" + JSON.stringify(error));
}
```
## WifiScanInfo<sup>9+</sup> ## WifiScanInfo<sup>9+</sup>
...@@ -248,59 +258,65 @@ Enumerates the WLAN security types. ...@@ -248,59 +258,65 @@ Enumerates the WLAN security types.
| WIFI_SEC_TYPE_WAPI_PSK<sup>9+</sup> | 9 | WAPI-PSK.| | WIFI_SEC_TYPE_WAPI_PSK<sup>9+</sup> | 9 | WAPI-PSK.|
## WifiInfoElem<sup>9+</sup> ## WifiBandType<sup>10+</sup>
Represents a WLAN information element. Enumerates the Wi-Fi band types.
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
| **Name**| **Value**| **Description**|
| -------- | -------- | -------- |
| WIFI_BAND_NONE | 0 | Invalid band type|
| WIFI_BAND_2G | 1 | 2.4 GHz|
| WIFI_BAND_5G | 2 | 5 GHz|
| WIFI_BAND_6G | 3 | 6 GHz|
| WIFI_BAND_60G | 4 | 60 GHz|
| **Name**| **Type**| **Readable**| **Writable**| **Description**| ## WifiStandard<sup>10+</sup>
| -------- | -------- | -------- | -------- | -------- |
| eid | number | Yes| No| ID of the information element.|
| content | Uint8Array | Yes| No| Content of the information element.|
## WifiChannelWidth<sup>9+</sup>
Enumerates the WLAN channel widths. Enumerates the Wi-Fi standards.
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
| **Name**| **Value**| **Description**| | **Name**| **Value**| **Description**|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| WIDTH_20MHZ | 0 | 20 MHz.| | WIFI_STANDARD_UNDEFINED | 0 | Invalid Wi-Fi standard|
| WIDTH_40MHZ | 1 | 40 MHz.| | WIFI_STANDARD_11A | 1 | 802.11a|
| WIDTH_80MHZ | 2 | 80 MHz.| | WIFI_STANDARD_11B | 2 | 802.11b|
| WIDTH_160MHZ | 3 | 160 MHz.| | WIFI_STANDARD_11G | 3 | 802.11g|
| WIDTH_80MHZ_PLUS | 4 | 80 MHz<sup>+</sup>.| | WIFI_STANDARD_11N | 4 | 802.11n|
| WIDTH_INVALID | 5 | Invalid value.| | WIFI_STANDARD_11AC | 5 | 802.11ac|
| WIFI_STANDARD_11AX | 6 | 802.11ax|
| WIFI_STANDARD_11AD | 7 | 802.11ad|
## WifiInfoElem<sup>9+</sup>
## wifi.getScanResultsSync<sup>9+</sup> Represents a WLAN information element.
getScanResultsSync(): &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; **System capability**: SystemCapability.Communication.WiFi.STA
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) | **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- |
| eid | number | Yes| No| ID of the information element.|
| content | Uint8Array | Yes| No| Content of the information element.|
**System capability**: SystemCapability.Communication.WiFi.STA
**Return value** ## WifiChannelWidth<sup>9+</sup>
| **Type**| **Description**| Enumerates the WLAN channel widths.
| -------- | -------- |
| &nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt; | Scan result obtained.|
**Error codes** **System capability**: SystemCapability.Communication.WiFi.STA
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Name**| **Value**| **Description**|
| -------- | -------- | | -------- | -------- | -------- |
| 2501000 | Operation failed.| | 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.addDeviceConfig<sup>9+</sup> ## wifi.addDeviceConfig<sup>9+</sup>
...@@ -316,24 +332,43 @@ Adds network configuration. This API uses a promise to return the result. ...@@ -316,24 +332,43 @@ Adds network configuration. This API uses a promise to return the result.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.| | Promise&lt;number&gt; | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifiManager.addDeviceConfig(config).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiDeviceConfig<sup>9+</sup> ## WifiDeviceConfig<sup>9+</sup>
Represents the WLAN configuration. Represents the WLAN configuration.
...@@ -348,14 +383,14 @@ Represents the WLAN configuration. ...@@ -348,14 +383,14 @@ Represents the WLAN configuration.
| preSharedKey | string | Yes| No| PSK of the hotspot.| | preSharedKey | string | Yes| No| PSK of the hotspot.|
| isHiddenSsid | boolean | Yes| No| Whether the network is hidden.| | isHiddenSsid | boolean | Yes| No| Whether the network is hidden.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| | securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.|
| creatorUid | number | Yes| No| ID of the creator.<br> **System API**: This is a system API.| | creatorUid | number | Yes| No| ID of the creator.<br>**System API**: This is a system API.|
| disableReason | number | Yes| No| Reason for disabling WLAN.<br> **System API**: This is a system API.| | disableReason | number | Yes| No| Reason for disabling WLAN.<br>**System API**: This is a system API.|
| netId | number | Yes| No| Network ID.<br> **System API**: This is a system API.| | netId | number | Yes| No| Network ID.<br>**System API**: This is a system API.|
| randomMacType | number | Yes| No| Random MAC type.<br> **System API**: This is a system API.| | randomMacType | number | Yes| No| Random MAC type.<br>**System API**: This is a system API.|
| randomMacAddr | string | Yes| No| Random MAC address.<br> **System API**: This is a system API.| | randomMacAddr | string | Yes| No| Random MAC address.<br>**System API**: This is a system API.|
| ipType | [IpType](#iptype9) | Yes| No| IP address type.<br> **System API**: This is a system API.| | ipType | [IpType](#iptype9) | Yes| No| IP address type.<br>**System API**: This is a system API.|
| staticIp | [IpConfig](#ipconfig9) | Yes| No| Static IP address configuration.<br> **System API**: This is a system API.| | staticIp | [IpConfig](#ipconfig9) | Yes| No| Static IP address configuration.<br>**System API**: This is a system API.|
| eapConfig<sup>9+</sup> | [WifiEapConfig](#wifieapconfig9) | Yes| No| EAP configuration.<br> **System API**: This is a system API.| | eapConfig<sup>9+</sup> | [WifiEapConfig](#wifieapconfig9) | Yes| No| EAP configuration.<br>**System API**: This is a system API.|
## IpType<sup>9+</sup> ## IpType<sup>9+</sup>
...@@ -473,19 +508,38 @@ Adds network configuration. This API uses an asynchronous callback to return the ...@@ -473,19 +508,38 @@ Adds network configuration. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | 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.| | 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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifiManager.addDeviceConfig(config,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.addCandidateConfig<sup>9+</sup> ## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig): Promise&lt;number&gt; addCandidateConfig(config: WifiDeviceConfig): Promise&lt;number&gt;
...@@ -498,24 +552,42 @@ Adds the configuration of a candidate network. This API uses a promise to return ...@@ -498,24 +552,42 @@ Adds the configuration of a candidate network. This API uses a promise to return
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the network configuration ID.| | Promise&lt;number&gt; | Promise used to return the network configuration ID.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
`````
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifiManager.addCandidateConfig(config).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
`````
## wifi.addCandidateConfig<sup>9+</sup> ## wifi.addCandidateConfig<sup>9+</sup>
addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;number&gt;): void addCandidateConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;number&gt;): void
...@@ -528,19 +600,37 @@ Adds the configuration of a candidate network. This API uses an asynchronous cal ...@@ -528,19 +600,37 @@ Adds the configuration of a candidate network. This API uses an asynchronous cal
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.| | 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.| | 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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
`````
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 0
}
wifiManager.addCandidateConfig(config,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
`````
## wifi.removeCandidateConfig<sup>9+</sup> ## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number): Promise&lt;void&gt; removeCandidateConfig(networkId: number): Promise&lt;void&gt;
...@@ -553,24 +643,39 @@ Removes the configuration of a candidate network. This API uses a promise to ret ...@@ -553,24 +643,39 @@ Removes the configuration of a candidate network. This API uses a promise to ret
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| networkId | number | Yes| ID of the network configuration to remove.| | networkId | number | Yes| ID of the network configuration to remove.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise used to return the result.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let networkId = 0;
wifiManager.removeCandidateConfig(networkId).then(result => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeCandidateConfig<sup>9+</sup> ## wifi.removeCandidateConfig<sup>9+</sup>
removeCandidateConfig(networkId: number, callback: AsyncCallback&lt;void&gt;): void removeCandidateConfig(networkId: number, callback: AsyncCallback&lt;void&gt;): void
...@@ -583,48 +688,84 @@ Removes the configuration of a candidate network. This API uses an asynchronous ...@@ -583,48 +688,84 @@ Removes the configuration of a candidate network. This API uses an asynchronous
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| networkId | number | Yes| ID of the network configuration to remove.| | 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.| | 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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let networkId = 0;
wifiManager.removeCandidateConfig(networkId,(error,result) => {
console.info("result:" + JSON.stringify(result));
});
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getCandidateConfigs<sup>9+</sup> ## wifi.getCandidateConfigs<sup>9+</sup>
getCandidateConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; getCandidateConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt;
Obtains candidate network configuration. Obtains candidate network configuration.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Candidate network configuration obtained.| | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Candidate network configuration obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
`````
import wifi from '@ohos.wifiManager';
try {
let configs = wifiManager.getCandidateConfigs();
console.info("configs:" + JSON.stringify(configs));
let len = Object.keys(configs).length;
console.log("result len: " + len);
if(len > 0){
for (var i = 0; i < len; ++i) {
console.info("ssid: " + configs[i].ssid);
console.info("bssid: " + configs[i].bssid);
}
}
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
`````
## wifi.connectToCandidateConfig<sup>9+</sup> ## wifi.connectToCandidateConfig<sup>9+</sup>
connectToCandidateConfig(networkId: number): void connectToCandidateConfig(networkId: number): void
Connects to a candidate network. Connects to a candidate network added by the application. If the device is already connected to a hotspot, disconnect it from the hotspot first.
**Required permissions**: ohos.permission.SET_WIFI_INFO **Required permissions**: ohos.permission.SET_WIFI_INFO
...@@ -632,24 +773,38 @@ Connects to a candidate network. ...@@ -632,24 +773,38 @@ Connects to a candidate network.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| networkId | number | Yes| ID of the candidate network configuration.| | networkId | number | Yes| ID of the candidate network configuration.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let networkId = 0;
let ret = wifiManager.connectToCandidateConfig(networkId);
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.connectToNetwork<sup>9+</sup> ## wifi.connectToNetwork<sup>9+</sup>
connectToNetwork(networkId: number): void connectToNetwork(networkId: number): void
Connects to the specified network. Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -659,24 +814,37 @@ Connects to the specified network. ...@@ -659,24 +814,37 @@ Connects to the specified network.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| networkId | number | Yes| Network configuration ID.| | networkId | number | Yes| Network configuration ID.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let networkId = 0;
wifiManager.connectToNetwork(networkId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.connectToDevice<sup>9+</sup> ## wifi.connectToDevice<sup>9+</sup>
connectToDevice(config: WifiDeviceConfig): void connectToDevice(config: WifiDeviceConfig): void
Connects to the specified network. Connects to the specified network. If the device is already connected to a hotspot, use **disconnect()** to disconnect it from the hotspot first.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -687,19 +855,36 @@ Connects to the specified network. ...@@ -687,19 +855,36 @@ Connects to the specified network.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration.| | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| Configuration of the WLAN to connect. |
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
wifiManager.connectToDevice(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disconnect<sup>9+</sup> ## wifi.disconnect<sup>9+</sup>
disconnect(): void disconnect(): void
...@@ -717,10 +902,21 @@ Disconnects the network. ...@@ -717,10 +902,21 @@ Disconnects the network.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.disconnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getSignalLevel<sup>9+</sup> ## wifi.getSignalLevel<sup>9+</sup>
getSignalLevel(rssi: number, band: number): number getSignalLevel(rssi: number, band: number): number
...@@ -733,25 +929,40 @@ Obtains the WLAN signal level. ...@@ -733,25 +929,40 @@ Obtains the WLAN signal level.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| rssi | number | Yes| RSSI of the hotspot, in dBm.| | rssi | number | Yes| RSSI of the hotspot, in dBm.|
| band | number | Yes| Frequency band of the WLAN AP.| | band | number | Yes| Frequency band of the WLAN AP.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| number | Signal level obtained. The value range is [0, 4].| | number | Signal level obtained. The value range is [0, 4].|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let rssi = 0;
let band = 0;
let level = wifiManager.getSignalLevel(rssi,band);
console.info("lelvel:" + JSON.stringify(lelvel));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getLinkedInfo<sup>9+</sup> ## wifi.getLinkedInfo<sup>9+</sup>
getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt; getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
...@@ -764,16 +975,16 @@ Obtains WLAN connection information. This API uses a promise to return the resul ...@@ -764,16 +975,16 @@ Obtains WLAN connection information. This API uses a promise to return the resul
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Promise used to return the WLAN connection information obtained.| | Promise&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Promise used to return the WLAN connection information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
...@@ -789,22 +1000,22 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r ...@@ -789,22 +1000,22 @@ Obtains WLAN connection information. This API uses an asynchronous callback to r
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | 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.| | 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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example** **Example**
```js ```js
import wifi from '@ohos.wifi'; import wifi from '@ohos.wifiManager';
wifi.getLinkedInfo((err, data) => { wifi.getLinkedInfo((err, data) => {
if (err) { if (err) {
...@@ -832,21 +1043,25 @@ Represents the WLAN connection information. ...@@ -832,21 +1043,25 @@ Represents the WLAN connection information.
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| | ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.|
| bssid | string | Yes| No| BSSID of the hotspot.| | bssid | string | Yes| No| BSSID of the hotspot.|
| networkId | number | Yes| No| Network configuration ID.<br> **System API**: This is a system API.| | networkId | number | Yes| No| Network configuration ID.<br>**System API**: This is a system API.|
| rssi | number | Yes| No| RSSI of the hotspot, in dBm.| | rssi | number | Yes| No| RSSI of the hotspot, in dBm.|
| band | number | Yes| No| Frequency band of the WLAN AP.| | band | number | Yes| No| Band of the WLAN AP.|
| linkSpeed | number | Yes| No| Speed of the WLAN AP.| | linkSpeed | number | Yes| No| Uplink speed of the WLAN AP.|
| rxLinkSpeed<sup>10+</sup> | number | Yes| No| Downlink speed of the WLAN AP.|
| maxSupportedTxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.|
| maxSupportedRxLinkSpeed<sup>10+</sup> | number | Yes| No| Maximum uplink speed supported.|
| frequency | number | Yes| No| Frequency of the WLAN AP.| | frequency | number | Yes| No| Frequency of the WLAN AP.|
| isHidden | boolean | Yes| No| Whether to hide the WLAN AP.| | isHidden | boolean | Yes| No| Whether to hide the WLAN AP.|
| isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.| | isRestricted | boolean | Yes| No| Whether to restrict data volume at the WLAN AP.|
| chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br> **System API**: This is a system API.| | chload | number | Yes| No| Channel load. A larger value indicates a higher load.<br>**System API**: This is a system API.|
| snr | number | Yes| No| Signal-to-noise ratio (SNR).<br> **System API**: This is a system API.| | snr | number | Yes| No| Signal-to-noise ratio (SNR).<br>**System API**: This is a system API.|
| macType<sup>9+</sup> | number | Yes| No| MAC address type.| | macType | number | Yes| No| MAC address type.|
| macAddress | string | Yes| No| MAC address of the device.| | macAddress | string | Yes| No| MAC address of the device.|
| ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.| | ipAddress | number | Yes| No| IP address of the device that sets up the WLAN connection.|
| suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br> **System API**: This is a system API.| | suppState | [SuppState](#suppstate) | Yes| No| Supplicant state.<br>**System API**: This is a system API.|
| connState | [ConnState](#connstate) | Yes| No| WLAN connection state.| | connState | [ConnState](#connstate) | Yes| No| WLAN connection state.|
| channelWidth<sup>10+</sup> | [WifiChannelWidth](#wifichannelwidth) | Yes| No| Channel bandwidth of the connected hotspot.|
| wifiStandard<sup>10+</sup> | [WifiStandard](#wifistandard) | Yes| No| Wi-Fi standard used by the connected hotspot.|
## ConnState<sup>9+</sup> ## ConnState<sup>9+</sup>
...@@ -889,12 +1104,29 @@ Enumerates the supplicant states. ...@@ -889,12 +1104,29 @@ Enumerates the supplicant states.
| UNINITIALIZED | 10 | The supplicant failed to set up the connection.| | UNINITIALIZED | 10 | The supplicant failed to set up the connection.|
| INVALID | 11 | Invalid value.| | INVALID | 11 | Invalid value.|
## SuppState<sup>10+</sup>
## wifi.isConnected<sup>9+</sup> Enumerates the Wi-Fi standards.
isConnected(): boolean
Checks whether the WLAN is connected. **System capability**: SystemCapability.Communication.WiFi.STA
| Name| Value| Description|
| -------- | -------- | -------- |
| WIFI_STANDARD_UNDEFINED | 0 | Undefined|
| WIFI_STANDARD_11A | 1 | 802.11a|
| WIFI_STANDARD_11B | 2 | 802.11b|
| WIFI_STANDARD_11G | 3 | 802.11g|
| WIFI_STANDARD_11N | 4 | 802.11n|
| WIFI_STANDARD_11AC | 5 | 802.11ac|
| WIFI_STANDARD_11AX | 6 | 802.11ax|
| WIFI_STANDARD_11AD | 7 | 802.11ad|
## wifi.isConnected<sup>9+</sup>
isConnected(): boolean
Checks whether the WLAN is connected.
**Required permissions**: ohos.permission.GET_WIFI_INFO **Required permissions**: ohos.permission.GET_WIFI_INFO
...@@ -902,18 +1134,31 @@ Checks whether the WLAN is connected. ...@@ -902,18 +1134,31 @@ Checks whether the WLAN is connected.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.| | boolean | Returns **true** if the WLAN is connected; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let ret = wifiManager.isConnected();
console.info("isConnected:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getSupportedFeatures<sup>9+</sup> ## wifi.getSupportedFeatures<sup>9+</sup>
getSupportedFeatures(): number getSupportedFeatures(): number
...@@ -928,9 +1173,9 @@ Obtains the features supported by this device. ...@@ -928,9 +1173,9 @@ Obtains the features supported by this device.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| number | Feature value. | | number | Feature value. |
**Feature IDs** **Feature IDs**
...@@ -951,10 +1196,23 @@ Obtains the features supported by this device. ...@@ -951,10 +1196,23 @@ Obtains the features supported by this device.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2401000 | Operation failed.| | 2401000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let ret = wifiManager.getSupportedFeatures();
console.info("supportedFeatures:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isFeatureSupported<sup>9+</sup> ## wifi.isFeatureSupported<sup>9+</sup>
isFeatureSupported(featureId: number): boolean isFeatureSupported(featureId: number): boolean
...@@ -968,24 +1226,38 @@ Checks whether the device supports the specified WLAN feature. ...@@ -968,24 +1226,38 @@ Checks whether the device supports the specified WLAN feature.
**Parameters** **Parameters**
| **Name**| **Type**| Mandatory| **Description**| | **Name**| **Type**| Mandatory| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| featureId | number | Yes| Feature ID.| | featureId | number | Yes| Feature ID.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the feature is supported; returns **false** otherwise.| | boolean | Returns **true** if the feature is supported; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2401000 | Operation failed.| | 2401000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let featureId = 0;
let ret = wifiManager.isFeatureSupported(featureId);
console.info("isFeatureSupported:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getDeviceMacAddress<sup>9+</sup> ## wifi.getDeviceMacAddress<sup>9+</sup>
getDeviceMacAddress(): string[] getDeviceMacAddress(): string[]
...@@ -1000,18 +1272,31 @@ Obtains the device MAC address. ...@@ -1000,18 +1272,31 @@ Obtains the device MAC address.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| string[] | MAC address obtained.| | string[] | MAC address obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let ret = wifiManager.getDeviceMacAddress();
console.info("deviceMacAddress:" + JSON.stringify(ret));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getIpInfo<sup>9+</sup> ## wifi.getIpInfo<sup>9+</sup>
getIpInfo(): IpInfo getIpInfo(): IpInfo
...@@ -1024,18 +1309,30 @@ Obtains IP information. ...@@ -1024,18 +1309,30 @@ Obtains IP information.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| [IpInfo](#ipinfo9) | IP information obtained.| | [IpInfo](#ipinfo9) | IP information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let info = wifiManager.getIpInfo();
console.info("info:" + JSON.stringify(info));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## IpInfo<sup>9+</sup> ## IpInfo<sup>9+</sup>
Represents IP information. Represents IP information.
...@@ -1065,18 +1362,30 @@ Obtains the country code. ...@@ -1065,18 +1362,30 @@ Obtains the country code.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| string | Country code obtained.| | string | Country code obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2401000 | Operation failed.| | 2401000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let code = wifiManager.getCountryCode();
console.info("code:" + code);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.reassociate<sup>9+</sup> ## wifi.reassociate<sup>9+</sup>
reassociate(): void reassociate(): void
...@@ -1093,11 +1402,22 @@ Re-associates with the network. ...@@ -1093,11 +1402,22 @@ Re-associates with the network.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.reassociate();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.reconnect<sup>9+</sup> ## wifi.reconnect<sup>9+</sup>
reconnect(): void reconnect(): void
...@@ -1114,11 +1434,22 @@ Reconnects to the network. ...@@ -1114,11 +1434,22 @@ Reconnects to the network.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
| 2501001 | Wifi is closed.| | 2501001 | Wifi is closed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.reconnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getDeviceConfigs<sup>9+</sup> ## wifi.getDeviceConfigs<sup>9+</sup>
getDeviceConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; getDeviceConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt;
...@@ -1127,27 +1458,39 @@ Obtains network configuration. ...@@ -1127,27 +1458,39 @@ Obtains network configuration.
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.GET_WIFI_CONFIG **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.GET_WIFI_CONFIG
**System capability**: SystemCapability.Communication.WiFi.STA **System capability**: SystemCapability.Communication.WiFi.STA
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.| | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | Array of network configuration obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.updateNetwork<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
let configs = wifiManager.getDeviceConfigs();
console.info("configs:" + JSON.stringify(configs));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.updateDeviceConfig<sup>9+</sup>
updateNetwork(config: WifiDeviceConfig): number updateDeviceConfig(config: WifiDeviceConfig): number
Updates network configuration. Updates network configuration.
...@@ -1159,27 +1502,44 @@ Updates network configuration. ...@@ -1159,27 +1502,44 @@ Updates network configuration.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.| | config | [WifiDeviceConfig](#wifideviceconfig) | Yes| New WLAN configuration.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.| | number | ID of the updated network configuration. The value **-1** indicates that the operation has failed.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.disableNetwork<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
let ret = wifiManager.updateDeviceConfig(config);
console.error("ret:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableDeviceConfig<sup>9+</sup>
disableNetwork(netId: number): void disableDeviceConfig(networkId: number): void
Disables network configuration. Disables network configuration.
...@@ -1191,21 +1551,33 @@ Disables network configuration. ...@@ -1191,21 +1551,33 @@ Disables network configuration.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| netId | number | Yes| ID of the network configuration to disable.| | netId | number | Yes| ID of the network configuration to disable.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.removeAllNetwork<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
let netId = 0;
wifiManager.disableDeviceConfig(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeAllDeviceConfigs<sup>9+</sup>
removeAllNetwork(): void removeAllDeviceConfigs(): void
Removes the configuration of all networks. Removes the configuration of all networks.
...@@ -1219,13 +1591,24 @@ Removes the configuration of all networks. ...@@ -1219,13 +1591,24 @@ Removes the configuration of all networks.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.removeDevice<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
removeDevice(id: number): void try {
wifiManager.removeAllDeviceConfigs();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.removeDeviceConfig<sup>9+</sup>
removeDeviceConfig(networkId: number): void
Removes the specified network configuration. Removes the specified network configuration.
...@@ -1237,18 +1620,114 @@ Removes the specified network configuration. ...@@ -1237,18 +1620,114 @@ Removes the specified network configuration.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| id | number | Yes| ID of the network configuration to remove.| | networkId | number | Yes| ID of the network configuration to remove.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **ID**| **Error Message**|
| -------- | -------- |
| 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let id = 0;
wifiManager.removeDeviceConfig(id);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isBandTypeSupported<sup>10+</sup>
isBandTypeSupported(bandType: WifiBandType): boolean
Checks whether the current frequency band is supported.
**Required permissions**: ohos.permission.GET_WIFI_INFO
**System capability**: SystemCapability.Communication.WiFi.STA
**Parameters**
| **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- |
| bandType | WifiBandType | Yes| Wi-Fi band type.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let type = 0;
boolean isBandTypeSupported = wifiManager.isBandTypeSupported(type);
console.info("isBandTypeSupported:" + isBandTypeSupported);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiBandType <sup>10+</sup>
Enumerates the Wi-Fi band types.
**System capability**: SystemCapability.Communication.WiFi.STA
| Name| Value| Description|
| -------- | -------- | -------- |
| WIFI_BAND_NONE | 0 | Undefined|
| WIFI_BAND_2G | 1 | 2 GHz|
| WIFI_BAND_5G | 2 | 5 GHz|
| WIFI_BAND_6G | 3 | 6 GHz|
| WIFI_BAND_60G | 4 | 60 GHz|
## wifi.get5GChannelList<sup>10+</sup>
get5GChannelList(): Array&lt;number&gt;
Obtains the list of 5 GHz channels supported by this device.
**System API**: This is a system API.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
**System capability**: SystemCapability.Communication.WiFi.STA
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **ID**| **Error Message**|
| -------- | -------- |
| 2501000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let channelList = wifiManager.get5GChannelList();
console.info("channelList:" + JSON.stringify(channelList));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.enableHotspot<sup>9+</sup> ## wifi.enableHotspot<sup>9+</sup>
enableHotspot(): void enableHotspot(): void
...@@ -1265,10 +1744,21 @@ Enables this hotspot. ...@@ -1265,10 +1744,21 @@ Enables this hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.enableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.disableHotspot<sup>9+</sup> ## wifi.disableHotspot<sup>9+</sup>
disableHotspot(): void disableHotspot(): void
...@@ -1285,10 +1775,21 @@ Disables this hotspot. ...@@ -1285,10 +1775,21 @@ Disables this hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.disableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isHotspotDualBandSupported<sup>9+</sup> ## wifi.isHotspotDualBandSupported<sup>9+</sup>
isHotspotDualBandSupported(): boolean isHotspotDualBandSupported(): boolean
...@@ -1303,18 +1804,30 @@ Checks whether the hotspot supports dual band. ...@@ -1303,18 +1804,30 @@ Checks whether the hotspot supports dual band.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.| | boolean | Returns **true** if the hotspot supports dual band; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let ret = wifiManager.isHotspotDualBandSupported();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.isHotspotActive<sup>9+</sup> ## wifi.isHotspotActive<sup>9+</sup>
isHotspotActive(): boolean isHotspotActive(): boolean
...@@ -1329,18 +1842,30 @@ Checks whether this hotspot is active. ...@@ -1329,18 +1842,30 @@ Checks whether this hotspot is active.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the hotspot is active; returns **false** otherwise.| | boolean | Returns **true** if the hotspot is active; returns **false** otherwise.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let ret = wifiManager.isHotspotActive();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.setHotspotConfig<sup>9+</sup> ## wifi.setHotspotConfig<sup>9+</sup>
setHotspotConfig(config: HotspotConfig): void setHotspotConfig(config: HotspotConfig): void
...@@ -1355,18 +1880,38 @@ Sets hotspot configuration. ...@@ -1355,18 +1880,38 @@ Sets hotspot configuration.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.| | config | [HotspotConfig](#hotspotconfig9) | Yes| Hotspot configuration to set.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
ssid: "****",
securityType: 3,
band: 0,
channel: 0,
preSharedKey: "****",
maxConn: 0
}
let ret = wifiManager.setHotspotConfig();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## HotspotConfig<sup>9+</sup> ## HotspotConfig<sup>9+</sup>
Represents the hotspot configuration. Represents the hotspot configuration.
...@@ -1377,12 +1922,12 @@ Represents the hotspot configuration. ...@@ -1377,12 +1922,12 @@ Represents the hotspot configuration.
| **Name**| **Type**| **Readable**| **Writable**| **Description**| | **Name**| **Type**| **Readable**| **Writable**| **Description**|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| SSID of the hotspot, in UTF-8 format.| | ssid | string | Yes| Yes| SSID of the hotspot, in UTF-8 format.|
| securityType | [WifiSecurityType](#wifisecuritytype) | Yes| No| Security type.| | securityType | [WifiSecurityType](#wifisecuritytype) | Yes| Yes| Security type.|
| band | number | Yes| No| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.| | band | number | Yes| Yes| Hotspot band. The value **1** stands for 2.4 GHz, the value **2** for 5 GHz, and the value **3** for dual band.|
| preSharedKey | string | Yes| No| PSK of the hotspot.| | channel<sup>10+</sup> | number | Yes| Yes| Hotspot channel (2.4 GHz: 1 to 14; 5 GHz: 7 to 196; Dual-band: not supported currently) |
| maxConn | number | Yes| No| Maximum number of connections allowed.| | preSharedKey | string | Yes| Yes| PSK of the hotspot.|
| maxConn | number | Yes| Yes| Maximum number of connections allowed.|
## wifi.getHotspotConfig<sup>9+</sup> ## wifi.getHotspotConfig<sup>9+</sup>
...@@ -1398,44 +1943,68 @@ Obtains hotspot configuration. ...@@ -1398,44 +1943,68 @@ Obtains hotspot configuration.
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.| | [HotspotConfig](#hotspotconfig9) | Hotspot configuration obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
## wifi.getStations<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = wifiManager.getHotspotConfig();
console.info("result:" + JSON.stringify(config));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getHotspotStations<sup>9+</sup>
getStations(): &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; getHotspotStations(): &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt;
Obtains information about the connected stations. Obtains information about the connected stations.
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications) **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
**System capability**: SystemCapability.Communication.WiFi.AP.Core **System capability**: SystemCapability.Communication.WiFi.AP.Core
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; | Connected stations obtained.| | &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; | Connected stations obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let stations = wifiManager.getHotspotStations();
console.info("result:" + JSON.stringify(stations));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## StationInfo<sup>9+</sup> ## StationInfo<sup>9+</sup>
Represents the station information. Represents the station information.
...@@ -1463,18 +2032,36 @@ Obtains P2P link information. This API uses a promise to return the result. ...@@ -1463,18 +2032,36 @@ Obtains P2P link information. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Promise used to return the P2P link information obtained.| | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Promise used to return the P2P link information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
wifi.getP2pLinkedInfo((err, data) => {
if (err) {
console.error("get p2p linked info error");
return;
}
console.info("get wifi p2p linked info: " + JSON.stringify(data));
});
wifi.getP2pLinkedInfo().then(data => {
console.info("get wifi p2p linked info: " + JSON.stringify(data));
});
```
## WifiP2pLinkedInfo<sup>9+</sup> ## WifiP2pLinkedInfo<sup>9+</sup>
Represents the P2P link information. Represents the P2P link information.
...@@ -1512,81 +2099,98 @@ Obtains P2P link information. This API uses an asynchronous callback to return t ...@@ -1512,81 +2099,98 @@ Obtains P2P link information. This API uses an asynchronous callback to return t
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&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.| | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&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.|
## wifi.getCurrentGroup<sup>9+</sup> ## wifi.getCurrentP2pGroup<sup>9+</sup>
getCurrentGroup(): Promise&lt;WifiP2pGroupInfo&gt; getCurrentP2pGroup(): Promise&lt;WifiP2pGroupInfo&gt;
Obtains the current P2P group information. This API uses a promise to return the result. Obtains the current P2P group information. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt; | Promise used to return the P2P group information obtained.| | Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt; | Promise used to return the P2P group information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.getCurrentGroup<sup>9+</sup> ## wifi.getCurrentP2pGroup<sup>9+</sup>
getCurrentGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void getCurrentP2pGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void
Obtains the current P2P group information. This API uses an asynchronous callback to return the result. Obtains the current P2P group information. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&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.| | callback | AsyncCallback&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
wifi.getCurrentP2pGroup((err, data) => {
if (err) {
console.error("get current P2P group error");
return;
}
console.info("get current P2P group: " + JSON.stringify(data));
});
wifi.getCurrentP2pGroup().then(data => {
console.info("get current P2P group: " + JSON.stringify(data));
});
```
## wifi.getP2pPeerDevices<sup>9+</sup> ## wifi.getP2pPeerDevices<sup>9+</sup>
getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt; getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;
Obtains the peer device list in the P2P connection. This API uses a promise to return the result. Obtains the peer device list in the P2P connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Promise used to return the peer device list.| | Promise&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Promise used to return the peer device list.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.getP2pPeerDevices<sup>9+</sup> ## wifi.getP2pPeerDevices<sup>9+</sup>
...@@ -1595,24 +2199,41 @@ getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void ...@@ -1595,24 +2199,41 @@ getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void
Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result. Obtains the peer device list in the P2P connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&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.| | callback | AsyncCallback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
wifi.getP2pPeerDevices((err, data) => {
if (err) {
console.error("get P2P peer devices error");
return;
}
console.info("get P2P peer devices: " + JSON.stringify(data));
});
wifi.getP2pPeerDevices().then(data => {
console.info("get P2P peer devices: " + JSON.stringify(data));
});
```
## WifiP2pDevice<sup>9+</sup> ## WifiP2pDevice<sup>9+</sup>
Represents the P2P device information. Represents the P2P device information.
...@@ -1655,16 +2276,16 @@ Obtains the local device information in the P2P connection. This API uses a prom ...@@ -1655,16 +2276,16 @@ Obtains the local device information in the P2P connection. This API uses a prom
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Promise used to return the local device information obtained.| | Promise&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Promise used to return the local device information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.getP2pLocalDevice<sup>9+</sup> ## wifi.getP2pLocalDevice<sup>9+</sup>
...@@ -1679,14 +2300,34 @@ Obtains the local device information in the P2P connection. This API uses an asy ...@@ -1679,14 +2300,34 @@ Obtains the local device information in the P2P connection. This API uses an asy
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[WifiP2pDevice](#wifip2pdevice9)&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.| | callback | AsyncCallback&lt;[WifiP2pDevice](#wifip2pdevice9)&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.|
| **ID**| **Error Message**|
| -------- | -------- |
| 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
wifiManager.getP2pLocalDevice((err, data) => {
if (err) {
console.error("get P2P local device error");
return;
}
console.info("get P2P local device: " + JSON.stringify(data));
});
wifi.getP2pLocalDevice().then(data => {
console.info("get P2P local device: " + JSON.stringify(data));
});
```
## wifi.createGroup<sup>9+</sup> ## wifi.createP2pGroup<sup>9+</sup>
createGroup(config: WifiP2PConfig): void createP2pGroup(config: WifiP2PConfig): void
Creates a P2P group. Creates a P2P group.
...@@ -1696,18 +2337,37 @@ Creates a P2P group. ...@@ -1696,18 +2337,37 @@ Creates a P2P group.
**Parameters** **Parameters**
| **Name**| **Type**| Mandatory| **Description**| | **Name**| **Type**| Mandatory| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration.| | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| Group configuration.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let config = {
deviceAddress: "****",
netId: 0,
passphrase: "*****",
groupName: "****",
goBand: 0
}
wifiManager.createP2pGroup(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## WifiP2PConfig<sup>9+</sup> ## WifiP2PConfig<sup>9+</sup>
Represents P2P group configuration. Represents P2P group configuration.
...@@ -1736,9 +2396,9 @@ Enumerates the P2P group frequency bands. ...@@ -1736,9 +2396,9 @@ Enumerates the P2P group frequency bands.
| GO_BAND_5GHZ | 2 | 5 GHz.| | GO_BAND_5GHZ | 2 | 5 GHz.|
## wifi.removeGroup<sup>9+</sup> ## wifi.removeP2pGroup<sup>9+</sup>
removeGroup(): void removeP2pGroup(): void
Removes this P2P group. Removes this P2P group.
...@@ -1750,33 +2410,43 @@ Removes this P2P group. ...@@ -1750,33 +2410,43 @@ Removes this P2P group.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.removeP2pGroup();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.p2pConnect<sup>9+</sup> ## wifi.p2pConnect<sup>9+</sup>
p2pConnect(config: WifiP2PConfig): void p2pConnect(config: WifiP2PConfig): void
Sets up a P2P connection. Sets up a P2P connection.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| **Name**| **Type**| Mandatory| **Description**|
| **Name**| **Type**| Mandatory| **Description**| | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | | config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration.|
| config | [WifiP2PConfig](#wifip2pconfig9) | Yes| P2P group configuration.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example** **Example**
...@@ -1843,7 +2513,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco ...@@ -1843,7 +2513,7 @@ For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorco
setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000); setTimeout(function() {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
console.info("start discover devices -> " + wifi.startDiscoverDevices()); console.info("start discover devices -> " + wifi.startP2pDiscoverDevices());
``` ```
## wifi.p2pCancelConnect<sup>9+</sup> ## wifi.p2pCancelConnect<sup>9+</sup>
...@@ -1860,17 +2530,28 @@ Cancels this P2P connection. ...@@ -1860,17 +2530,28 @@ Cancels this P2P connection.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.startDiscoverDevices<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.p2pCancelConnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
startDiscoverDevices(): void ## wifi.startDiscoverP2pDevices<sup>9+</sup>
startDiscoverP2pDevices(): void
Starts to discover devices. Starts to discover devices.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
...@@ -1878,13 +2559,24 @@ Starts to discover devices. ...@@ -1878,13 +2559,24 @@ Starts to discover devices.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.stopDiscoverDevices<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.startDiscoverP2pDevices();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
stopDiscoverDevices(): void ## wifi.stopDiscoverP2pDevices<sup>9+</sup>
stopDiscoverP2pDevices(): void
Stops discovering devices. Stops discovering devices.
...@@ -1896,13 +2588,24 @@ Stops discovering devices. ...@@ -1896,13 +2588,24 @@ Stops discovering devices.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.deletePersistentGroup<sup>9+</sup> **Example**
```
import wifi from '@ohos.wifiManager';
try {
wifiManager.stopDiscoverP2pDevices();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
deletePersistentGroup(netId: number): void ## wifi.deletePersistentP2pGroup<sup>9+</sup>
deletePersistentP2pGroup(netId: number): void
Deletes a persistent group. Deletes a persistent group.
...@@ -1915,18 +2618,30 @@ Deletes a persistent group. ...@@ -1915,18 +2618,30 @@ Deletes a persistent group.
**Parameters** **Parameters**
| **Name**| **Type**| Mandatory| **Description**| | **Name**| **Type**| Mandatory| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| netId | number | Yes| ID of the group to delete.| | netId | number | Yes| ID of the group to delete.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let netId = 0;
wifiManager.deletePersistentP2pGroup(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.getP2pGroups<sup>9+</sup> ## wifi.getP2pGroups<sup>9+</sup>
getP2pGroups(): Promise&lt;Array&lt;WifiP2pGroupInfo&gt;&gt; getP2pGroups(): Promise&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;
...@@ -1935,24 +2650,42 @@ Obtains information about all P2P groups. This API uses a promise to return the ...@@ -1935,24 +2650,42 @@ Obtains information about all P2P groups. This API uses a promise to return the
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt;&nbsp;&gt; | Promise used to return the group information obtained.| | Promise&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&gt;&nbsp;&gt; | Promise used to return the group information obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
wifiManager.getP2pGroups((err, data) => {
if (err) {
console.error("get P2P groups error");
return;
}
console.info("get P2P groups: " + JSON.stringify(data));
});
wifi.getP2pGroups().then(data => {
console.info("get P2P groups: " + JSON.stringify(data));
});
```
## WifiP2pGroupInfo<sup>9+</sup> ## WifiP2pGroupInfo<sup>9+</sup>
Represents the P2P group information. Represents the P2P group information.
...@@ -1980,27 +2713,27 @@ Obtains information about all P2P groups. This API uses an asynchronous callback ...@@ -1980,27 +2713,27 @@ Obtains information about all P2P groups. This API uses an asynchronous callback
**System API**: This is a system API. **System API**: This is a system API.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&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.| | callback | AsyncCallback&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo9)&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.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.setDeviceName<sup>9+</sup> ## wifi.setP2pDeviceName<sup>9+</sup>
setDeviceName(devName: string): void setP2pDeviceName(devName: string): void
Sets the device name. Sets the device name.
...@@ -2012,18 +2745,30 @@ Sets the device name. ...@@ -2012,18 +2745,30 @@ Sets the device name.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| devName | string | Yes| Device name to set.| | devName | string | Yes| Device name to set.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```
import wifi from '@ohos.wifiManager';
try {
let name = "****";
wifiManager.setP2pDeviceName(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
```
## wifi.on('wifiStateChange')<sup>9+</sup> ## wifi.on('wifiStateChange')<sup>9+</sup>
on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
...@@ -2036,17 +2781,17 @@ Registers the WLAN state change events. ...@@ -2036,17 +2781,17 @@ Registers the WLAN state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiStateChange**.| | type | string | Yes| Event type. The value is **wifiStateChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN state.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**WLAN states** **WLAN states**
...@@ -2071,17 +2816,17 @@ Unregisters the WLAN state change events. ...@@ -2071,17 +2816,17 @@ Unregisters the WLAN state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiStateChange**.| | type | string | Yes| Event type. The value is **wifiStateChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the WLAN state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the WLAN state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example** **Example**
...@@ -2112,10 +2857,10 @@ Registers the WLAN connection state change events. ...@@ -2112,10 +2857,10 @@ Registers the WLAN connection state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiConnectionChange**.| | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN connection state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN connection state.|
**WLAN connection states** **WLAN connection states**
...@@ -2128,8 +2873,8 @@ Registers the WLAN connection state change events. ...@@ -2128,8 +2873,8 @@ Registers the WLAN connection state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.off('wifiConnectionChange')<sup>9+</sup> ## wifi.off('wifiConnectionChange')<sup>9+</sup>
...@@ -2144,19 +2889,34 @@ Unregisters the WLAN connection state change events. ...@@ -2144,19 +2889,34 @@ Unregisters the WLAN connection state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiConnectionChange**.| | type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the WLAN connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the WLAN connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvWifiConnectionChangeFunc = result => {
console.info("Receive wifi connection change event: " + result);
}
// Register an event.
wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc);
// Unregister an event.
wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc);
```
## wifi.on('wifiScanStateChange')<sup>9+</sup> ## wifi.on('wifiScanStateChange')<sup>9+</sup>
on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
...@@ -2169,10 +2929,10 @@ Registers the WLAN scan state change events. ...@@ -2169,10 +2929,10 @@ Registers the WLAN scan state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiScanStateChange**.| | type | string | Yes| Event type. The value is **wifiScanStateChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN scan state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the WLAN scan state.|
**WLAN scan states** **WLAN scan states**
...@@ -2185,8 +2945,8 @@ Registers the WLAN scan state change events. ...@@ -2185,8 +2945,8 @@ Registers the WLAN scan state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.off('wifiScanStateChange')<sup>9+</sup> ## wifi.off('wifiScanStateChange')<sup>9+</sup>
...@@ -2210,10 +2970,25 @@ Unregisters the WLAN scan state change events. ...@@ -2210,10 +2970,25 @@ Unregisters the WLAN scan state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifi';
var recvWifiScanStateChangeFunc = result => {
console.info("Receive Wifi scan state change event: " + result);
}
// Register an event.
wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc);
// Unregister an event.
wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc);
```
## wifi.on('wifiRssiChange')<sup>9+</sup> ## wifi.on('wifiRssiChange')<sup>9+</sup>
on(type: "wifiRssiChange", callback: Callback&lt;number&gt;): void on(type: "wifiRssiChange", callback: Callback&lt;number&gt;): void
...@@ -2226,17 +3001,17 @@ Registers the RSSI change events. ...@@ -2226,17 +3001,17 @@ Registers the RSSI change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiRssiChange**.| | type | string | Yes| Event type. The value is **wifiRssiChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the RSSI, in dBm.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the RSSI, in dBm.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
## wifi.off('wifiRssiChange')<sup>9+</sup> ## wifi.off('wifiRssiChange')<sup>9+</sup>
...@@ -2251,19 +3026,34 @@ Unregisters the RSSI change events. ...@@ -2251,19 +3026,34 @@ Unregisters the RSSI change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **wifiRssiChange**.| | type | string | Yes| Event type. The value is **wifiRssiChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the RSSI change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the RSSI change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2501000 | Operation failed.| | 2501000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvWifiRssiChangeFunc = result => {
console.info("Receive wifi rssi change event: " + result);
}
// Register an event.
wifiManager.on("wifiRssiChange", recvWifiRssiChangeFunc);
// Unregister an event.
wifiManager.off("wifiRssiChange", recvWifiRssiChangeFunc);
```
## wifi.on('hotspotStateChange')<sup>9+</sup> ## wifi.on('hotspotStateChange')<sup>9+</sup>
on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
...@@ -2276,10 +3066,10 @@ Registers the hotspot state change events. ...@@ -2276,10 +3066,10 @@ Registers the hotspot state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **hotspotStateChange**.| | type | string | Yes| Event type. The value is **hotspotStateChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the hotspot state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the hotspot state.|
**Hotspot states** **Hotspot states**
...@@ -2294,8 +3084,8 @@ Registers the hotspot state change events. ...@@ -2294,8 +3084,8 @@ Registers the hotspot state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
## wifi.off('hotspotStateChange')<sup>9+</sup> ## wifi.off('hotspotStateChange')<sup>9+</sup>
...@@ -2310,19 +3100,34 @@ Unregisters the hotspot state change events. ...@@ -2310,19 +3100,34 @@ Unregisters the hotspot state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **hotspotStateChange**.| | type | string | Yes| Event type. The value is **hotspotStateChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the hotspot state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the hotspot state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2601000 | Operation failed.| | 2601000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvHotspotStateChangeFunc = result => {
console.info("Receive hotspot state change event: " + result);
}
// Register an event.
wifiManager.on("hotspotStateChange", recvHotspotStateChangeFunc);
// Unregister an event.
wifiManager.off("hotspotStateChange", recvHotspotStateChangeFunc);
```
## wifi.on('p2pStateChange')<sup>9+</sup> ## wifi.on('p2pStateChange')<sup>9+</sup>
on(type: "p2pStateChange", callback: Callback&lt;number&gt;): void on(type: "p2pStateChange", callback: Callback&lt;number&gt;): void
...@@ -2335,10 +3140,10 @@ Registers the P2P state change events. ...@@ -2335,10 +3140,10 @@ Registers the P2P state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pStateChange**.| | type | string | Yes| Event type. The value is **p2pStateChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P state.|
**P2P states** **P2P states**
...@@ -2354,8 +3159,8 @@ Registers the P2P state change events. ...@@ -2354,8 +3159,8 @@ Registers the P2P state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pStateChange')<sup>9+</sup> ## wifi.off('p2pStateChange')<sup>9+</sup>
...@@ -2370,19 +3175,34 @@ Unregisters the P2P state change events. ...@@ -2370,19 +3175,34 @@ Unregisters the P2P state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pStateChange**.| | type | string | Yes| Event type. The value is **p2pStateChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the P2P state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the P2P state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pStateChangeFunc = result => {
console.info("Receive p2p state change event: " + result);
}
// Register an event.
wifiManager.on("p2pStateChange", recvP2pStateChangeFunc);
// Unregister an event.
wifiManager.off("p2pStateChange", recvP2pStateChangeFunc);
```
## wifi.on('p2pConnectionChange')<sup>9+</sup> ## wifi.on('p2pConnectionChange')<sup>9+</sup>
on(type: "p2pConnectionChange", callback: Callback&lt;WifiP2pLinkedInfo&gt;): void on(type: "p2pConnectionChange", callback: Callback&lt;WifiP2pLinkedInfo&gt;): void
...@@ -2395,17 +3215,17 @@ Registers the P2P connection state change events. ...@@ -2395,17 +3215,17 @@ Registers the P2P connection state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pConnectionChange**.| | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Yes| Callback invoked to return the P2P connection state.| | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | Yes| Callback invoked to return the P2P connection state.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pConnectionChange')<sup>9+</sup> ## wifi.off('p2pConnectionChange')<sup>9+</sup>
...@@ -2420,42 +3240,57 @@ Unregisters the P2P connection state change events. ...@@ -2420,42 +3240,57 @@ Unregisters the P2P connection state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pConnectionChange**.| | type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | No| Callback for the P2P connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo9)&gt; | No| Callback for the P2P connection state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pConnectionChangeFunc = result => {
console.info("Receive p2p connection change event: " + result);
}
// Register an event.
wifiManager.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
// Unregister an event.
wifiManager.off("p2pConnectionChange", recvP2pConnectionChangeFunc);
```
## wifi.on('p2pDeviceChange')<sup>9+</sup> ## wifi.on('p2pDeviceChange')<sup>9+</sup>
on(type: "p2pDeviceChange", callback: Callback&lt;WifiP2pDevice&gt;): void on(type: "p2pDeviceChange", callback: Callback&lt;WifiP2pDevice&gt;): void
Registers the P2P device state change events. Registers the P2P device state change events.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pDeviceChange**.| | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Yes| Callback invoked to return the P2P device state.| | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | Yes| Callback invoked to return the P2P device state.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pDeviceChange')<sup>9+</sup> ## wifi.off('p2pDeviceChange')<sup>9+</sup>
...@@ -2464,48 +3299,63 @@ off(type: "p2pDeviceChange", callback?: Callback&lt;WifiP2pDevice&gt;): void ...@@ -2464,48 +3299,63 @@ off(type: "p2pDeviceChange", callback?: Callback&lt;WifiP2pDevice&gt;): void
Unregisters the P2P device state change events. Unregisters the P2P device state change events.
**Required permissions**: ohos.permission.LOCATION **Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pDeviceChange**.| | type | string | Yes| Event type. The value is **p2pDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | No| Callback for the P2P device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice9)&gt; | No| Callback for the P2P device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pDeviceChangeFunc = result => {
console.info("Receive recv p2p device change event: " + result);
}
// Register an event.
wifiManager.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
// Unregister an event.
wifiManager.off("p2pDeviceChange", recvP2pDeviceChangeFunc);
```
## wifi.on('p2pPeerDeviceChange')<sup>9+</sup> ## wifi.on('p2pPeerDeviceChange')<sup>9+</sup>
on(type: "p2pPeerDeviceChange", callback: Callback&lt;WifiP2pDevice[]&gt;): void on(type: "p2pPeerDeviceChange", callback: Callback&lt;WifiP2pDevice[]&gt;): void
Registers the P2P peer device state change events. Registers the P2P peer device state change events.
**Required permissions**: ohos.permission.GET_WIFI_INFO and ohos.permission.LOCATION **Required permissions**: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Yes| Callback invoked to return the P2P peer device state.| | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | Yes| Callback invoked to return the P2P peer device state.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pPeerDeviceChange')<sup>9+</sup> ## wifi.off('p2pPeerDeviceChange')<sup>9+</sup>
...@@ -2514,25 +3364,40 @@ off(type: "p2pPeerDeviceChange", callback?: Callback&lt;WifiP2pDevice[]&gt;): vo ...@@ -2514,25 +3364,40 @@ off(type: "p2pPeerDeviceChange", callback?: Callback&lt;WifiP2pDevice[]&gt;): vo
Unregisters the P2P peer device state change events. Unregisters the P2P peer device state change events.
**Required permissions**: ohos.permission.LOCATION **Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Communication.WiFi.P2P **System capability**: SystemCapability.Communication.WiFi.P2P
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.| | type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | No| Callback for the P2P peer device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice9)&gt; | No| Callback for the P2P peer device state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pPeerDeviceChangeFunc = result => {
console.info("Receive recv p2p peer device change event: " + result);
}
// Register an event.
wifiManager.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
// Unregister an event.
wifiManager.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
```
## wifi.on('p2pPersistentGroupChange')<sup>9+</sup> ## wifi.on('p2pPersistentGroupChange')<sup>9+</sup>
on(type: "p2pPersistentGroupChange", callback: Callback&lt;void&gt;): void on(type: "p2pPersistentGroupChange", callback: Callback&lt;void&gt;): void
...@@ -2545,17 +3410,17 @@ Registers the P2P persistent group state change events. ...@@ -2545,17 +3410,17 @@ Registers the P2P persistent group state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| callback | Callback&lt;void&gt; | Yes| Callback invoked to return the P2P persistent group state.| | callback | Callback&lt;void&gt; | Yes| Callback invoked to return the P2P persistent group state.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pPersistentGroupChange')<sup>9+</sup> ## wifi.off('p2pPersistentGroupChange')<sup>9+</sup>
...@@ -2570,19 +3435,34 @@ Unregisters the P2P persistent group state change events. ...@@ -2570,19 +3435,34 @@ Unregisters the P2P persistent group state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.| | type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| callback | Callback&lt;void&gt; | No| Callback for the P2P persistent group state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;void&gt; | No| Callback for the P2P persistent group state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pPersistentGroupChangeFunc = result => {
console.info("Receive recv p2p persistent group change event: " + result);
}
// Register an event.
wifiManager.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
// Unregister an event.
wifiManager.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
```
## wifi.on('p2pDiscoveryChange')<sup>9+</sup> ## wifi.on('p2pDiscoveryChange')<sup>9+</sup>
on(type: "p2pDiscoveryChange", callback: Callback&lt;number&gt;): void on(type: "p2pDiscoveryChange", callback: Callback&lt;number&gt;): void
...@@ -2595,10 +3475,10 @@ Registers the P2P device discovery state change events. ...@@ -2595,10 +3475,10 @@ Registers the P2P device discovery state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P device discovery state.| | callback | Callback&lt;number&gt; | Yes| Callback invoked to return the P2P device discovery state.|
**P2P discovered device states** **P2P discovered device states**
...@@ -2611,8 +3491,8 @@ Registers the P2P device discovery state change events. ...@@ -2611,8 +3491,8 @@ Registers the P2P device discovery state change events.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
## wifi.off('p2pDiscoveryChange')<sup>9+</sup> ## wifi.off('p2pDiscoveryChange')<sup>9+</sup>
...@@ -2627,15 +3507,30 @@ Unregisters the P2P device discovery state change events. ...@@ -2627,15 +3507,30 @@ Unregisters the P2P device discovery state change events.
**Parameters** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.| | type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| callback | Callback&lt;number&gt; | No| Callback for the P2P device discovery state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.| | callback | Callback&lt;number&gt; | No| Callback for the P2P device discovery state change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **ID**| **Error Message**|
| -------- | -------- | | -------- | -------- |
| 2801000 | Operation failed.| | 2801000 | Operation failed.|
**Example**
```js
import wifi from '@ohos.wifiManager';
var recvP2pDiscoveryChangeFunc = result => {
console.info("Receive recv p2p discovery change event: " + result);
}
// Register an event.
wifiManager.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
// Unregister an event.
wifiManager.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册