1# @ohos.wifiManagerExt (WLAN扩展接口) 2该模块主要提供WLAN扩展接口,供非通用类型产品使用。 3 4> **说明:** 5> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 6该文档中的接口只供非通用类型产品使用,如路由器等,对于常规类型产品,不应该使用这些接口。 7 8 9## 导入模块 10 11```js 12import { wifiManagerExt } from '@kit.ConnectivityKit'; 13``` 14 15## wifiManagerExt.enableHotspot<sup>9+</sup> 16 17enableHotspot(): void; 18 19使能WLAN热点。 20 21> **说明:** 22> 从 API version 9开始支持,从API version 10开始废弃。 23 24**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 25 26**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 27 28**错误码:** 29 30以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 31 32| **错误码ID** | **错误信息** | 33 | -------- | -------- | 34| 201 | Permission denied. | 35| 801 | Capability not supported. | 36| 2701000 | Operation failed. | 37 38**示例:** 39 40```ts 41 import { wifiManagerExt } from '@kit.ConnectivityKit'; 42 43 try { 44 wifiManagerExt.enableHotspot(); 45 }catch(error){ 46 console.error("failed:" + JSON.stringify(error)); 47 } 48``` 49 50## wifiManagerExt.disableHotspot<sup>9+</sup> 51 52disableHotspot(): void; 53 54去使能WLAN热点。 55 56> **说明:** 57> 从 API version 9开始支持,从API version 10开始废弃。 58 59**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 60 61**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 62 63**错误码:** 64 65以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 66 67| **错误码ID** | **错误信息** | 68 | -------- | -------- | 69| 201 | Permission denied. | 70| 801 | Capability not supported. | 71| 2701000 | Operation failed. | 72 73**示例:** 74 75```ts 76 import { wifiManagerExt } from '@kit.ConnectivityKit'; 77 78 try { 79 wifiManagerExt.disableHotspot(); 80 }catch(error){ 81 console.error("failed:" + JSON.stringify(error)); 82 } 83``` 84 85## wifiManagerExt.getSupportedPowerMode<sup>9+</sup> 86 87getSupportedPowerMode(): Promise<Array<PowerMode>> 88 89获取支持的功率模式,使用Promise异步回调。 90 91**需要权限:** ohos.permission.GET_WIFI_INFO 92 93**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 94 95**返回值:** 96 97 | 类型 | 说明 | 98 | -------- | -------- | 99 | Promise<Array<[PowerMode](#powermode9)>> | Promise对象。表示功率模式。 | 100 101**错误码:** 102 103以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 104 105| **错误码ID** | **错误信息** | 106 | -------- | -------- | 107| 201 | Permission denied. | 108| 801 | Capability not supported. | 109| 2701000 | Operation failed. | 110## PowerMode<sup>9+</sup> 111 112表示功率模式的枚举。 113 114**系统能力:** SystemCapability.Ability.AbilityRuntime.Core 115 116| 名称 | 值 | 说明 | 117| -------- | -------- | -------- | 118| SLEEPING | 0 | 睡眠模式。 | 119| GENERAL | 1 | 常规模式。 | 120| THROUGH_WALL | 2 | 穿墙模式。 | 121 122 123## wifiManagerExt.getSupportedPowerMode<sup>9+</sup> 124 125getSupportedPowerMode(callback: AsyncCallback<Array<PowerMode>>): void 126 127获取支持的功率模式,使用callback异步回调。 128 129**需要权限:** ohos.permission.GET_WIFI_INFO 130 131**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 132 133**参数:** 134 135 | 参数名 | 类型 | 必填 | 说明 | 136 | -------- | -------- | -------- | -------- | 137 | callback | AsyncCallback<Array<[PowerMode](#powermode9)>> | 是 | 回调函数。当操作成功时,err为0,data表示支持的功率模式。如果err为非0,表示处理出现错误。 | 138 139**错误码:** 140 141以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 142 143| **错误码ID** | **错误信息** | 144 | -------- | -------- | 145| 201 | Permission denied. | 146| 801 | Capability not supported. | 147| 2701000 | Operation failed. | 148 149**示例:** 150 151```ts 152 import { wifiManagerExt } from '@kit.ConnectivityKit'; 153 154 wifiManagerExt.getSupportedPowerMode((err, data:wifiManagerExt.PowerMode) => { 155 if (err) { 156 console.error("get supported power mode info error"); 157 return; 158 } 159 console.info("get supported power mode info: " + JSON.stringify(data)); 160 }); 161 162 wifiManagerExt.getSupportedPowerMode().then(data => { 163 console.info("get supported power mode info: " + JSON.stringify(data)); 164 }).catch((error:number) => { 165 console.info("get supported power mode error"); 166 }); 167``` 168 169## wifiManagerExt.getPowerMode<sup>9+</sup> 170 171getPowerMode(): Promise<PowerMode> 172 173获取功率模式,使用Promise异步回调。 174 175> **说明:** 176> 从 API version 9开始支持,从API version 10开始废弃。 177 178**需要权限:** ohos.permission.GET_WIFI_INFO 179 180**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 181 182**返回值:** 183 184 | 类型 | 说明 | 185 | -------- | -------- | 186 | Promise<[PowerMode](#powermode9)> | Promise对象。表示功率模式。 | 187 188**错误码:** 189 190以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 191 192| **错误码ID** | **错误信息** | 193 | -------- | -------- | 194| 201 | Permission denied. | 195| 801 | Capability not supported. | 196| 2701000 | Operation failed. | 197 198**示例:** 199 200```ts 201 import { wifiManagerExt } from '@kit.ConnectivityKit'; 202 203 try { 204 let model = wifiManagerExt.getPowerMode(); 205 console.info("model info:" + model); 206 }catch(error){ 207 console.error("failed:" + JSON.stringify(error)); 208 } 209``` 210 211## wifiManagerExt.getPowerMode<sup>9+</sup> 212 213getPowerMode(callback: AsyncCallback<PowerMode>): void 214 215获取功率模式,使用callback异步回调。 216 217**需要权限:** ohos.permission.GET_WIFI_INFO 218 219**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 220 221**参数:** 222 223 | 参数名 | 类型 | 必填 | 说明 | 224 | -------- | -------- | -------- | -------- | 225 | callback | AsyncCallback<[PowerMode](#powermode9)> | 是 | 回调函数。当操作成功时,err为0,data表示功率模式。如果err为非0,表示处理出现错误。 | 226 227**错误码:** 228 229以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 230 231| **错误码ID** | **错误信息** | 232 | -------- | -------- | 233| 201 | Permission denied. | 234| 801 | Capability not supported. | 235| 2701000 | Operation failed. | 236 237**示例:** 238 239```ts 240 import { wifiManagerExt } from '@kit.ConnectivityKit'; 241 242 wifiManagerExt.getPowerMode((err, data:wifiManagerExt.PowerMode) => { 243 if (err) { 244 console.error("get linked info error"); 245 return; 246 } 247 console.info("get power mode info: " + JSON.stringify(data)); 248 }); 249 250 wifiManagerExt.getPowerMode().then(data => { 251 console.info("get power mode info: " + JSON.stringify(data)); 252 }).catch((error:number) => { 253 console.info("get power mode error"); 254 }); 255``` 256 257## wifiManagerExt.setPowerMode<sup>9+</sup> 258 259setPowerMode(mode: PowerMode) : void; 260 261 设置功率模式。 262 263> **说明:** 264> 从 API version 9开始支持,从API version 10开始废弃。 265 266**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT_EXT 267 268**系统能力:** SystemCapability.Communication.WiFi.AP.Extension 269 270**参数:** 271 272| 参数名 | 类型 | 必填 | 说明 | 273| -------- | -------- | -------- | -------- | 274| mode | [PowerMode](#powermode9) | 是 | 功率模式。 | 275 276**错误码:** 277 278以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 279 280| **错误码ID** | **错误信息** | 281 | -------- | -------- | 282| 201 | Permission denied. | 283| 801 | Capability not supported. | 284| 2701000 | Operation failed. | 285 286**示例:** 287 288```ts 289 import { wifiManagerExt } from '@kit.ConnectivityKit'; 290 291 try { 292 let model = 0; 293 wifiManagerExt.setPowerMode(model); 294 }catch(error){ 295 console.error("failed:" + JSON.stringify(error)); 296 } 297``` 298