1# @ohos.wifiManager (WLAN)(系统接口) 2该模块主要提供WLAN基础功能、P2P(peer-to-peer)功能和WLAN消息通知的相应服务,让应用可以通过WLAN和其他设备互联互通。 3 4> **说明:** 5> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 6> 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.wifiManager (WLAN)](js-apis-wifiManager.md) 7 8## 导入模块 9 10```ts 11import { wifiManager } from '@kit.ConnectivityKit'; 12``` 13 14## wifiManager.enableWifi<sup>9+</sup> 15 16enableWifi(): void 17 18使能WLAN,异步接口,需要通过注册"wifiStateChange"事件的回调来监听是否打开成功。 19 20**系统接口:** 此接口为系统接口。 21 22**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION 仅系统应用可用。 23 24**系统能力:** SystemCapability.Communication.WiFi.STA 25 26**错误码:** 27 28以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 29 30| **错误码ID** | **错误信息** | 31| -------- | -------- | 32| 201 | Permission denied. | 33| 202 | System API is not allowed called by Non-system application. | 34| 801 | Capability not supported. | 35| 2501000 | Operation failed.| 36| 2501003 | Operation failed because the service is being closed. | 37 38**示例:** 39 40```ts 41 import { wifiManager } from '@kit.ConnectivityKit'; 42 43 try { 44 wifiManager.enableWifi(); 45 }catch(error){ 46 console.error("failed:" + JSON.stringify(error)); 47 } 48``` 49 50## wifiManager.disableWifi<sup>9+</sup> 51 52disableWifi(): void 53 54去使能WLAN,异步接口,需要通过注册"wifiStateChange"事件的回调来监听是否关闭成功。 55 56**系统接口:** 此接口为系统接口。 57 58**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 59 60**系统能力:** SystemCapability.Communication.WiFi.STA 61 62**错误码:** 63 64以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 65 66| **错误码ID** | **错误信息** | 67| -------- | -------- | 68| 201 | Permission denied. | 69| 202 | System API is not allowed called by Non-system application. | 70| 801 | Capability not supported. | 71| 2501000 | Operation failed.| 72| 2501004 | Operation failed because the service is being opened. | 73 74**示例:** 75 76```ts 77 import { wifiManager } from '@kit.ConnectivityKit'; 78 79 try { 80 wifiManager.disableWifi(); 81 }catch(error){ 82 console.error("failed:" + JSON.stringify(error)); 83 } 84``` 85 86## wifiManager.enableSemiWifi<sup>12+</sup> 87 88enableSemiWifi(): void 89 90使能WLAN半关闭(STA关闭、其他P2p、Hml可用),异步接口,需要通过注册"wifiStateChange"事件的回调来监听是否使能成功。 91 92**系统接口:** 此接口为系统接口。 93 94**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION 仅系统应用可用。 95 96**系统能力:** SystemCapability.Communication.WiFi.STA 97 98**错误码:** 99 100以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 101 102| **错误码ID** | **错误信息** | 103| -------- | -------- | 104| 201 | Permission denied. | 105| 202 | System API is not allowed called by Non-system application. | 106| 801 | Capability not supported. | 107| 2501000 | Operation failed.| 108| 2501004 | Operation failed because the service is being opened. | 109 110**示例:** 111 112```ts 113 import { wifiManager } from '@kit.ConnectivityKit'; 114 115 try { 116 wifiManager.enableSemiWifi(); 117 } catch(error) { 118 console.error("failed:" + JSON.stringify(error)); 119 } 120``` 121 122## wifiManager.startScan<sup>10+</sup> 123 124startScan(): void 125 126**系统接口:** 此接口为系统接口。 127 128启动WLAN扫描。 129 130**需要权限:** ohos.permission.SET_WIFI_INFO 和ohos.permission.MANAGE_WIFI_CONNECTION 131 132**系统能力:** SystemCapability.Communication.WiFi.STA 133 134**错误码:** 135 136以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 137 138| **错误码ID** | **错误信息** | 139| -------- | -------- | 140| 201 | Permission denied. | 141| 202 | System API is not allowed called by Non-system application. | 142| 801 | Capability not supported. | 143| 2501000 | Operation failed.| 144 145**示例:** 146 147```ts 148 import { wifiManager } from '@kit.ConnectivityKit'; 149 150 try { 151 wifiManager.startScan(); 152 }catch(error){ 153 console.error("failed:" + JSON.stringify(error)); 154 } 155``` 156 157## wifiManager.setScanAlwaysAllowed<sup>10+</sup> 158 159setScanAlwaysAllowed(isScanAlwaysAllowed: boolean): void 160 161设置是否始终允许扫描。 162 163**系统接口:** 此接口为系统接口。 164 165**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 166 167**系统能力:** SystemCapability.Communication.WiFi.STA 168 169**参数:** 170 171| **参数名** | **类型** | **必填** | **说明** | 172| -------- | -------- | -------- | -------- | 173| isScanAlwaysAllowed | boolean | 是 | 是否始终允许扫描。 | 174 175**错误码:** 176 177以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 178 179| **错误码ID** | **错误信息** | 180 | -------- | -------- | 181| 201 | Permission denied. | 182| 202 | System API is not allowed called by Non-system application. | 183| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 184| 801 | Capability not supported. | 185| 2501000 | Operation failed.| 186 187```ts 188 import { wifiManager } from '@kit.ConnectivityKit'; 189 190 try { 191 let isScanAlwaysAllowed = true; 192 wifiManager.setScanAlwaysAllowed(isScanAlwaysAllowed); 193 }catch(error){ 194 console.error("failed:" + JSON.stringify(error)); 195 } 196``` 197 198## wifiManager.getScanAlwaysAllowed<sup>10+</sup> 199 200getScanAlwaysAllowed(): boolean 201 202获取是否始终允许扫描。 203 204**系统接口:** 此接口为系统接口。 205 206**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 207 208**系统能力:** SystemCapability.Communication.WiFi.STA 209 210**返回值:** 211 212| **类型** | **说明** | 213| -------- | -------- | 214| boolean| 是否始终允许扫描。 true 表示允许触发扫描,false表示在禁用wifi时不允许触发扫描| 215 216**错误码:** 217 218以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 219 220| **错误码ID** | **错误信息** | 221| -------- | -------- | 222| 201 | Permission denied. | 223| 202 | System API is not allowed called by Non-system application. | 224| 801 | Capability not supported. | 225| 2501000 | Operation failed.| 226 227**示例:** 228 229```ts 230 import { wifiManager } from '@kit.ConnectivityKit'; 231 232 try { 233 let isScanAlwaysAllowed = wifiManager.getScanAlwaysAllowed(); 234 console.info("isScanAlwaysAllowed:" + isScanAlwaysAllowed); 235 }catch(error){ 236 console.error("failed:" + JSON.stringify(error)); 237 } 238``` 239 240## wifiManager.addDeviceConfig<sup>9+</sup> 241 242addDeviceConfig(config: WifiDeviceConfig): Promise<number> 243 244添加网络配置,使用Promise异步回调。 245 246**系统接口:** 此接口为系统接口。 247 248**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 249 250**系统能力:** SystemCapability.Communication.WiFi.STA 251 252**参数:** 253 254| **参数名** | **类型** | **必填** | **说明** | 255| -------- | -------- | -------- | -------- | 256| config | [WifiDeviceConfig](#wifideviceconfig9) | 是 | WLAN配置信息。如果bssidType未指定值,则bssidType默认为随机设备地址类型。 | 257 258**返回值:** 259 260 | **类型** | **说明** | 261 | -------- | -------- | 262 | Promise<number> | Promise对象。返回添加的网络配置ID,如果值为-1表示添加失败。 | 263 264**错误码:** 265 266以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 267 268| **错误码ID** | **错误信息** | 269| -------- | -------- | 270| 201 | Permission denied. | 271| 202 | System API is not allowed called by Non-system application. | 272| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 273| 801 | Capability not supported. | 274| 2501000 | Operation failed.| 275| 2501001 | Wi-Fi STA disabled. | 276 277**示例:** 278 279```ts 280 import { wifiManager } from '@kit.ConnectivityKit'; 281 282 try { 283 let config:wifiManager.WifiDeviceConfig = { 284 ssid : "****", 285 preSharedKey : "****", 286 securityType : 0 287 } 288 wifiManager.addDeviceConfig(config).then(result => { 289 console.info("result:" + JSON.stringify(result)); 290 }).catch((err:number) => { 291 console.error("failed:" + JSON.stringify(err)); 292 }); 293 }catch(error){ 294 console.error("failed:" + JSON.stringify(error)); 295 } 296``` 297 298## WifiDeviceConfig<sup>9+</sup> 299 300WLAN配置信息。 301 302**系统能力:** SystemCapability.Communication.WiFi.STA 303 304 305| **名称** | **类型** | **可读** | **可写** | **说明** | 306| -------- | -------- | -------- | -------- | -------- | 307| creatorUid | number | 是 | 否 | 创建用户的ID。 <br /> **系统接口:** 此接口为系统接口。 | 308| disableReason | number | 是 | 否 | 禁用原因。 <br /> **系统接口:** 此接口为系统接口。 | 309| netId | number | 是 | 否 | 分配的网络ID。 <br /> **系统接口:** 此接口为系统接口。 | 310| randomMacType | number | 是 | 否 | MAC地址类型。0 - 随机MAC地址,1 - 设备MAC地址 <br /> **系统接口:** 此接口为系统接口。 | 311| randomMacAddr | string | 是 | 否 | MAC地址。<br /> **系统接口:** 此接口为系统接口。 | 312| ipType | [IpType](#iptype9) | 是 | 否 | IP地址类型。 <br /> **系统接口:** 此接口为系统接口。 | 313| staticIp | [IpConfig](#ipconfig9) | 是 | 否 | 静态IP配置信息。 <br /> **系统接口:** 此接口为系统接口。 | 314| proxyConfig<sup>10+</sup> | [WifiProxyConfig](#wifiproxyconfig10) | 是 | 否 | 代理配置。 <br /> **系统接口:** 此接口为系统接口。| 315| configStatus<sup>12+</sup> | number | 是 | 否 | 返回当前网络是否允许参与选网。 <br /> **系统接口:** 此接口为系统接口。| 316 317## IpType<sup>9+</sup> 318 319表示IP类型的枚举。 320 321**系统接口:** 此接口为系统接口。 322 323**系统能力:** SystemCapability.Communication.WiFi.STA 324 325 326| 名称 | 值 | 说明 | 327| -------- | -------- | -------- | 328| STATIC | 0 | 静态IP。 | 329| DHCP | 1 | 通过DHCP获取。 | 330| UNKNOWN | 2 | 未指定。 | 331 332 333## IpConfig<sup>9+</sup> 334 335IP配置信息。 336 337**系统接口:** 此接口为系统接口。 338 339**系统能力:** SystemCapability.Communication.WiFi.STA 340 341| **名称** | **类型** | **可读** | **可写** | **说明** | 342| -------- | -------- | -------- | -------- | -------- | 343| ipAddress | number | 是 | 否 | IP地址。 | 344| gateway | number | 是 | 否 | 网关。 | 345| prefixLength | number | 是 | 否 | 掩码。 | 346| dnsServers | number[] | 是 | 否 | DNS服务器。 | 347| domains | Array<string> | 是 | 否 | 域信息。 | 348 349 350## WifiProxyConfig<sup>10+</sup> 351 352Wifi 代理配置。 353 354**系统接口:** 此接口为系统接口。 355 356**系统能力:** SystemCapability.Communication.WiFi.STA 357 358| **名称** | **类型** | **可读** | **可写** | **说明** | 359| -------- | -------- | -------- | -------- | -------- | 360| proxyMethod | ProxyMethod | 是 | 否 | 代理方法 | 361| pacWebAddress | string | 是 | 否 | 自动配置代理的PAC web 地址。 | 362| serverHostName | string | 是 | 否 | 手动配置代理的服务器主机名。 | 363| serverPort | number | 是 | 否 | 手动配置代理的服务器端口。 | 364| exclusionObjects | string | 是 | 否 | 手动配置代理的排除对象,对象用“,”分隔。| 365 366## ProxyMethod<sup>10+</sup> 367 368表示WiFi代理方法的枚举。 369 370**系统接口:** 此接口为系统接口。 371 372**系统能力:** SystemCapability.Communication.WiFi.STA 373 374| 名称 | 值 | 说明 | 375| -------- | -------- | -------- | 376| METHOD_NONE | 0 | 不使用代理。 | 377| METHOD_AUTO | 1 | 使用自动配置的代理。 | 378| METHOD_MANUAL | 2 | 使用手动配置的代理。 | 379 380## wifiManager.addDeviceConfig<sup>9+</sup> 381 382addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback<number>): void 383 384添加网络配置,使用callback异步回调。 385 386**系统接口:** 此接口为系统接口。 387 388**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 389 390**系统能力:** SystemCapability.Communication.WiFi.STA 391 392**参数:** 393 394| **参数名** | **类型** | **必填** | **说明** | 395| -------- | -------- | -------- | -------- | 396| config | [WifiDeviceConfig](#wifideviceconfig9) | 是 | WLAN配置信息。如果bssidType未指定值,则bssidType默认为随机设备地址类型。 | 397| callback | AsyncCallback<number> | 是 | 回调函数。当操作成功时,err为0,data为添加的网络配置ID,如果data值为-1,表示添加失败。当error为非0,表示处理出现错误。 | 398 399**错误码:** 400 401以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 402 403| **错误码ID** | **错误信息** | 404| -------- | -------- | 405| 201 | Permission denied. | 406| 202 | System API is not allowed called by Non-system application. | 407| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 408| 801 | Capability not supported. | 409| 2501000 | Operation failed.| 410| 2501001 | Wi-Fi STA disabled. | 411 412**示例:** 413 414```ts 415 import { wifiManager } from '@kit.ConnectivityKit'; 416 417 try { 418 let config:wifiManager.WifiDeviceConfig = { 419 ssid : "****", 420 preSharedKey : "****", 421 securityType : 0 422 } 423 wifiManager.addDeviceConfig(config,(error,result) => { 424 console.info("result:" + JSON.stringify(result)); 425 }); 426 }catch(error){ 427 console.error("failed:" + JSON.stringify(error)); 428 } 429``` 430 431 432## wifiManager.connectToNetwork<sup>9+</sup> 433 434connectToNetwork(networkId: number): void 435 436连接到指定网络(如果当前已经连接到热点,请先使用disconnect()接口断开连接)。 437 438**系统接口:** 此接口为系统接口。 439 440**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 441 442**系统能力:** SystemCapability.Communication.WiFi.STA 443 444**参数:** 445 446 | **参数名** | **类型** | **必填** | **说明** | 447 | -------- | -------- | -------- | -------- | 448 | networkId | number | 是 | 待连接的网络配置ID。 | 449 450**错误码:** 451 452以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 453 454| **错误码ID** | **错误信息** | 455| -------- | -------- | 456| 201 | Permission denied. | 457| 202 | System API is not allowed called by Non-system application. | 458| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 459| 801 | Capability not supported. | 460| 2501000 | Operation failed.| 461| 2501001 | Wi-Fi STA disabled.| 462 463**示例:** 464 465```ts 466 import { wifiManager } from '@kit.ConnectivityKit'; 467 468 try { 469 let networkId = 0; 470 wifiManager.connectToNetwork(networkId); 471 }catch(error){ 472 console.error("failed:" + JSON.stringify(error)); 473 } 474``` 475 476## wifiManager.connectToDevice<sup>9+</sup> 477 478connectToDevice(config: WifiDeviceConfig): void 479 480连接到指定网络(如果当前已经连接到热点,请先使用disconnect()接口断开连接)。 481 482**系统接口:** 此接口为系统接口。 483 484**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 485 486**系统能力:** 487 SystemCapability.Communication.WiFi.STA 488 489**参数:** 490 491| **参数名** | **类型** | **必填** | **说明** | 492| -------- | -------- | -------- | -------- | 493| config | [WifiDeviceConfig](#wifideviceconfig9) | 是 | WLAN配置信息。如果bssidType未指定值,则bssidType默认为随机设备地址类型。 | 494 495**错误码:** 496 497以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 498 499| **错误码ID** | **错误信息** | 500| -------- | -------- | 501| 201 | Permission denied. | 502| 202 | System API is not allowed called by Non-system application. | 503| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 504| 801 | Capability not supported. | 505| 2501000 | Operation failed.| 506| 2501001 | Wi-Fi STA disabled.| 507 508**示例:** 509```ts 510 import { wifiManager } from '@kit.ConnectivityKit'; 511 512 try { 513 let config:wifiManager.WifiDeviceConfig = { 514 ssid : "****", 515 preSharedKey : "****", 516 securityType : 3 517 } 518 wifiManager.connectToDevice(config); 519 520 }catch(error){ 521 console.error("failed:" + JSON.stringify(error)); 522 } 523``` 524 525## wifiManager.disconnect<sup>9+</sup> 526 527disconnect(): void 528 529断开连接的网络。 530 531**系统接口:** 此接口为系统接口。 532 533**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 534 535**系统能力:** 536 SystemCapability.Communication.WiFi.STA 537 538**错误码:** 539 540以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 541 542| **错误码ID** | **错误信息** | 543| -------- | -------- | 544| 201 | Permission denied. | 545| 202 | System API is not allowed called by Non-system application. | 546| 801 | Capability not supported. | 547| 2501000 | Operation failed.| 548| 2501001 | Wi-Fi STA disabled. | 549 550**示例:** 551```ts 552 import { wifiManager } from '@kit.ConnectivityKit'; 553 554 try { 555 wifiManager.disconnect(); 556 }catch(error){ 557 console.error("failed:" + JSON.stringify(error)); 558 } 559``` 560 561 562## WifiLinkedInfo<sup>9+</sup> 563 564提供WLAN连接的相关信息。 565 566**系统能力:** SystemCapability.Communication.WiFi.STA 567 568| 名称 | 类型 | 可读 | 可写 | 说明 | 569| -------- | -------- | -------- | -------- | -------- | 570| networkId | number | 是 | 否 | 网络配置ID。 <br /> **系统接口:** 此接口为系统接口。 | 571| chload | number | 是 | 否 | 连接负载,值越大表示负载约高。 <br /> **系统接口:** 此接口为系统接口。 | 572| snr | number | 是 | 否 | 信噪比。 <br /> **系统接口:** 此接口为系统接口。 | 573| suppState | [SuppState](#suppstate9) | 是 | 否 | 请求状态。 <br /> **系统接口:** 此接口为系统接口。 | 574 575 576 577## SuppState<sup>9+</sup> 578 579表示请求状态的枚举。 580 581**系统接口:** 此接口为系统接口。 582 583**系统能力:** SystemCapability.Communication.WiFi.STA 584 585| 名称 | 值 | 说明 | 586| -------- | -------- | -------- | 587| DISCONNECTED | 0 | 已断开。 | 588| INTERFACE_DISABLED | 1 | 接口禁用。 | 589| INACTIVE | 2 | 未激活。 | 590| SCANNING | 3 | 扫描中。 | 591| AUTHENTICATING | 4 | 认证中。 | 592| ASSOCIATING | 5 | 关联中。 | 593| ASSOCIATED | 6 | 已关联。 | 594| FOUR_WAY_HANDSHAKE | 7 | 四次握手。 | 595| GROUP_HANDSHAKE | 8 | 组握手。 | 596| COMPLETED | 9 | 所有认证已完成。 | 597| UNINITIALIZED | 10 | 连接建立失败。 | 598| INVALID | 11 | 无效值。 | 599 600 601## wifiManager.getSupportedFeatures<sup>9+</sup> 602 603getSupportedFeatures(): number 604 605查询设备支持的特性。 606 607**系统接口:** 此接口为系统接口。 608 609**需要权限:** ohos.permission.GET_WIFI_INFO 610 611**系统能力:** SystemCapability.Communication.WiFi.Core 612 613**返回值:** 614 615 | **类型** | **说明** | 616 | -------- | -------- | 617 | number | 支持的特性值。 | 618 619**特性ID值枚举:** 620 621| 枚举值 | 说明 | 622| -------- | -------- | 623| 0x0001 | 基础结构模式特性。 | 624| 0x0002 | 5 GHz带宽特性。 | 625| 0x0004 | GAS/ANQP特性。 | 626| 0x0008 | Wifi-Direct特性。 | 627| 0x0010 | Soft AP特性。 | 628| 0x0040 | Wi-Fi AWare组网特性。 | 629| 0x8000 | AP STA共存特性。 | 630| 0x8000000 | WPA3-Personal SAE特性。 | 631| 0x10000000 | WPA3-Enterprise Suite-B | 632| 0x20000000 | 增强开放特性。 | 633 634**错误码:** 635 636以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 637 638| **错误码ID** | **错误信息** | 639| -------- | -------- | 640| 201 | Permission denied. | 641| 202 | System API is not allowed called by Non-system application. | 642| 801 | Capability not supported. | 643| 2401000 | Operation failed.| 644 645**示例:** 646```ts 647 import { wifiManager } from '@kit.ConnectivityKit'; 648 649 try { 650 let ret = wifiManager.getSupportedFeatures(); 651 console.info("supportedFeatures:" + ret); 652 }catch(error){ 653 console.error("failed:" + JSON.stringify(error)); 654 } 655 656``` 657 658 659## wifiManager.getDeviceMacAddress<sup>9+</sup> 660 661getDeviceMacAddress(): string[] 662 663获取设备的MAC地址。 664 665**系统接口:** 此接口为系统接口。 666 667**需要权限:** ohos.permission.GET_WIFI_LOCAL_MAC 和 ohos.permission.GET_WIFI_INFO,仅系统应用可用。 668 669**系统能力:** SystemCapability.Communication.WiFi.STA 670 671**返回值:** 672 673 | **类型** | **说明** | 674 | -------- | -------- | 675 | string[] | MAC地址。 | 676 677**错误码:** 678 679以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 680 681| **错误码ID** | **错误信息** | 682| -------- | -------- | 683| 201 | Permission denied. | 684| 202 | System API is not allowed called by Non-system application. | 685| 801 | Capability not supported. | 686| 2501000 | Operation failed.| 687| 2501001 | Wi-Fi STA disabled.| 688 689**示例:** 690```ts 691 import { wifiManager } from '@kit.ConnectivityKit'; 692 693 try { 694 let ret = wifiManager.getDeviceMacAddress(); 695 console.info("deviceMacAddress:" + JSON.stringify(ret)); 696 }catch(error){ 697 console.error("failed:" + JSON.stringify(error)); 698 } 699 700``` 701 702## wifiManager.getWifiDetailState<sup>12+</sup> 703 704getWifiDetailState(): WifiDetailState 705 706获取Wifi开关详细状态。 707 708**系统接口:** 此接口为系统接口。 709 710**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 711 712**系统能力:** SystemCapability.Communication.WiFi.STA 713 714**返回值:** 715 716 | **类型** | **说明** | 717 | -------- | -------- | 718 | WifiDetailState | Wifi枚举状态。 | 719 720**错误码:** 721 722以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 723 724| **错误码ID** | **错误信息** | 725| -------- | -------- | 726| 201 | Permission denied. | 727| 202 | System API is not allowed called by Non-system application. | 728| 801 | Capability not supported. | 729| 2501000 | Operation failed.| 730 731**示例:** 732```ts 733 import { wifiManager } from '@kit.ConnectivityKit'; 734 735 try { 736 let ret = wifiManager.getWifiDetailState(); 737 console.info("wifiDetailState:" + ret); 738 } catch(error) { 739 console.error("failed:" + JSON.stringify(error)); 740 } 741 742``` 743 744## WifiDetailState<sup>12+</sup> 745 746表示Wifi开关状态的枚举。 747 748**系统接口:** 此接口为系统接口。 749 750**系统能力:** SystemCapability.Communication.WiFi.STA 751 752| 名称 | 值 | 说明 | 753| -------- | -------- | -------- | 754| UNKNOWN | -1 | 未指定。 | 755| INACTIVE | 0 | 已关闭。 | 756| ACTIVATED | 1 | 已激活。 | 757| ACTIVATING | 2 | 激活中。 | 758| DEACTIVATING | 3 | 关闭中。 | 759| SEMI_ACTIVATING | 4 | 半关闭中。 | 760| SEMI_ACTIVE | 5 | 已半关闭。 | 761 762 763## wifiManager.reassociate<sup>9+</sup> 764 765reassociate(): void 766 767重新关联网络。 768 769**系统接口:** 此接口为系统接口。 770 771**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 772 773**系统能力:** SystemCapability.Communication.WiFi.STA 774 775**错误码:** 776 777以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 778 779| **错误码ID** | **错误信息** | 780| -------- | -------- | 781| 201 | Permission denied. | 782| 202 | System API is not allowed called by Non-system application. | 783| 801 | Capability not supported. | 784| 2501000 | Operation failed.| 785| 2501001 | Wi-Fi STA disabled.| 786 787**示例:** 788```ts 789 import { wifiManager } from '@kit.ConnectivityKit'; 790 791 try { 792 wifiManager.reassociate(); 793 }catch(error){ 794 console.error("failed:" + JSON.stringify(error)); 795 } 796``` 797 798## wifiManager.reconnect<sup>9+</sup> 799 800reconnect(): void 801 802重新连接网络。 803 804**系统接口:** 此接口为系统接口。 805 806**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 807 808**系统能力:** SystemCapability.Communication.WiFi.STA 809 810**错误码:** 811 812以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 813 814| **错误码ID** | **错误信息** | 815| -------- | -------- | 816| 201 | Permission denied. | 817| 202 | System API is not allowed called by Non-system application. | 818| 801 | Capability not supported. | 819| 2501000 | Operation failed.| 820| 2501001 | Wi-Fi STA disabled.| 821 822**示例:** 823```ts 824 import { wifiManager } from '@kit.ConnectivityKit'; 825 826 try { 827 wifiManager.reconnect(); 828 }catch(error){ 829 console.error("failed:" + JSON.stringify(error)); 830 } 831``` 832 833## wifiManager.getDeviceConfigs<sup>9+</sup> 834 835getDeviceConfigs(): Array<[WifiDeviceConfig](#wifideviceconfig9)> 836 837获取网络配置。 838 839**系统接口:** 此接口为系统接口。 840 841**需要权限:** 842 843API 9:ohos.permission.GET_WIFI_INFO、ohos.permission.LOCATION、ohos.permission.APPROXIMATELY_LOCATION 和 ohos.permission.GET_WIFI_CONFIG 844 845API 10起:ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 846 847**系统能力:** SystemCapability.Communication.WiFi.STA 848 849**返回值:** 850 851 | **类型** | **说明** | 852 | -------- | -------- | 853 | Array<[WifiDeviceConfig](#wifideviceconfig9)> | 网络配置信息的数组。 | 854 855**错误码:** 856 857以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 858 859| **错误码ID** | **错误信息** | 860| -------- | -------- | 861| 201 | Permission denied. | 862| 202 | System API is not allowed called by Non-system application. | 863| 801 | Capability not supported. | 864| 2501000 | Operation failed.| 865 866**示例:** 867```ts 868 import { wifiManager } from '@kit.ConnectivityKit'; 869 870 try { 871 let configs = wifiManager.getDeviceConfigs(); 872 console.info("configs:" + JSON.stringify(configs)); 873 }catch(error){ 874 console.error("failed:" + JSON.stringify(error)); 875 } 876``` 877 878## wifiManager.updateNetwork<sup>9+</sup> 879 880updateNetwork(config: WifiDeviceConfig): number 881 882更新网络配置。 883 884**系统接口:** 此接口为系统接口。 885 886**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.SET_WIFI_CONFIG 887 888**系统能力:** SystemCapability.Communication.WiFi.STA 889 890**参数:** 891 892 | **参数名** | **类型** | **必填** | **说明** | 893 | -------- | -------- | -------- | -------- | 894 | config | [WifiDeviceConfig](#wifideviceconfig9) | 是 | WLAN配置信息。 | 895 896**返回值:** 897 898 | **类型** | **说明** | 899 | -------- | -------- | 900 | number | 返回更新的网络配置ID,如果值为-1表示更新失败。 | 901 902**错误码:** 903 904以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 905 906| **错误码ID** | **错误信息** | 907| -------- | -------- | 908| 201 | Permission denied. | 909| 202 | System API is not allowed called by Non-system application. | 910| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 911| 801 | Capability not supported. | 912| 2501000 | Operation failed.| 913| 2501001 | Wi-Fi STA disabled. | 914 915**示例:** 916```ts 917 import { wifiManager } from '@kit.ConnectivityKit'; 918 919 try { 920 let config:wifiManager.WifiDeviceConfig = { 921 ssid : "****", 922 preSharedKey : "****", 923 securityType : 3 924 } 925 let ret = wifiManager.updateNetwork(config); 926 console.info("ret:" + ret); 927 }catch(error){ 928 console.error("failed:" + JSON.stringify(error)); 929 } 930``` 931 932## wifiManager.disableNetwork<sup>9+</sup> 933 934disableNetwork(netId: number): void 935 936去使能网络配置。 937 938**系统接口:** 此接口为系统接口。 939 940**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 941 942**系统能力:** SystemCapability.Communication.WiFi.STA 943 944**参数:** 945 946 | **参数名** | **类型** | **必填** | **说明** | 947 | -------- | -------- | -------- | -------- | 948 | netId | number | 是 | 网络配置ID。 | 949 950**错误码:** 951 952以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 953 954| **错误码ID** | **错误信息** | 955| -------- | -------- | 956| 201 | Permission denied. | 957| 202 | System API is not allowed called by Non-system application. | 958| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 959| 801 | Capability not supported. | 960| 2501000 | Operation failed.| 961| 2501001 | Wi-Fi STA disabled. | 962 963**示例:** 964```ts 965 import { wifiManager } from '@kit.ConnectivityKit'; 966 967 try { 968 let netId = 0; 969 wifiManager.disableNetwork(netId); 970 }catch(error){ 971 console.error("failed:" + JSON.stringify(error)); 972 } 973``` 974 975## wifiManager.removeAllNetwork<sup>9+</sup> 976 977removeAllNetwork(): void 978 979移除所有网络配置。 980 981**系统接口:** 此接口为系统接口。 982 983**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 984 985**系统能力:** SystemCapability.Communication.WiFi.STA 986 987**错误码:** 988 989以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 990 991| **错误码ID** | **错误信息** | 992| -------- | -------- | 993| 201 | Permission denied. | 994| 202 | System API is not allowed called by Non-system application. | 995| 801 | Capability not supported. | 996| 2501000 | Operation failed.| 997| 2501001 | Wi-Fi STA disabled. | 998 999**示例:** 1000```ts 1001 import { wifiManager } from '@kit.ConnectivityKit'; 1002 1003 try { 1004 wifiManager.removeAllNetwork(); 1005 }catch(error){ 1006 console.error("failed:" + JSON.stringify(error)); 1007 } 1008``` 1009 1010## wifiManager.removeDevice<sup>9+</sup> 1011 1012removeDevice(id: number): void 1013 1014移除指定的网络配置。 1015 1016**系统接口:** 此接口为系统接口。 1017 1018**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 1019 1020**系统能力:** SystemCapability.Communication.WiFi.STA 1021 1022**参数:** 1023 1024 | **参数名** | **类型** | **必填** | **说明** | 1025 | -------- | -------- | -------- | -------- | 1026 | id | number | 是 | 网络配置ID。 | 1027 1028**错误码:** 1029 1030以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1031 1032| **错误码ID** | **错误信息** | 1033| -------- | -------- | 1034| 201 | Permission denied. | 1035| 202 | System API is not allowed called by Non-system application. | 1036| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1037| 801 | Capability not supported. | 1038| 2501000 | Operation failed.| 1039| 2501001 | Wi-Fi STA disabled. | 1040 1041**示例:** 1042```ts 1043 import { wifiManager } from '@kit.ConnectivityKit'; 1044 1045 try { 1046 let id = 0; 1047 wifiManager.removeDevice(id); 1048 }catch(error){ 1049 console.error("failed:" + JSON.stringify(error)); 1050 } 1051``` 1052 1053## wifiManager.get5GChannelList<sup>10+</sup> 1054 1055get5GChannelList(): Array<number> 1056 1057获取当前设备支持的5G信道列表。 1058 1059**系统接口:** 此接口为系统接口。 1060 1061**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 1062 1063**系统能力:** SystemCapability.Communication.WiFi.STA 1064 1065**返回值:** 1066 1067 | **类型** | **说明** | 1068 | -------- | -------- | 1069 | Array<number> | 设备支持的5G信道列表。 | 1070 1071**错误码:** 1072 1073以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1074 1075| **错误码ID** | **错误信息** | 1076| -------- | -------- | 1077| 201 | Permission denied. | 1078| 202 | System API is not allowed called by Non-system application. | 1079| 801 | Capability not supported. | 1080| 2501000 | Operation failed.| 1081 1082**示例:** 1083```ts 1084 import { wifiManager } from '@kit.ConnectivityKit'; 1085 1086 try { 1087 let channelList = wifiManager.get5GChannelList(); 1088 console.info("channelList:" + JSON.stringify(channelList)); 1089 }catch(error){ 1090 console.error("failed:" + JSON.stringify(error)); 1091 } 1092``` 1093## wifiManager.getDisconnectedReason<sup>10+</sup> 1094 1095getDisconnectedReason(): DisconnectedReason 1096 1097获取最近一次断连原因。 1098 1099**系统接口:** 此接口为系统接口。 1100 1101**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 1102 1103**系统能力:** SystemCapability.Communication.WiFi.STA 1104 1105**错误码:** 1106 1107以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1108 1109| **错误码ID** | **错误信息** | 1110| -------- | -------- | 1111| 201 | Permission denied. | 1112| 801 | Capability not supported. | 1113| 2501000 | Operation failed.| 1114 1115**返回值:** 1116 1117| **类型** | **说明** | 1118| -------- | -------- | 1119| [DisconnectedReason](#disconnectedreason-10) | 最近断开的原因 | 1120 1121**示例:** 1122```ts 1123 import { wifiManager } from '@kit.ConnectivityKit'; 1124 1125 try { 1126 let disconnectedReason = wifiManager.getDisconnectedReason(); 1127 console.info("disconnectedReason:" + disconnectedReason); 1128 }catch(error){ 1129 console.error("failed:" + JSON.stringify(error)); 1130 } 1131``` 1132 1133## DisconnectedReason <sup>10+</sup> 1134 1135表示wifi断开原因的枚举。 1136 1137**系统接口:** 此接口为系统接口。 1138 1139**系统能力:** SystemCapability.Communication.WiFi.STA 1140 1141| 名称 | 值 | 说明 | 1142| -------- | -------- | -------- | 1143| DISC_REASON_DEFAULT | 0 | 默认原因。 | 1144| DISC_REASON_WRONG_PWD | 1 | 密码错误。 | 1145| DISC_REASON_CONNECTION_FULL | 2 | 路由器的连接数已达到最大数量限制。 | 1146 1147## wifiManager.startPortalCertification<sup>11+</sup> 1148 1149startPortalCertification(): void 1150 1151**系统接口:** 此接口为系统接口。 1152 1153启动portal认证。 1154 1155**需要权限:** ohos.permission.SET_WIFI_INFO 和ohos.permission.MANAGE_WIFI_CONNECTION 1156 1157**系统能力:** SystemCapability.Communication.WiFi.STA 1158 1159**错误码:** 1160 1161以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1162 1163| **错误码ID** | **错误信息** | 1164| -------- | -------- | 1165| 201 | Permission denied. | 1166| 202 | System API is not allowed called by Non-system application. | 1167| 801 | Capability not supported. | 1168| 2501000 | Operation failed.| 1169| 2501001 | Wi-Fi STA disabled. | 1170 1171**示例:** 1172 1173```ts 1174 import { wifiManager } from '@kit.ConnectivityKit'; 1175 1176 try { 1177 wifiManager.startPortalCertification(); 1178 }catch(error){ 1179 console.error("failed:" + JSON.stringify(error)); 1180 } 1181``` 1182 1183## wifiManager.enableHiLinkHandshake<sup>12+</sup> 1184 1185enableHiLinkHandshake(isHiLinkEnable: boolean, bssid: string, config: WifiDeviceConfig): void 1186 1187**系统接口:** 此接口为系统接口。 1188 1189设置是否使能hiLink。 1190 1191**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION 1192 1193**系统能力:** SystemCapability.Communication.WiFi.STA 1194 1195**参数:** 1196 1197| **参数名** | **类型** | **必填** | **说明** | 1198| -------- | -------- | -------- | -------- | 1199| isHiLinkEnable | boolean | 是 | 是否使能hiLink。true:使能, false:去使能。 | 1200| bssid | string | 是 | 热点的mac地址,例如:00:11:22:33:44:55。 | 1201| config | [WifiDeviceConfig](#wifideviceconfig9) | 是 | WLAN的配置信息。config.bssid必须和第二个参数bssid保持一致。如果bssidType未指定值,则bssidType默认为随机设备地址类型。 | 1202 1203**错误码:** 1204 1205以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1206 1207| **错误码ID** | **错误信息** | 1208| -------- | -------- | 1209| 201 | Permission denied. | 1210| 202 | System API is not allowed called by Non-system application. | 1211| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1212| 801 | Capability not supported. | 1213| 2501000 | Operation failed.| 1214| 2501001 | Wi-Fi STA disabled. | 1215 1216**示例:** 1217 1218```ts 1219 import { wifiManager } from '@kit.ConnectivityKit'; 1220 // config数据可以通过getScanInfoList接口获取,只有WifiScanInfo.isHiLinkNetwork为true的热点,才能正常使用该接口 1221 let config:wifiManager.WifiDeviceConfig = { 1222 ssid : "****", 1223 preSharedKey : "****", 1224 securityType : 0, 1225 bssid : "38:37:8b:80:bf:cc", 1226 bssidType : 1, 1227 isHiddenSsid : false 1228 } 1229 try { 1230 wifiManager.enableHiLinkHandshake(true, config.bssid, config); 1231 }catch(error){ 1232 console.error("failed:" + JSON.stringify(error)); 1233 } 1234``` 1235 1236## wifiManager.factoryReset<sup>11+</sup> 1237 1238factoryReset(): void 1239 1240**系统接口:** 此接口为系统接口。 1241 1242重置wifi相关配置。 1243 1244**需要权限:** ohos.permission.SET_WIFI_INFO 和ohos.permission.SET_WIFI_CONFIG 1245 1246**系统能力:** SystemCapability.Communication.WiFi.STA 1247 1248**错误码:** 1249 1250以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1251 1252| **错误码ID** | **错误信息** | 1253| -------- | -------- | 1254| 201 | Permission denied. | 1255| 202 | System API is not allowed called by Non-system application. | 1256| 801 | Capability not supported. | 1257| 2501000 | Operation failed.| 1258 1259**示例:** 1260 1261```ts 1262 import { wifiManager } from '@kit.ConnectivityKit'; 1263 1264 try { 1265 wifiManager.factoryReset(); 1266 }catch(error){ 1267 console.error("failed:" + JSON.stringify(error)); 1268 } 1269``` 1270## wifiManager.enableHotspot<sup>9+</sup> 1271 1272enableHotspot(): void 1273 1274使能热点,异步接口,是否打开成功需要注册并监听hotspotStateChange的回调。 1275 1276**系统接口:** 此接口为系统接口。 1277 1278**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1279 1280**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1281 1282**错误码:** 1283 1284以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1285 1286| **错误码ID** | **错误信息** | 1287| -------- | -------- | 1288| 201 | Permission denied. | 1289| 202 | System API is not allowed called by Non-system application. | 1290| 801 | Capability not supported. | 1291| 2601000 | Operation failed. | 1292 1293**示例:** 1294```ts 1295 import { wifiManager } from '@kit.ConnectivityKit'; 1296 1297 try { 1298 wifiManager.enableHotspot(); 1299 }catch(error){ 1300 console.error("failed:" + JSON.stringify(error)); 1301 } 1302``` 1303 1304## wifiManager.disableHotspot<sup>9+</sup> 1305 1306disableHotspot(): void 1307 1308去使能热点 ,异步接口,是否关闭成功需要注册并监听hotspotStateChange的回调。 1309 1310**系统接口:** 此接口为系统接口。 1311 1312**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1313 1314**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1315 1316**错误码:** 1317 1318以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1319 1320| **错误码ID** | **错误信息** | 1321| -------- | -------- | 1322| 201 | Permission denied. | 1323| 202 | System API is not allowed called by Non-system application. | 1324| 801 | Capability not supported. | 1325| 2601000 | Operation failed. | 1326 1327**示例:** 1328```ts 1329 import { wifiManager } from '@kit.ConnectivityKit'; 1330 1331 try { 1332 wifiManager.disableHotspot(); 1333 }catch(error){ 1334 console.error("failed:" + JSON.stringify(error)); 1335 } 1336``` 1337 1338## wifiManager.isHotspotDualBandSupported<sup>9+</sup> 1339 1340isHotspotDualBandSupported(): boolean 1341 1342热点是否支持双频。 1343 1344**系统接口:** 此接口为系统接口。 1345 1346**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1347 1348**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1349 1350**返回值:** 1351 1352 | **类型** | **说明** | 1353 | -------- | -------- | 1354 | boolean | true:支持, false:不支持.| 1355 1356**错误码:** 1357 1358以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1359 1360| **错误码ID** | **错误信息** | 1361| -------- | -------- | 1362| 201 | Permission denied. | 1363| 202 | System API is not allowed called by Non-system application. | 1364| 801 | Capability not supported. | 1365| 2601000 | Operation failed. | 1366 1367**示例:** 1368```ts 1369 import { wifiManager } from '@kit.ConnectivityKit'; 1370 1371 try { 1372 let ret = wifiManager.isHotspotDualBandSupported(); 1373 console.info("result:" + ret); 1374 }catch(error){ 1375 console.error("failed:" + JSON.stringify(error)); 1376 } 1377``` 1378 1379## wifiManager.isHotspotActive<sup>9+</sup> 1380 1381isHotspotActive(): boolean 1382 1383热点是否已使能。 1384 1385**系统接口:** 此接口为系统接口。 1386 1387**需要权限:** ohos.permission.GET_WIFI_INFO 1388 1389**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1390 1391**返回值:** 1392 1393 | **类型** | **说明** | 1394 | -------- | -------- | 1395 | boolean | true:已使能, false:未使能.| 1396 1397**错误码:** 1398 1399以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1400 1401| **错误码ID** | **错误信息** | 1402| -------- | -------- | 1403| 201 | Permission denied. | 1404| 202 | System API is not allowed called by Non-system application. | 1405| 801 | Capability not supported. | 1406| 2601000 | Operation failed. | 1407 1408**示例:** 1409```ts 1410 import { wifiManager } from '@kit.ConnectivityKit'; 1411 1412 try { 1413 let ret = wifiManager.isHotspotActive(); 1414 console.info("result:" + ret); 1415 }catch(error){ 1416 console.error("failed:" + JSON.stringify(error)); 1417 } 1418``` 1419 1420## wifiManager.setHotspotConfig<sup>9+</sup> 1421 1422setHotspotConfig(config: HotspotConfig): void 1423 1424设置热点配置信息。 1425 1426**系统接口:** 此接口为系统接口。 1427 1428**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 1429 1430**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1431 1432**参数:** 1433 1434 | **参数名** | **类型** | **必填** | **说明** | 1435 | -------- | -------- | -------- | -------- | 1436 | config | [HotspotConfig](#hotspotconfig9) | 是 | 热点配置信息。 | 1437 1438**错误码:** 1439 1440以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1441 1442| **错误码ID** | **错误信息** | 1443| -------- | -------- | 1444| 201 | Permission denied. | 1445| 202 | System API is not allowed called by Non-system application. | 1446| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1447| 801 | Capability not supported. | 1448| 2601000 | Operation failed. | 1449 1450**示例:** 1451```ts 1452 import { wifiManager } from '@kit.ConnectivityKit'; 1453 1454 try { 1455 let config:wifiManager.HotspotConfig = { 1456 ssid: "****", 1457 securityType: 3, 1458 band: 0, 1459 channel: 0, 1460 preSharedKey: "****", 1461 maxConn: 0 1462 } 1463 let ret = wifiManager.setHotspotConfig(config); 1464 console.info("result:" + ret); 1465 }catch(error){ 1466 console.error("failed:" + JSON.stringify(error)); 1467 } 1468``` 1469 1470## HotspotConfig<sup>9+</sup> 1471 1472热点配置信息。 1473 1474**系统接口:** 此接口为系统接口。 1475 1476**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1477 1478| **名称** | **类型** | **可读** | **可写** | **说明** | 1479| -------- | -------- | -------- | -------- | -------- | 1480| ssid | string | 是 | 是 | 热点的SSID,编码格式为UTF-8。 | 1481| securityType | [WifiSecurityType](js-apis-wifiManager.md#wifisecuritytype9)| 是 | 是 | 加密类型。 | 1482| band | number | 是 | 是 | 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 | 1483| channel<sup>10+</sup> | number | 是 | 是 | 热点的信道(2.4G:1~14,5G:7~196)。 | 1484| preSharedKey | string | 是 | 是 | 热点的密钥。 | 1485| maxConn | number | 是 | 是 | 最大设备连接数。 | 1486 1487## wifiManager.getHotspotConfig<sup>9+</sup> 1488 1489getHotspotConfig(): HotspotConfig 1490 1491获取热点配置信息。 1492 1493**系统接口:** 此接口为系统接口。 1494 1495**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.GET_WIFI_CONFIG 1496 1497**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1498 1499**返回值:** 1500 1501 | **类型** | **说明** | 1502 | -------- | -------- | 1503 | [HotspotConfig](#hotspotconfig9) | 热点的配置信息。 | 1504 1505**错误码:** 1506 1507以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1508 1509| **错误码ID** | **错误信息** | 1510| -------- | -------- | 1511| 201 | Permission denied. | 1512| 202 | System API is not allowed called by Non-system application. | 1513| 801 | Capability not supported. | 1514| 2601000 | Operation failed. | 1515 1516**示例:** 1517```ts 1518 import { wifiManager } from '@kit.ConnectivityKit'; 1519 1520 try { 1521 let config = wifiManager.getHotspotConfig(); 1522 console.info("result:" + JSON.stringify(config)); 1523 }catch(error){ 1524 console.error("failed:" + JSON.stringify(error)); 1525 } 1526``` 1527 1528## wifiManager.getStations<sup>9+</sup> 1529 1530getStations(): Array<StationInfo> 1531 1532获取连接的设备。 1533 1534**系统接口:** 此接口为系统接口。 1535 1536**需要权限:** 1537 1538API 9:ohos.permission.GET_WIFI_INFO、ohos.permission.LOCATION、ohos.permission.APPROXIMATELY_LOCATION 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1539 1540API 10起:ohos.permission.GET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1541 1542**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1543 1544**返回值:** 1545 1546| **类型** | **说明** | 1547| -------- | -------- | 1548| Array<[StationInfo](#stationinfo9)> | 连接的设备数组。如果应用申请了ohos.permission.GET_WIFI_PEERS_MAC权限,则返回结果中的macAddress为真实设备地址,否则为随机设备地址。 | 1549 1550**错误码:** 1551 1552以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1553 1554| **错误码ID** | **错误信息** | 1555| -------- | -------- | 1556| 201 | Permission denied. | 1557| 202 | System API is not allowed called by Non-system application. | 1558| 801 | Capability not supported. | 1559| 2601000 | Operation failed. | 1560 1561**示例:** 1562```ts 1563 import { wifiManager } from '@kit.ConnectivityKit'; 1564 1565 try { 1566 let stations = wifiManager.getStations(); 1567 console.info("result:" + JSON.stringify(stations)); 1568 }catch(error){ 1569 console.error("failed:" + JSON.stringify(error)); 1570 } 1571``` 1572 1573## StationInfo<sup>9+</sup> 1574 1575接入的设备信息。 1576 1577**系统接口:** 此接口为系统接口。 1578 1579**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1580 1581| **名称** | **类型** | **可读** | **可写** | **说明** | 1582| -------- | -------- | -------- | -------- | -------- | 1583| name | string | 是 | 否 | 设备名称。 | 1584| macAddress | string | 是 | 否 | MAC地址。 | 1585| macAddressType<sup>10+</sup> | [DeviceAddressType](js-apis-wifiManager.md#deviceaddresstype10) | 是 | 否 | MAC地址类型。 | 1586| ipAddress | string | 是 | 否 | IP地址。 | 1587 1588## wifiManager.addHotspotBlockList<sup>11+</sup> 1589 1590addHotspotBlockList(stationInfo: StationInfo) 1591 1592将设备添加到热点的阻止连接设备列表中,列表中的设备将不能访问热点。 1593 1594**系统接口:** 此接口为系统接口。 1595 1596**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1597 1598**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1599 1600**参数:** 1601 1602| **参数名** | **类型** | **必填** | **说明** | 1603| -------- | -------- | -------- | -------- | 1604| stationInfo | [StationInfo](#stationinfo9) | 是 | 将添加到热点的阻止列表中的设备。 | 1605 1606**错误码:** 1607 1608以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1609 1610| **错误码ID** | **错误信息** | 1611| -------- | -------- | 1612| 201 | Permission denied. | 1613| 202 | System API is not allowed called by Non-system application. | 1614| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1615| 801 | Capability not supported. | 1616| 2601000 | Operation failed. | 1617 1618**示例:** 1619 1620```ts 1621 import { wifiManager } from '@kit.ConnectivityKit'; 1622 1623 try { 1624 let config:wifiManager.StationInfo = { 1625 name : "testSsid", 1626 macAddress : "11:22:33:44:55:66", 1627 ipAddress : "192.168.1.111" 1628 } 1629 // 热点开启后,才能正常将设备添加到连接阻止列表中 1630 wifiManager.addHotspotBlockList(config); 1631 }catch(error){ 1632 console.error("failed:" + JSON.stringify(error)); 1633 } 1634``` 1635 1636## wifiManager.delHotspotBlockList<sup>11+</sup> 1637 1638delHotspotBlockList(stationInfo: StationInfo) 1639 1640将设备从热点的阻止列表中删除。 1641 1642**系统接口:** 此接口为系统接口。 1643 1644**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1645 1646**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1647 1648**参数:** 1649 1650| **参数名** | **类型** | **必填** | **说明** | 1651| -------- | -------- | -------- | -------- | 1652| stationInfo | [StationInfo](#stationinfo9) | 是 | 将从热点的阻止列表中删除的设备。 | 1653 1654**错误码:** 1655 1656以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1657 1658| **错误码ID** | **错误信息** | 1659| -------- | -------- | 1660| 201 | Permission denied. | 1661| 202 | System API is not allowed called by Non-system application. | 1662| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. | 1663| 801 | Capability not supported. | 1664| 2601000 | Operation failed. | 1665 1666**示例:** 1667 1668```ts 1669 import { wifiManager } from '@kit.ConnectivityKit'; 1670 1671 try { 1672 let config:wifiManager.StationInfo = { 1673 name : "testSsid", 1674 macAddress : "11:22:33:44:55:66", 1675 ipAddress : "192.168.1.111" 1676 } 1677 wifiManager.delHotspotBlockList(config); 1678 }catch(error){ 1679 console.error("failed:" + JSON.stringify(error)); 1680 } 1681``` 1682 1683## wifiManager.getHotspotBlockList<sup>11+</sup> 1684 1685getHotspotBlockList(): Array<StationInfo> 1686 1687获取热点的阻止列表。 1688 1689**系统接口:** 此接口为系统接口。 1690 1691**需要权限:** ohos.permission.GET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。 1692 1693**系统能力:** SystemCapability.Communication.WiFi.AP.Core 1694 1695**返回值:** 1696 1697| **类型** | **说明** | 1698| -------- | -------- | 1699| Array<[StationInfo](#stationinfo9)> | 热点的阻止列表。 | 1700 1701**错误码:** 1702 1703以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1704 1705| **错误码ID** | **错误信息** | 1706 | -------- | -------- | 1707| 201 | Permission denied. | 1708| 202 | System API is not allowed called by Non-system application. | 1709| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. | 1710| 801 | Capability not supported. | 1711| 2601000 | Operation failed. | 1712 1713**示例:** 1714 1715```ts 1716 import { wifiManager } from '@kit.ConnectivityKit'; 1717 1718 try { 1719 let data = wifiManager.getHotspotBlockList(); 1720 console.info("result:" + JSON.stringify(data)); 1721 }catch(error){ 1722 console.error("failed:" + JSON.stringify(error)); 1723 } 1724``` 1725 1726## wifiManager.deletePersistentGroup<sup>9+</sup> 1727 1728deletePersistentGroup(netId: number): void 1729 1730删除永久组。 1731 1732**系统接口:** 此接口为系统接口。 1733 1734**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION 1735 1736**系统能力:** SystemCapability.Communication.WiFi.P2P 1737 1738**参数:** 1739 1740 1741 | **参数名** | **类型** | 必填 | **说明** | 1742 | -------- | -------- | -------- | -------- | 1743 | netId | number | 是 | 组的ID。 | 1744 1745**错误码:** 1746 1747以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1748 1749| **错误码ID** | **错误信息** | 1750| -------- | -------- | 1751| 201 | Permission denied. | 1752| 202 | System API is not allowed called by Non-system application. | 1753| 401 | Invalid parameters. Possible causes: 1.Incorrect parameter types. | 1754| 801 | Capability not supported. | 1755| 2801000 | Operation failed. | 1756| 2801001 | Wi-Fi STA disabled. | 1757 1758**示例:** 1759```ts 1760 import { wifiManager } from '@kit.ConnectivityKit'; 1761 1762 try { 1763 let netId = 0; 1764 wifiManager.deletePersistentGroup(netId); 1765 }catch(error){ 1766 console.error("failed:" + JSON.stringify(error)); 1767 } 1768``` 1769 1770## wifiManager.getP2pGroups<sup>9+</sup> 1771 1772getP2pGroups(): Promise<Array<WifiP2pGroupInfo>> 1773 1774获取创建的所有P2P群组信息,使用Promise异步回调。 1775 1776**系统接口:** 此接口为系统接口。 1777 1778**需要权限:** 1779 1780API 9:ohos.permission.GET_WIFI_INFO、ohos.permission.LOCATION 和 ohos.permission.APPROXIMATELY_LOCATION 1781 1782API 10起:ohos.permission.GET_WIFI_INFO 1783 1784**系统能力:** SystemCapability.Communication.WiFi.P2P 1785 1786**返回值:** 1787 1788| 类型 | 说明 | 1789| -------- | -------- | 1790| Promise< Array<[WifiP2pGroupInfo](js-apis-wifiManager.md#wifip2pgroupinfo9)> > | Promise对象。表示所有群组信息。如果应用申请了ohos.permission.GET_WIFI_PEERS_MAC权限,则返回结果中的deviceAddress为真实设备地址,否则为随机设备地址。 | 1791 1792**错误码:** 1793 1794以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1795 1796| **错误码ID** | **错误信息** | 1797| -------- | -------- | 1798| 201 | Permission denied. | 1799| 202 | System API is not allowed called by Non-system application. | 1800| 801 | Capability not supported. | 1801| 2801000 | Operation failed. | 1802 1803**示例:** 1804```ts 1805 import { wifiManager } from '@kit.ConnectivityKit'; 1806 1807 wifiManager.getP2pGroups((err, data:wifiManager.WifiP2pGroupInfo) => { 1808 if (err) { 1809 console.error("get P2P groups error"); 1810 return; 1811 } 1812 console.info("get P2P groups: " + JSON.stringify(data)); 1813 }); 1814 1815 wifiManager.getP2pGroups().then(data => { 1816 console.info("get P2P groups: " + JSON.stringify(data)); 1817 }); 1818 1819``` 1820 1821 1822## wifiManager.getP2pGroups<sup>9+</sup> 1823 1824getP2pGroups(callback: AsyncCallback<Array<WifiP2pGroupInfo>>): void 1825 1826获取创建的所有P2P群组信息,使用callback方式作为异步方法。 1827 1828**系统接口:** 此接口为系统接口。 1829 1830**需要权限:** 1831 1832API 9:ohos.permission.GET_WIFI_INFO、ohos.permission.LOCATION 和 ohos.permission.APPROXIMATELY_LOCATION 1833 1834API 10起:ohos.permission.GET_WIFI_INFO 1835 1836**系统能力:** SystemCapability.Communication.WiFi.P2P 1837 1838**参数:** 1839 1840| 参数名 | 类型 | 必填 | 说明 | 1841| -------- | -------- | -------- | -------- | 1842| callback | AsyncCallback< Array<[WifiP2pGroupInfo](js-apis-wifiManager.md#wifip2pgroupinfo9)>> | 是 | 回调函数。当操作成功时,err为0,data表示所有群组信息。如果error为非0,表示处理出现错误。如果应用申请了ohos.permission.GET_WIFI_PEERS_MAC权限,则返回结果中的deviceAddress为真实设备地址,否则为随机设备地址。 | 1843 1844**错误码:** 1845 1846以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1847 1848| **错误码ID** | **错误信息** | 1849| -------- | -------- | 1850| 201 | Permission denied. | 1851| 202 | System API is not allowed called by Non-system application. | 1852| 801 | Capability not supported. | 1853| 2801000 | Operation failed. | 1854| 2801001 | Wi-Fi STA disabled. | 1855 1856## wifiManager.setDeviceName<sup>9+</sup> 1857 1858setDeviceName(devName: string): void 1859 1860设置设备名称。 1861 1862**系统接口:** 此接口为系统接口。 1863 1864**需要权限:** ohos.permission.SET_WIFI_INFO 和 ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。 1865 1866**系统能力:** SystemCapability.Communication.WiFi.P2P 1867 1868**参数:** 1869 1870 | **参数名** | **类型** | **必填** | **说明** | 1871 | -------- | -------- | -------- | -------- | 1872 | devName | string | 是 | 设备名称。 | 1873 1874**错误码:** 1875 1876以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1877 1878| **错误码ID** | **错误信息** | 1879| -------- | -------- | 1880| 201 | Permission denied. | 1881| 202 | System API is not allowed called by Non-system application. | 1882| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. | 1883| 801 | Capability not supported. | 1884| 2801000 | Operation failed. | 1885| 2801001 | Wi-Fi STA disabled. | 1886 1887**示例:** 1888```ts 1889 import { wifiManager } from '@kit.ConnectivityKit'; 1890 1891 try { 1892 let name = "****"; 1893 wifiManager.setDeviceName(name); 1894 }catch(error){ 1895 console.error("failed:" + JSON.stringify(error)); 1896 } 1897``` 1898 1899 1900## wifiManager.on('streamChange')<sup>9+</sup> 1901 1902on(type: 'streamChange', callback: Callback<number>): void 1903 1904注册WIFI流变更事件,在业务退出时,要调用off(type: 'streamChange', callback?: Callback<number>)接口去掉之前的注册回调。 1905 1906**系统接口:** 此接口为系统接口。 1907 1908**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION 1909 1910**系统能力:** SystemCapability.Communication.WiFi.STA 1911 1912**参数:** 1913 1914| **参数名** | **类型** | **必填** | **说明** | 1915| -------- | -------- | -------- | -------- | 1916| type | string | 是 | 固定填"streamChange"字符串。 | 1917| callback | Callback<number> | 是 | 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 | 1918 1919**错误码:** 1920 1921以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1922 1923| **错误码ID** | **错误信息** | 1924| -------- | -------- | 1925| 201 | Permission denied. | 1926| 202 | System API is not allowed called by Non-system application. | 1927| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1928| 801 | Capability not supported. | 1929| 2501000 | Operation failed.| 1930 1931## wifiManager.off('streamChange')<sup>9+</sup> 1932 1933off(type: 'streamChange', callback?: Callback<number>): void 1934 1935取消注册WIFI流变更事件。 1936 1937**系统接口:** 此接口为系统接口。 1938 1939**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION 1940 1941**系统能力:** SystemCapability.Communication.WiFi.STA 1942 1943**参数:** 1944 1945| **参数名** | **类型** | **必填** | **说明** | 1946| -------- | -------- | -------- | -------- | 1947| type | string | 是 | 固定填"streamChange"字符串。 | 1948| callback | Callback<number> | 否 | 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 | 1949 1950**错误码:** 1951 1952以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1953 1954| **错误码ID** | **错误信息** | 1955| -------- | -------- | 1956| 201 | Permission denied. | 1957| 202 | System API is not allowed called by Non-system application. | 1958| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 1959| 801 | Capability not supported. | 1960| 2501000 | Operation failed.| 1961 1962**示例:** 1963```ts 1964import { wifi } from '@kit.ConnectivityKit'; 1965 1966let recvStreamChangeFunc = (result:number) => { 1967 console.info("Receive stream change event: " + result); 1968} 1969 1970// Register event 1971wifi.on("streamChange", recvStreamChangeFunc); 1972 1973// Unregister event 1974wifi.off("streamChange", recvStreamChangeFunc); 1975 1976``` 1977## wifiManager.on('deviceConfigChange')<sup>9+</sup> 1978 1979on(type: 'deviceConfigChange', callback: Callback<number>): void 1980 1981注册WIFI设备配置更改事件,在业务退出时,要调用off(type: 'deviceConfigChange', callback?: Callback<number>)接口去掉之前的注册回调。 1982 1983**系统接口:** 此接口为系统接口。 1984 1985**需要权限:** ohos.permission.GET_WIFI_INFO 1986 1987**系统能力:** SystemCapability.Communication.WiFi.STA 1988 1989**参数:** 1990 1991| **参数名** | **类型** | **必填** | **说明** | 1992| -------- | -------- | -------- | -------- | 1993| type | string | 是 | 固定填"deviceConfigChange"字符串。 | 1994| callback | Callback<number> | 是 | 状态改变回调函数,返回0: 添加配置, 1: 更改配置, 2: 删除配置. | 1995 1996**错误码:** 1997 1998以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 1999 2000| **错误码ID** | **错误信息** | 2001| -------- | -------- | 2002| 201 | Permission denied. | 2003| 202 | System API is not allowed called by Non-system application. | 2004| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2005| 801 | Capability not supported. | 2006| 2501000 | Operation failed.| 2007 2008## wifiManager.off('deviceConfigChange')<sup>9+</sup> 2009 2010off(type: 'deviceConfigChange', callback?: Callback<number>): void 2011 2012取消注册WIFI设备配置更改事件。 2013 2014**系统接口:** 此接口为系统接口。 2015 2016**需要权限:** ohos.permission.GET_WIFI_INFO 2017 2018**系统能力:** SystemCapability.Communication.WiFi.STA 2019 2020**参数:** 2021 2022| **参数名** | **类型** | **必填** | **说明** | 2023| -------- | -------- | -------- | -------- | 2024| type | string | 是 | 固定填"deviceConfigChange"字符串。 | 2025| callback | Callback<number> | 否 | 状态改变回调函数,返回0: 添加配置, 1: 更改配置, 2: 删除配置.| 2026 2027**错误码:** 2028 2029以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 2030 2031| **错误码ID** | **错误信息** | 2032| -------- | -------- | 2033| 201 | Permission denied. | 2034| 202 | System API is not allowed called by Non-system application. | 2035| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2036| 801 | Capability not supported. | 2037| 2501000 | Operation failed.| 2038 2039**示例:** 2040```ts 2041import { wifiManager } from '@kit.ConnectivityKit'; 2042 2043let recvDeviceConfigChangeFunc = (result:number) => { 2044 console.info("Receive device config change event: " + result); 2045} 2046 2047// Register event 2048wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc); 2049 2050// Unregister event 2051wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc); 2052 2053``` 2054 2055## wifiManager.on('hotspotStaJoin')<sup>9+</sup> 2056 2057on(type: 'hotspotStaJoin', callback: Callback<StationInfo>): void 2058 2059注册wifi热点sta加入事件,在业务退出时,要调用off(type: 'hotspotStaJoin', callback?: Callback<StationInfo>)接口去掉之前的注册回调。 2060 2061**系统接口:** 此接口为系统接口。 2062 2063**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT 2064 2065**系统能力:** SystemCapability.Communication.WiFi.AP.Core 2066 2067**参数:** 2068 2069| **参数名** | **类型** | **必填** | **说明** | 2070| -------- | -------- | -------- | -------- | 2071| type | string | 是 | 固定填"hotspotStaJoin"字符串。 | 2072| callback | Callback<StationInfo> | 是 | 状态改变回调函数。 | 2073 2074**错误码:** 2075 2076以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 2077 2078| **错误码ID** | **错误信息** | 2079| -------- | -------- | 2080| 201 | Permission denied. | 2081| 202 | System API is not allowed called by Non-system application. | 2082| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2083| 801 | Capability not supported. | 2084| 2601000 | Operation failed. | 2085 2086## wifiManager.off('hotspotStaJoin')<sup>9+</sup> 2087 2088off(type: 'hotspotStaJoin', callback?: Callback<StationInfo>): void 2089 2090取消注册wifi热点sta加入事件。 2091 2092**系统接口:** 此接口为系统接口。 2093 2094**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT 2095 2096**系统能力:** SystemCapability.Communication.WiFi.AP.Core 2097 2098**参数:** 2099 2100| **参数名** | **类型** | **必填** | **说明** | 2101| -------- | -------- | -------- | -------- | 2102| type | string | 是 | 固定填"hotspotStaJoin"字符串。 | 2103| callback | Callback<StationInfo> | 否 | 状态改变回调函数。 | 2104 2105**错误码:** 2106 2107以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 2108 2109| **错误码ID** | **错误信息** | 2110| -------- | -------- | 2111| 201 | Permission denied. | 2112| 202 | System API is not allowed called by Non-system application. | 2113| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2114| 801 | Capability not supported. | 2115| 2601000 | Operation failed. | 2116 2117**示例:** 2118```ts 2119import { wifiManager } from '@kit.ConnectivityKit'; 2120 2121let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => { 2122 console.info("Receive hotspot sta join event: " + result); 2123} 2124 2125// Register event 2126wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc); 2127 2128// Unregister event 2129wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc); 2130 2131``` 2132 2133## wifiManager.on('hotspotStaLeave')<sup>9+</sup> 2134 2135on(type: 'hotspotStaLeave', callback: Callback<StationInfo>): void 2136 2137注册wifi热点sta离开事件,在业务退出时,要调用off(type: 'hotspotStaLeave', callback?: Callback<StationInfo>)接口去掉之前的注册回调。 2138 2139**系统接口:** 此接口为系统接口。 2140 2141**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT 2142 2143**系统能力:** SystemCapability.Communication.WiFi.AP.Core 2144 2145**参数:** 2146 2147 | **参数名** | **类型** | **必填** | **说明** | 2148 | -------- | -------- | -------- | -------- | 2149 | type | string | 是 | 固定填"hotspotStaLeave"字符串。 | 2150 | callback | Callback<StationInf]> | 是 | 状态改变回调函数。 | 2151 2152**错误码:** 2153 2154以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 2155 2156| **错误码ID** | **错误信息** | 2157| -------- | -------- | 2158| 201 | Permission denied. | 2159| 202 | System API is not allowed called by Non-system application. | 2160| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2161| 801 | Capability not supported. | 2162| 2601000 | Operation failed. | 2163 2164## wifiManager.off('hotspotStaLeave')<sup>9+</sup> 2165 2166off(type: 'hotspotStaLeave', callback?: Callback<StationInfo>): void 2167 2168取消注册wifi热点sta离开事件。 2169 2170**系统接口:** 此接口为系统接口。 2171 2172**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT 2173 2174**系统能力:** SystemCapability.Communication.WiFi.AP.Core 2175 2176**参数:** 2177 2178| **参数名** | **类型** | **必填** | **说明** | 2179| -------- | -------- | -------- | -------- | 2180| type | string | 是 | 固定填"hotspotStaLeave"字符串。 | 2181| callback | Callback<StationInf]> | 否 | 状态改变回调函数。 | 2182 2183**错误码:** 2184 2185以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。 2186 2187| **错误码ID** | **错误信息** | 2188| -------- | -------- | 2189| 201 | Permission denied. | 2190| 202 | System API is not allowed called by Non-system application. | 2191| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 2192| 801 | Capability not supported. | 2193| 2601000 | Operation failed. | 2194 2195**示例:** 2196```ts 2197import { wifiManager } from '@kit.ConnectivityKit'; 2198 2199let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => { 2200 console.info("Receive hotspot sta leave event: " + result); 2201} 2202 2203// Register event 2204wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc); 2205 2206// Unregister event 2207wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc); 2208 2209``` 2210 2211