@ohos.wifiManagerExt (WLAN Extension)
The wifiManagerExt module provides WLAN extension APIs for non-universal products.
NOTE The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. The APIs described in this document are used only for non-universal products, such as routers.
Modules to Import
import { wifiManagerExt } from '@kit.ConnectivityKit';
wifiManagerExt.enableHotspot(deprecated)
enableHotspot(): void
Enables the WLAN hotspot.
NOTE This API is supported since API version 9 and deprecated since API version 10.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
System capability: SystemCapability.Communication.WiFi.AP.Extension
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
try {
wifiManagerExt.enableHotspot();
}catch(error){
console.error("failed: " + JSON.stringify(error));
}
wifiManagerExt.disableHotspot(deprecated)
disableHotspot(): void
Disables the WLAN hotspot.
NOTE This API is supported since API version 9 and deprecated since API version 10.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
System capability: SystemCapability.Communication.WiFi.AP.Extension
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
try {
wifiManagerExt.disableHotspot();
}catch(error){
console.error("failed: " + JSON.stringify(error));
}
wifiManagerExt.getSupportedPowerMode
getSupportedPowerMode(): Promise<Array<PowerMode>>
Obtains the supported power models. This API uses a promise to return the result.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.AP.Extension
Return value
| Type | Description |
|---|---|
| Promise<Array<PowerMode>> | Promise used to return the power modes obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
PowerMode
Enumerates the power modes.
System capability: SystemCapability.Communication.WiFi.AP.Extension
| Name | Value | Description |
|---|---|---|
| SLEEPING | 0 | Sleeping |
| GENERAL | 1 | General |
| THROUGH_WALL | 2 | Through_wall |
wifiManagerExt.getSupportedPowerMode
getSupportedPowerMode(callback: AsyncCallback<Array<PowerMode>>): void
Obtains the supported power models. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.AP.Extension
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<Array<PowerMode>> | Yes | Callback used to return the result. If the operation is successful, err is 0 and data is the power modes obtained. If the operation fails, err is not 0. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
wifiManagerExt.getSupportedPowerMode((err, data: wifiManagerExt.PowerMode[]) => {
if (err) {
console.error("get supported power mode info error: ", err);
return;
}
console.info("get supported power mode info: " + JSON.stringify(data));
});
wifiManagerExt.getPowerMode
getPowerMode(): Promise<PowerMode>
Obtains the power mode. This API uses a promise to return the result.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.AP.Extension
Return value
| Type | Description |
|---|---|
| Promise<PowerMode> | Promise used to return the power modes obtained. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
try {
let model = wifiManagerExt.getPowerMode();
console.info("model info:" + model);
}catch(error){
console.error("failed: " + JSON.stringify(error));
}
wifiManagerExt.getPowerMode
getPowerMode(callback: AsyncCallback<PowerMode>): void
Obtains the power mode. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.GET_WIFI_INFO
System capability: SystemCapability.Communication.WiFi.AP.Extension
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<PowerMode> | Yes | Callback used to return the result. If the operation is successful, err is 0 and data is the power mode obtained. If the operation fails, err is not 0. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
wifiManagerExt.getPowerMode((err, data:wifiManagerExt.PowerMode) => {
if (err) {
console.error("Failed to get linked information");
return;
}
console.info("get power mode info: " + JSON.stringify(data));
});
wifiManagerExt.getPowerMode().then(data => {
console.info("get power mode info: " + JSON.stringify(data));
}).catch((error:number) => {
console.error("get power mode error");
});
wifiManagerExt.setPowerMode(deprecated)
setPowerMode(mode: PowerMode) : void
Sets the power mode.
NOTE This API is supported since API version 9 and deprecated since API version 10.
Required permissions: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
System capability: SystemCapability.Communication.WiFi.AP.Extension
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| mode | PowerMode | Yes | Power mode to set. |
Error codes
For details about the error codes, see Wi-Fi Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permission denied. |
| 801 | Capability not supported. |
| 2701000 | Operation failed. |
Example
import { wifiManagerExt } from '@kit.ConnectivityKit';
try {
let model = 0;
wifiManagerExt.setPowerMode(model);
}catch(error){
console.error("failed: " + JSON.stringify(error));
}