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