harmony 鸿蒙@ohos.wifiManager (WLAN) (System API)
@ohos.wifiManager (WLAN) (System API)
The WLAN module provides basic wireless local area network (WLAN) functions, peer-to-peer (P2P) functions, and WLAN message notification services. It allows applications to communicate with devices over WLAN.
NOTE The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. This topic describes only the system APIs provided by the module. For details about its public APIs, see @ohos.wifiManager (WLAN).
Modules to Import
import { wifiManager } from '@kit.ConnectivityKit';
wifiManager.disableWifi9+
disableWifi(): void
Disables WLAN. This is an asynchronous API. You need to register a callback for the wifiStateChange event to check whether WLAN is successfully disabled.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501004 | Operation failed because the service is being opened. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.disableWifi();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.enableSemiWifi12+
enableSemiWifi(): void
Enables WLAN partially, that is, enables P2P and Huawei Magneto Link (HML) while disabling STA. You need to register a callback for the wifiStateChange event to return the operation result.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501004 | Operation failed because the service is being opened. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.enableSemiWifi();
} catch(error) {
console.error("failed:" + JSON.stringify(error));
}
wifiManager.startScan10+
startScan(): void
System API: This is a system API.
Starts a scan for WLAN.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.startScan();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.setScanAlwaysAllowed10+
setScanAlwaysAllowed(isScanAlwaysAllowed: boolean): void
Sets whether scan is always allowed.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
isScanAlwaysAllowed | boolean | Yes | Whether scan is always allowed. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2501000 | Operation failed. |
import { wifiManager } from '@kit.ConnectivityKit';
try {
let isScanAlwaysAllowed = true;
wifiManager.setScanAlwaysAllowed(isScanAlwaysAllowed);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getScanAlwaysAllowed10+
getScanAlwaysAllowed(): boolean
Obtains whether scan is always allowed.
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
Return value
Type | Description |
---|---|
boolean | Whether scan is always allowed. The value true means scan is allowed, and the value false means the opposite. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let isScanAlwaysAllowed = wifiManager.getScanAlwaysAllowed();
console.info("isScanAlwaysAllowed:" + isScanAlwaysAllowed);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
WifiDeviceConfig9+
Represents the WLAN configuration.
System capability: SystemCapability.Communication.WiFi.STA
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
creatorUid | number | Yes | No | ID of the creator. System API: This is a system API. |
disableReason | number | Yes | No | Reason for disabling Wi-Fi. -1: unknown reason 0: not disabled 1: association refused 2: authentication failed 3: DHCP failure 4: no Internet connection 5: no authentication credentials 6: no Internet connection permanently 7: disabled by Wi-Fi manager 8: disabled due to incorrect password 9: authentication without subscription 10: private EAP authentication error 11: network not found 12: consecutive failures 13: disabled by the system 14: EAP-AKA authentication failed 15: association removed 16: maximum number of forbidden network selections System API: This is a system API. |
netId | number | Yes | No | Network ID. System API: This is a system API. |
randomMacType | number | Yes | No | MAC address type. The value 0 indicates a random MAC address, and the value 1 indicates a device MAC address. System API: This is a system API. |
randomMacAddr | string | Yes | No | MAC address. System API: This is a system API. |
ipType | IpType | Yes | No | IP address type. System API: This is a system API. |
staticIp | IpConfig | Yes | No | Static IP address information. System API: This is a system API. |
proxyConfig10+ | WifiProxyConfig | Yes | No | Proxy configuration. System API: This is a system API. |
configStatus12+ | number | Yes | No | Status indicating whether the current network can be selected. 1: network selection allowed 2: network selection forbidden 3: network selection permanently forbidden 4: unknown System API: This is a system API. |
IpType9+
Enumerates the IP address types.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Value | Description |
---|---|---|
STATIC | 0 | Static IP address. |
DHCP | 1 | IP address allocated by DHCP. |
UNKNOWN | 2 | Not specified. |
IpConfig9+
Represents IP configuration information.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
ipAddress | number | Yes | No | IP address. |
gateway | number | Yes | No | Gateway. |
prefixLength | number | Yes | No | Subnet mask. |
dnsServers | number[] | Yes | No | Domain name server (DNS) information. |
domains | Array<string> | Yes | No | Domain information. |
WifiProxyConfig10+
Represents the Wi-Fi proxy configuration.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
proxyMethod | ProxyMethod | Yes | No | Proxy method. |
pacWebAddress | string | Yes | No | PAC web address of the proxy automatically configured. |
serverHostName | string | Yes | No | Server host name of the proxy manually configured. |
serverPort | number | Yes | No | Server port of the proxy manually configured. |
exclusionObjects | string | Yes | No | Excluded objects of the manually configured proxy. Multiple objects are separated by commas (,). |
ProxyMethod10+
Enumerates the Wi-Fi proxy methods.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Value | Description |
---|---|---|
METHOD_NONE | 0 | No proxy. |
METHOD_AUTO | 1 | Use an automatically configured proxy. |
METHOD_MANUAL | 2 | Use a manually configured proxy. |
wifiManager.connectToDevice9+
connectToDevice(config: WifiDeviceConfig): void
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.
Required permissions: ohos.permission.SET_WIFI_INFO, ohos.permission.SET_WIFI_CONFIG, and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
config | WifiDeviceConfig | Yes | WLAN configuration to add. The default bssidType is random device address. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config:wifiManager.WifiDeviceConfig = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
wifiManager.connectToDevice(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
WifiLinkedInfo9+
Represents the WLAN connection information.
System capability: SystemCapability.Communication.WiFi.STA
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
networkId | number | Yes | No | Network configuration ID. System API: This is a system API. |
chload | number | Yes | No | Channel load. A larger value indicates a higher load. System API: This is a system API. |
snr | number | Yes | No | Signal-to-noise ratio (SNR). System API: This is a system API. |
suppState | SuppState | Yes | No | Supplicant state. System API: This is a system API. |
SuppState9+
Enumerates the supplicant states.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Value | Description |
---|---|---|
DISCONNECTED | 0 | The supplicant is disconnected from the AP. |
INTERFACE_DISABLED | 1 | The network interface is disabled. |
INACTIVE | 2 | The supplicant is inactive. |
SCANNING | 3 | The supplicant is scanning for a WLAN connection. |
AUTHENTICATING | 4 | The supplicant is being authenticated. |
ASSOCIATING | 5 | The supplicant is being associated with an AP. |
ASSOCIATED | 6 | The supplicant is associated with an AP. |
FOUR_WAY_HANDSHAKE | 7 | A four-way handshake is being performed for the supplicant. |
GROUP_HANDSHAKE | 8 | A group handshake is being performed for the supplicant. |
COMPLETED | 9 | The authentication is complete. |
UNINITIALIZED | 10 | The supplicant failed to set up the connection. |
INVALID | 11 | Invalid value. |
wifiManager.getSupportedFeatures9+
getSupportedFeatures(): number
Obtains the features supported by this device.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.Core
Return value
Type | Description |
---|---|
number | Feature value. |
Feature IDs
Value | Description |
---|---|
0x0001 | WLAN infrastructure mode |
0x0002 | 5 GHz feature |
0x0004 | Generic Advertisement Service (GAS)/Access Network Query Protocol (ANQP) feature |
0x0008 | Wi-Fi Direct |
0x0010 | SoftAP |
0x0040 | Wi-Fi Aware |
0x8000 | WLAN AP/STA concurrency |
0x8000000 | WPA3 Personal (WPA-3 SAE) |
0x10000000 | WPA3-Enterprise Suite B |
0x20000000 | Enhanced open feature |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2401000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let ret = wifiManager.getSupportedFeatures();
console.info("supportedFeatures:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getDeviceMacAddress15+
getDeviceMacAddress(): string[]
Obtains the device MAC address.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_LOCAL_MAC and ohos.permission.GET_WIFI_INFO (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Return value
Type | Description |
---|---|
string[] | MAC address obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let ret = wifiManager.getDeviceMacAddress();
console.info("deviceMacAddress:" + JSON.stringify(ret));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getWifiDetailState12+
getWifiDetailState(): WifiDetailState
Obtains the Wi-Fi state.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Return value
Type | Description |
---|---|
WifiDetailState | Wi-Fi state obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let ret = wifiManager.getWifiDetailState();
console.info("wifiDetailState:" + ret);
} catch(error) {
console.error("failed:" + JSON.stringify(error));
}
WifiDetailState12+
Enumerates Wi-Fi states.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Value | Description |
---|---|---|
UNKNOWN | -1 | Unidentified. |
INACTIVE | 0 | Inactive. |
ACTIVATED | 1 | Activated. |
ACTIVATING | 2 | Activating. |
DEACTIVATING | 3 | Deactivating |
SEMI_ACTIVATING | 4 | Partially activating. |
SEMI_ACTIVE | 5 | partially activated. |
wifiManager.reassociate9+
reassociate(): void
Re-associates with the network.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.reassociate();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.reconnect9+
reconnect(): void
Reconnects to the network.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.reconnect();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.updateNetwork9+
updateNetwork(config: WifiDeviceConfig): number
Updates network configuration.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
config | WifiDeviceConfig | Yes | New WLAN configuration. |
Return value
Type | Description |
---|---|
number | ID of the updated network configuration. The value -1 indicates that the operation has failed. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config:wifiManager.WifiDeviceConfig = {
ssid : "****",
preSharedKey : "****",
securityType : 3
}
let ret = wifiManager.updateNetwork(config);
console.info("ret:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.disableNetwork9+
disableNetwork(netId: number): void
Disables network configuration.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
netId | number | Yes | ID of the network configuration to disable. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let netId = 0;
wifiManager.disableNetwork(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.removeAllNetwork9+
removeAllNetwork(): void
Removes the configuration of all networks.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.removeAllNetwork();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.get5GChannelList10+
get5GChannelList(): Array<number>
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
Return value
Type | Description |
---|---|
Array<number> | List of 5 GHz channels supported by the device. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let channelList = wifiManager.get5GChannelList();
console.info("channelList:" + JSON.stringify(channelList));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getDisconnectedReason10+
getDisconnectedReason(): DisconnectedReason
Obtains the reason of the latest disconnection.
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.
ID | Error Message |
---|---|
201 | Permission denied. |
801 | Capability not supported. |
2501000 | Operation failed. |
Return value
Type | Description |
---|---|
DisconnectedReason | Returns the reason of the latest disconnection obtained. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let disconnectedReason = wifiManager.getDisconnectedReason();
console.info("disconnectedReason:" + disconnectedReason);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
DisconnectedReason 10+
Enumerates the Wi-Fi disconnection reasons.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.STA
Name | Value | Description |
---|---|---|
DISC_REASON_DEFAULT | 0 | Default reason. |
DISC_REASON_WRONG_PWD | 1 | Incorrect password. |
DISC_REASON_CONNECTION_FULL | 2 | The number of connections to the router has reached the limit. |
wifiManager.startPortalCertification11+
startPortalCertification(): void
System API: This is a system API.
Starts portal certification.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.startPortalCertification();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.enableHiLinkHandshake12+
enableHiLinkHandshake(isHiLinkEnable: boolean, bssid: string, config: WifiDeviceConfig): void
System API: This is a system API.
Enables or disables HiLink.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
isHiLinkEnable | boolean | Yes | Whether to enable hiLink. The value true means to enable HiLink, and the value false means the opposite. |
bssid | string | Yes | MAC address of the hotspot, for example, 00:11:22:33:44:55. |
config | WifiDeviceConfig | Yes | WLAN configuration information. The value of config.bssid must be the same as that of the second parameter bssid. The default bssidType is random device address. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
801 | Capability not supported. |
2501000 | Operation failed. |
2501001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
// You can obtain config data by using getScanInfoList, which can be used only when WifiScanInfo.isHiLinkNetwork is true.
let config:wifiManager.WifiDeviceConfig = {
ssid : "****",
preSharedKey : "****",
securityType : 0,
bssid : "38:37:8b:80:bf:cc",
bssidType : 1,
isHiddenSsid : false
}
try {
wifiManager.enableHiLinkHandshake(true, config.bssid, config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.factoryReset11+
factoryReset(): void
System API: This is a system API.
Resets Wi-Fi configurations.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.SET_WIFI_CONFIG
System capability: SystemCapability.Communication.WiFi.STA
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.factoryReset();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.enableHotspot9+
enableHotspot(): void
Enables this hotspot. This API is an asynchronous interface. The hotspotStateChange callback must be registered and listened for.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.enableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.disableHotspot9+
disableHotspot(): void
Disables this hotspot. This API is an asynchronous interface. The hotspotStateChange callback must be registered and listened for.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
wifiManager.disableHotspot();
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.isHotspotDualBandSupported9+
isHotspotDualBandSupported(): boolean
Checks whether the hotspot supports dual band.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Return value
Type | Description |
---|---|
boolean | Whether the hotspot supports dual band. The value true indicates dual band is supported, and the value false indicates the opposite. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let ret = wifiManager.isHotspotDualBandSupported();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.isOpenSoftApAllowed18+
isOpenSoftApAllowed(): boolean
Checks whether the hotspot supports dual band.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Return value
Type | Description |
---|---|
boolean | Whether the hotspot supports dual band. The value true indicates dual band is supported, and the value false indicates the opposite. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let ret = wifiManager.isOpenSoftApAllowed();
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.setHotspotConfig9+
setHotspotConfig(config: HotspotConfig): void
Sets hotspot configuration.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.GET_WIFI_CONFIG
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
config | HotspotConfig | Yes | Hotspot configuration to set. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Incorrect parameter types. 2. Parameter verification failed. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config:wifiManager.HotspotConfig = {
ssid: "****",
securityType: 3,
band: 0,
channel: 0,
preSharedKey: "****",
maxConn: 0
}
let ret = wifiManager.setHotspotConfig(config);
console.info("result:" + ret);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
HotspotConfig9+
Represents the hotspot configuration.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.AP.Core
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
ssid | string | Yes | Yes | SSID of the hotspot, in UTF-8 format. |
securityType | WifiSecurityType | Yes | Yes | Security type. |
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. |
channel10+ | number | Yes | Yes | Hotspot channel (channels 1 to 14 for 2.4 GHz, and channels 7 to 196 for 5 GHz) |
preSharedKey | string | Yes | Yes | PSK of the hotspot. |
maxConn | number | Yes | Yes | Maximum number of connections allowed. |
wifiManager.getHotspotConfig9+
getHotspotConfig(): HotspotConfig
Obtains hotspot configuration.
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.AP.Core
Return value
Type | Description |
---|---|
HotspotConfig | Hotspot configuration obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config = wifiManager.getHotspotConfig();
console.info("result:" + JSON.stringify(config));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getStations9+
getStations(): Array<StationInfo>
Obtains information about the connected stations.
System API: This is a system API.
Required permissions:
API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, ohos.permission.APPROXIMATELY_LOCATION, and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only)
API version 10 and later: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (for system applications only)
System capability: SystemCapability.Communication.WiFi.AP.Core
Return value
Type | Description |
---|---|
Array<StationInfo> | Connected stations obtained. If the application has the ohos.permission.GET_WIFI_PEERS_MAC permission, macAddress in the return value is a real MAC address; otherwise, macAddress is a random MAC address. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let stations = wifiManager.getStations();
console.info("result:" + JSON.stringify(stations));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
StationInfo9+
Represents the station information.
System API: This is a system API.
System capability: SystemCapability.Communication.WiFi.AP.Core
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
name | string | Yes | No | Device name. |
macAddress | string | Yes | No | MAC address. |
macAddressType10+ | DeviceAddressType | Yes | No | MAC address type. |
ipAddress | string | Yes | No | IP address. |
wifiManager.addHotspotBlockList11+
addHotspotBlockList(stationInfo: StationInfo)
Adds a device to the list of blocked devices of the hotspot. Devices in the list cannot access the hotspot.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
stationInfo | StationInfo | Yes | Device to add. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Incorrect parameter types. 2. Parameter verification failed. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config:wifiManager.StationInfo = {
name : "testSsid",
macAddress : "11:22:33:44:55:66",
ipAddress : "192.168.1.111"
}
// The device can be added to the block list only after the hotspot is enabled.
wifiManager.addHotspotBlockList(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.delHotspotBlockList11+
delHotspotBlockList(stationInfo: StationInfo)
Deletes a device from the list of blocked devices of the hotspot.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
stationInfo | StationInfo | Yes | Device to delete. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Incorrect parameter types. 2. Parameter verification failed. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let config:wifiManager.StationInfo = {
name : "testSsid",
macAddress : "11:22:33:44:55:66",
ipAddress : "192.168.1.111"
}
wifiManager.delHotspotBlockList(config);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getHotspotBlockList11+
getHotspotBlockList(): Array<StationInfo>
Obtains the list of blocked devices of the hotspot.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO and ohos.permission.MANAGE_WIFI_HOTSPOT (available only to system applications)
System capability: SystemCapability.Communication.WiFi.AP.Core
Return value
Type | Description |
---|---|
Array<StationInfo> | List of blocked devices obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let data = wifiManager.getHotspotBlockList();
console.info("result:" + JSON.stringify(data));
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.deletePersistentGroup9+
deletePersistentGroup(netId: number): void
Deletes a persistent group.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.P2P
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
netId | number | Yes | ID of the group to delete. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1.Incorrect parameter types. |
801 | Capability not supported. |
2801000 | Operation failed. |
2801001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let netId = 0;
wifiManager.deletePersistentGroup(netId);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.getP2pGroups9+
getP2pGroups(): Promise<Array<WifiP2pGroupInfo>>
Obtains information about all P2P groups. This API uses a promise to return the result.
System API: This is a system API.
Required permissions:
API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
API version 10 and later : ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.P2P
Return value
Type | Description |
---|---|
Promise< Array<WifiP2pGroupInfo> > | Promise used to return the group information obtained. If the application has the ohos.permission.GET_WIFI_PEERS_MAC permission, deviceAddress in the return value is a real device address; otherwise, deviceAddress is a random device address. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2801000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
wifiManager.getP2pGroups((err, data:wifiManager.WifiP2pGroupInfo) => {
if (err) {
console.error("get P2P groups error");
return;
}
console.info("get P2P groups: " + JSON.stringify(data));
});
wifiManager.getP2pGroups().then(data => {
console.info("get P2P groups: " + JSON.stringify(data));
});
wifiManager.getP2pGroups9+
getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void
Obtains information about all P2P groups. This API uses an asynchronous callback to return the result.
System API: This is a system API.
Required permissions:
API version 9: ohos.permission.GET_WIFI_INFO, ohos.permission.LOCATION, and ohos.permission.APPROXIMATELY_LOCATION
API version 10 and later : ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.P2P
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback< Array<WifiP2pGroupInfo>> | Yes | Callback used to return the result. If the operation is successful, error is 0 and data is the group information obtained. If the operation fails, error is not 0. If the application has the ohos.permission.GET_WIFI_PEERS_MAC permission, deviceAddress in the return value is a real device address; otherwise, deviceAddress is a random device address. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
801 | Capability not supported. |
2801000 | Operation failed. |
2801001 | Wi-Fi STA disabled. |
wifiManager.setDeviceName9+
setDeviceName(devName: string): void
Sets the device name.
System API: This is a system API.
Required permissions: ohos.permission.SET_WIFI_INFO and ohos.permission.MANAGE_WIFI_CONNECTION (available only to system applications)
System capability: SystemCapability.Communication.WiFi.P2P
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
devName | string | Yes | Device name to set. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. |
801 | Capability not supported. |
2801000 | Operation failed. |
2801001 | Wi-Fi STA disabled. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
try {
let name = "****";
wifiManager.setDeviceName(name);
}catch(error){
console.error("failed:" + JSON.stringify(error));
}
wifiManager.on(‘streamChange’)9+
on(type: ‘streamChange’, callback: Callback<number>): void
Subscribes to Wi-Fi stream changes. When the service exits, call off(type: ‘streamChange’, callback?: Callback<number>) to unregister the callback registered.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of streamChange. |
callback | Callback<number> | Yes | Callback used to return the Wi-Fi stream change, which can be any of the following values: - 0: No stream. - 1: Downward. - 2: Upward. - 3: Bidirectional. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2501000 | Operation failed. |
wifiManager.off(‘streamChange’)9+
off(type: ‘streamChange’, callback?: Callback<number>): void
Unsubscribes from Wi-Fi stream changes.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_CONNECTION
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of streamChange. |
callback | Callback<number> | No | Callback to unregister. The stream change can be any of the following values: - 0: No stream. - 1: Downward. - 2: Upward. - 3: Bidirectional. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifi } from '@kit.ConnectivityKit';
let recvStreamChangeFunc = (result:number) => {
console.info("Receive stream change event: " + result);
}
// Register an event.
wifi.on("streamChange", recvStreamChangeFunc);
// Unregister an event.
wifi.off("streamChange", recvStreamChangeFunc);
wifiManager.on(‘deviceConfigChange’)9+
on(type: ‘deviceConfigChange’, callback: Callback<number>): void
Subscribes to Wi-Fi device configuration changes. When the service exits, call off(type: ‘deviceConfigChange’, callback?: Callback<number>) to unregister the callback registered.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of deviceConfigChange. |
callback | Callback<number> | Yes | Callback for device configuration changes. 0: Configuration is added. 1: Configuration is modified. 2: Configuration is deleted. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2501000 | Operation failed. |
wifiManager.off(‘deviceConfigChange’)9+
off(type: ‘deviceConfigChange’, callback?: Callback<number>): void
Unsubscribes from Wi-Fi device configuration changes.
System API: This is a system API.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.STA
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of deviceConfigChange. |
callback | Callback<number> | No | Callback for device configuration changes. 0: Configuration is added. 1: Configuration is modified. 2: Configuration is deleted. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2501000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
let recvDeviceConfigChangeFunc = (result:number) => {
console.info("Receive device config change event: " + result);
}
// Register an event.
wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc);
// Unregister an event.
wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc);
wifiManager.on(‘hotspotStaJoin’)9+
on(type: ‘hotspotStaJoin’, callback: Callback<StationInfo>): void
Subscribes to the event of an STA joining a Wi-Fi hotspot. When the service exits, call off(type: ‘hotspotStaJoin’, callback?: Callback<StationInfo>) to unregister the callback registered.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of hotspotStaJoin. |
callback | Callback<StationInfo> | Yes | Callback used to return the event. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2601000 | Operation failed. |
wifiManager.off(‘hotspotStaJoin’)9+
off(type: ‘hotspotStaJoin’, callback?: Callback<StationInfo>): void
Unsubscribes from the event of an STA joining a Wi-Fi hotspot.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of hotspotStaJoin. |
callback | Callback<StationInfo> | No | Callback to unregister. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => {
console.info("Receive hotspot sta join event: " + result);
}
// Register an event.
wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc);
// Unregister an event.
wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc);
wifiManager.on(‘hotspotStaLeave’)9+
on(type: ‘hotspotStaLeave’, callback: Callback<StationInfo>): void
Subscribes to the event of an STA leaving a Wi-Fi hotspot. When the service exits, call off(type: ‘hotspotStaLeave’, callback?: Callback<StationInfo>) to unregister the callback registered.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of hotspotStaLeave. |
callback | Callback<StationInf]> | Yes | Callback used to return the event. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2601000 | Operation failed. |
wifiManager.off(‘hotspotStaLeave’)9+
off(type: ‘hotspotStaLeave’, callback?: Callback<StationInfo>): void
Unsubscribes from the event of an STA leaving a Wi-Fi hotspot.
System API: This is a system API.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT
System capability: SystemCapability.Communication.WiFi.AP.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
type | string | Yes | Event type, which has a fixed value of hotspotStaLeave. |
callback | Callback<StationInf]> | No | Callback to unregister. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | System API is not allowed called by Non-system application. |
401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
801 | Capability not supported. |
2601000 | Operation failed. |
Example
import { wifiManager } from '@kit.ConnectivityKit';
let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => {
console.info("Receive hotspot sta leave event: " + result);
}
// Register an event.
wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc);
// Unregister an event.
wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc);
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Connectivity Kit (Short-Range Communication Service)
harmony 鸿蒙Bluetooth Error Codes
harmony 鸿蒙SecureElement Error Codes
harmony 鸿蒙@ohos.bluetooth.a2dp (Bluetooth A2DP Module) (System API)
harmony 鸿蒙@ohos.bluetooth.a2dp (Bluetooth A2DP Module)
harmony 鸿蒙@ohos.bluetooth.access (Bluetooth Access Module) (System API)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦