| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```js
importwififrom'@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
importwififrom'@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
importwififrom'@ohos.wifi';
try{
letisActivate=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
importwififrom'@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< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
| callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
**Example**
**Example**
```js
importwififrom'@ohos.wifi';
wifi.getScanInfos((err,result)=>{
```js
importwififrom'@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
| 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<number> | 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<number> | 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.|
@@ -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<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
| Promise<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
**Example**
```js
importwififrom'@ohos.wifi';
try{
letconfig={
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<boolean> | 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<boolean> | 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
importwififrom'@ohos.wifi';
try{
letconfig={
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<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
| Promise<boolean> | Promise used to return the result. If the operation is successful, **true** is returned; otherwise, **false** is returned.|
@@ -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<boolean> | 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<boolean> | 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.|
@@ -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
importwififrom'@ohos.wifi';
try{
letnetworkId=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
importwififrom'@ohos.wifi';
try{
letconfig={
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
importwififrom'@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
importwififrom'@ohos.wifi';
try{
letrssi=0;
letband=0;
letlevel=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<[WifiLinkedInfo](#wifilinkedinfo)> | 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<[WifiLinkedInfo](#wifilinkedinfo)> | 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.|
@@ -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<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | 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<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | 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.|
@@ -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<[WifiP2pGroupInfo](#wifip2pgroupinfo8)> | 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<[WifiP2pGroupInfo](#wifip2pgroupinfo8)> | 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
importwififrom'@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<[WifiP2pDevice[]](#wifip2pdevice8)> | 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<[WifiP2pDevice[]](#wifip2pdevice8)> | 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.|
@@ -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
importwififrom'@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
importwififrom'@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
importwififrom'@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
importwififrom'@ohos.wifi';
try{
letnetId=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
importwififrom'@ohos.wifi';
try{
letname="****";
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<number> | No| Callback for the WLAN state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| callback | Callback<number> | 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
importwififrom'@ohos.wifi';
importwififrom'@ohos.wifi';
varrecvPowerNotifyFunc=result=>{
varrecvPowerNotifyFunc=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<number> | 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<number> | No| Callback for the WLAN connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
@@ -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<number> | 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<number> | 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
importwififrom'@ohos.wifi';
varrecvWifiScanStateChangeFunc=result=>{
console.info("Receive Wifi scan state change event: "+result);
@@ -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<number> | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| callback | Callback<number> | No| Callback for the RSSI. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
@@ -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<number> | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| callback | Callback<number> | No| Callback for the P2P state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
**Example**
```js
importwififrom'@ohos.wifi';
varrecvP2pStateChangeFunc=result=>{
console.info("Receive p2p state change event: "+result);
@@ -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<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | 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<[WifiP2pLinkedInfo](#wifip2plinkedinfo8)> | No| Callback for the P2P connection state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
@@ -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<[WifiP2pDevice](#wifip2pdevice8)> | 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<[WifiP2pDevice](#wifip2pdevice8)> | No| Callback for the P2P device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
@@ -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<[WifiP2pDevice[]](#wifip2pdevice8)> | 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<[WifiP2pDevice[]](#wifip2pdevice8)> | No| Callback for the peer device state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
@@ -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<void> | 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<void> | 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
importwififrom'@ohos.wifi';
varrecvP2pPersistentGroupChangeFunc=result=>{
console.info("Receive recv p2p persistent group change event: "+result);
@@ -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<number> | 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<number> | No| Callback for the P2P device discovery state. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
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))
| callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the detected hotspots. Otherwise, **err** is a non-zero value and **data** is empty.|
| Array<[WifiScanInfo](#wifiscaninfo)> | 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).
| 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<number> | Promise used to return the ID of the added network configuration. If **-1** is returned, the network configuration fails to be added.|
| Promise<number> | 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).
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| callback | AsyncCallback<number> | 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<number> | 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).
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| config | [WifiDeviceConfig](#wifideviceconfig) | Yes| WLAN configuration to add.|
| callback | AsyncCallback<number> | 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<number> | 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).
| networkId | number | Yes| ID of the network configuration to remove.|
| networkId | number | Yes| ID of the network configuration to remove.|
| callback | AsyncCallback<void> | 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<void> | 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).
| 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<WifiLinkedInfo>
getLinkedInfo(): Promise<WifiLinkedInfo>
...
@@ -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<[WifiLinkedInfo](#wifilinkedinfo)> | Promise used to return the WLAN connection information obtained.|
| Promise<[WifiLinkedInfo](#wifilinkedinfo)> | 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<[WifiLinkedInfo](#wifilinkedinfo)> | 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<[WifiLinkedInfo](#wifilinkedinfo)> | 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
importwififrom'@ohos.wifi';
importwififrom'@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.
**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)
@@ -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<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | 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<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | 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<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | 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<[WifiP2pGroupInfo](#wifip2pgroupinfo9)> | 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));
| callback | AsyncCallback<[WifiP2pDevice[]](#wifip2pdevice9)> | 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<[WifiP2pDevice[]](#wifip2pdevice9)> | 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).
@@ -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<[WifiP2pDevice](#wifip2pdevice9)> | Promise used to return the local device information obtained.|
| Promise<[WifiP2pDevice](#wifip2pdevice9)> | 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<[WifiP2pDevice](#wifip2pdevice9)> | 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<[WifiP2pDevice](#wifip2pdevice9)> | 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
| callback | AsyncCallback< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | 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< Array<[WifiP2pGroupInfo](#wifip2pgroupinfo9)>> | 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 | string | Yes| Event type. The value is **wifiStateChange**.|
| type | string | Yes| Event type. The value is **wifiStateChange**.|
| callback | Callback<number> | 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<number> | 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.
| type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| type | string | Yes| Event type. The value is **wifiConnectionChange**.|
| callback | Callback<number> | 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<number> | 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 | string | Yes| Event type. The value is **wifiRssiChange**.|
| type | string | Yes| Event type. The value is **wifiRssiChange**.|
| callback | Callback<number> | No| Callback for the RSSI change. If this parameter is not specified, all callbacks associated with the specified event will be unregistered.|
| callback | Callback<number> | 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 | string | Yes| Event type. The value is **hotspotStateChange**.|
| type | string | Yes| Event type. The value is **hotspotStateChange**.|
| callback | Callback<number> | 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<number> | 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
importwififrom'@ohos.wifiManager';
varrecvHotspotStateChangeFunc=result=>{
console.info("Receive hotspot state change event: "+result);
| type | string | Yes| Event type. The value is **p2pStateChange**.|
| type | string | Yes| Event type. The value is **p2pStateChange**.|
| callback | Callback<number> | 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<number> | 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
importwififrom'@ohos.wifiManager';
varrecvP2pStateChangeFunc=result=>{
console.info("Receive p2p state change event: "+result);
| type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| type | string | Yes| Event type. The value is **p2pConnectionChange**.|
| callback | Callback<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | 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<[WifiP2pLinkedInfo](#wifip2plinkedinfo9)> | 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 | string | Yes| Event type. The value is **p2pDeviceChange**.|
| type | string | Yes| Event type. The value is **p2pDeviceChange**.|
| callback | Callback<[WifiP2pDevice](#wifip2pdevice9)> | 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<[WifiP2pDevice](#wifip2pdevice9)> | 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 | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| type | string | Yes| Event type. The value is **p2pPeerDeviceChange**.|
| callback | Callback<[WifiP2pDevice[]](#wifip2pdevice9)> | 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<[WifiP2pDevice[]](#wifip2pdevice9)> | 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 | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| type | string | Yes| Event type. The value is **p2pPersistentGroupChange**.|
| callback | Callback<void> | 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<void> | 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
importwififrom'@ohos.wifiManager';
varrecvP2pPersistentGroupChangeFunc=result=>{
console.info("Receive recv p2p persistent group change event: "+result);
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| type | string | Yes| Event type. The value is **p2pDiscoveryChange**.|
| callback | Callback<number> | 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<number> | 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).