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