• 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 | 是 | 是否始终允许扫描。 |
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_CONFIGohos.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>9+</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.setHotspotConfig<sup>9+</sup>
1065
1066setHotspotConfig(config: HotspotConfig): void
1067
1068设置热点配置信息。
1069
1070**系统接口:** 此接口为系统接口。
1071
1072**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.GET_WIFI_CONFIG
1073
1074**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1075
1076**参数:**
1077
1078  | **参数名** | **类型** | **必填** | **说明** |
1079  | -------- | -------- | -------- | -------- |
1080  | config | [HotspotConfig](#hotspotconfig9) | 是 | 热点配置信息。 |
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| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1091| 801 | Capability not supported.          |
1092| 2601000  | Operation failed. |
1093
1094**示例:**
1095```ts
1096	import { wifiManager } from '@kit.ConnectivityKit';
1097
1098	try {
1099		let config:wifiManager.HotspotConfig = {
1100			ssid: "****",
1101			securityType: 3,
1102			band: 0,
1103			channel: 0,
1104			preSharedKey: "****",
1105			maxConn: 0
1106		}
1107		let ret = wifiManager.setHotspotConfig(config);
1108		console.info("result:" + ret);
1109	}catch(error){
1110		console.error("failed:" + JSON.stringify(error));
1111	}
1112```
1113
1114## HotspotConfig<sup>9+</sup>
1115
1116热点配置信息。
1117
1118**系统接口:** 此接口为系统接口。
1119
1120**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1121
1122| **名称** | **类型** | **可读** | **可写** | **说明** |
1123| -------- | -------- | -------- | -------- | -------- |
1124| ssid | string | 是 | 是 | 热点的SSID,编码格式为UTF-8。 |
1125| securityType | [WifiSecurityType](js-apis-wifiManager.md#wifisecuritytype9)| 是 | 是 | 加密类型。 |
1126| band | number | 是 | 是 | 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 |
1127| channel<sup>10+</sup> | number | 是 | 是 | 热点的信道(2.4G:1~14,5G:7~196)。 |
1128| preSharedKey | string | 是 | 是 | 热点的密钥。 |
1129| maxConn | number | 是 | 是 | 最大设备连接数。 |
1130
1131## wifiManager.getHotspotConfig<sup>9+</sup>
1132
1133getHotspotConfig(): HotspotConfig
1134
1135获取热点配置信息。
1136
1137**系统接口:** 此接口为系统接口。
1138
1139**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.GET_WIFI_CONFIG
1140
1141**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1142
1143**返回值:**
1144
1145  | **类型** | **说明** |
1146  | -------- | -------- |
1147  | [HotspotConfig](#hotspotconfig9) | 热点的配置信息。 |
1148
1149**错误码:**
1150
1151以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1152
1153| **错误码ID** | **错误信息** |
1154| -------- | -------- |
1155| 201 | Permission denied.                 |
1156| 202 | System API is not allowed called by Non-system application. |
1157| 801 | Capability not supported.          |
1158| 2601000  | Operation failed. |
1159
1160**示例:**
1161```ts
1162	import { wifiManager } from '@kit.ConnectivityKit';
1163
1164	try {
1165		let config = wifiManager.getHotspotConfig();
1166		console.info("result:" + JSON.stringify(config));
1167	}catch(error){
1168		console.error("failed:" + JSON.stringify(error));
1169	}
1170```
1171
1172## wifiManager.getStations<sup>9+</sup>
1173
1174getStations(): &nbsp;Array&lt;StationInfo&gt;
1175
1176获取连接的设备。
1177
1178**系统接口:** 此接口为系统接口。
1179
1180**需要权限:**
1181
1182API 9:ohos.permission.GET_WIFI_INFOohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATIONohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1183
1184API 10起:ohos.permission.GET_WIFI_INFOohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1185
1186**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1187
1188**返回值:**
1189
1190| **类型** | **说明** |
1191| -------- | -------- |
1192| &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; | 连接的设备数组。如果应用申请了ohos.permission.GET_WIFI_PEERS_MAC权限,则返回结果中的macAddress为真实设备地址,否则为随机设备地址。 |
1193
1194**错误码:**
1195
1196以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1197
1198| **错误码ID** | **错误信息** |
1199| -------- | -------- |
1200| 201 | Permission denied.                 |
1201| 202 | System API is not allowed called by Non-system application. |
1202| 801 | Capability not supported.          |
1203| 2601000  | Operation failed. |
1204
1205**示例:**
1206```ts
1207	import { wifiManager } from '@kit.ConnectivityKit';
1208
1209	try {
1210		let stations = wifiManager.getStations();
1211		console.info("result:" + JSON.stringify(stations));
1212	}catch(error){
1213		console.error("failed:" + JSON.stringify(error));
1214	}
1215```
1216
1217## StationInfo<sup>9+</sup>
1218
1219接入的设备信息。
1220
1221**系统接口:** 此接口为系统接口。
1222
1223**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1224
1225| **名称** | **类型** | **可读** | **可写** | **说明** |
1226| -------- | -------- | -------- | -------- | -------- |
1227| name | string | 是 | 否 | 设备名称。 |
1228| macAddress | string | 是 | 否 | MAC地址。 |
1229| macAddressType<sup>10+</sup> | [DeviceAddressType](js-apis-wifiManager.md#deviceaddresstype10) | 是 | 否 | MAC地址类型。 |
1230| ipAddress | string | 是 | 否 | IP地址。 |
1231
1232## wifiManager.addHotspotBlockList<sup>11+</sup>
1233
1234addHotspotBlockList(stationInfo: StationInfo)
1235
1236将设备添加到热点的阻止连接设备列表中,列表中的设备将不能访问热点。
1237
1238**系统接口:** 此接口为系统接口。
1239
1240**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1241
1242**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1243
1244**参数:**
1245
1246| **参数名** | **类型** | **必填** | **说明** |
1247| -------- | -------- | -------- | -------- |
1248| stationInfo | [StationInfo](#stationinfo9) | 是 | 将添加到热点的阻止列表中的设备。 |
1249
1250**错误码:**
1251
1252以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1253
1254| **错误码ID** | **错误信息** |
1255| -------- | -------- |
1256| 201 | Permission denied.                 |
1257| 202 | System API is not allowed called by Non-system application. |
1258| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1259| 801 | Capability not supported.          |
1260| 2601000  | Operation failed. |
1261
1262**示例:**
1263
1264```ts
1265	import { wifiManager } from '@kit.ConnectivityKit';
1266
1267	try {
1268		let config:wifiManager.StationInfo = {
1269			name : "testSsid",
1270			macAddress : "11:22:33:44:55:66",
1271			ipAddress : "192.168.1.111"
1272		}
1273		// 热点开启后,才能正常将设备添加到连接阻止列表中
1274		wifiManager.addHotspotBlockList(config);
1275	}catch(error){
1276		console.error("failed:" + JSON.stringify(error));
1277	}
1278```
1279
1280## wifiManager.delHotspotBlockList<sup>11+</sup>
1281
1282delHotspotBlockList(stationInfo: StationInfo)
1283
1284将设备从热点的阻止列表中删除。
1285
1286**系统接口:** 此接口为系统接口。
1287
1288**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1289
1290**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1291
1292**参数:**
1293
1294| **参数名** | **类型** | **必填** | **说明** |
1295| -------- | -------- | -------- | -------- |
1296| stationInfo | [StationInfo](#stationinfo9) | 是 | 将从热点的阻止列表中删除的设备。 |
1297
1298**错误码:**
1299
1300以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1301
1302| **错误码ID** | **错误信息** |
1303| -------- | -------- |
1304| 201 | Permission denied.                 |
1305| 202 | System API is not allowed called by Non-system application. |
1306| 401 | Invalid parameters. Possible causes: 1. Incorrect parameter types.<br>2. Parameter verification failed. |
1307| 801 | Capability not supported.          |
1308| 2601000  | Operation failed. |
1309
1310**示例:**
1311
1312```ts
1313	import { wifiManager } from '@kit.ConnectivityKit';
1314
1315	try {
1316		let config:wifiManager.StationInfo = {
1317			name : "testSsid",
1318			macAddress : "11:22:33:44:55:66",
1319			ipAddress : "192.168.1.111"
1320		}
1321		wifiManager.delHotspotBlockList(config);
1322	}catch(error){
1323		console.error("failed:" + JSON.stringify(error));
1324	}
1325```
1326
1327## wifiManager.getHotspotBlockList<sup>11+</sup>
1328
1329getHotspotBlockList(): Array&lt;StationInfo&gt;
1330
1331获取热点的阻止列表。
1332
1333**系统接口:** 此接口为系统接口。
1334
1335**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1336
1337**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1338
1339**返回值:**
1340
1341| **类型** | **说明** |
1342| -------- | -------- |
1343| &nbsp;Array&lt;[StationInfo](#stationinfo9)&gt; | 热点的阻止列表。 |
1344
1345**错误码:**
1346
1347以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1348
1349| **错误码ID** | **错误信息** |
1350  | -------- | -------- |
1351| 201 | Permission denied.                 |
1352| 202 | System API is not allowed called by Non-system application. |
1353| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. |
1354| 801 | Capability not supported.          |
1355| 2601000  | Operation failed. |
1356
1357**示例:**
1358
1359```ts
1360	import { wifiManager } from '@kit.ConnectivityKit';
1361
1362	try {
1363		let data = wifiManager.getHotspotBlockList();
1364		console.info("result:" + JSON.stringify(data));
1365	}catch(error){
1366		console.error("failed:" + JSON.stringify(error));
1367	}
1368```
1369
1370## wifiManager.deletePersistentGroup<sup>9+</sup>
1371
1372deletePersistentGroup(netId: number): void
1373
1374删除永久组。
1375
1376**系统接口:** 此接口为系统接口。
1377
1378**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION
1379
1380**系统能力:** SystemCapability.Communication.WiFi.P2P
1381
1382**参数:**
1383
1384
1385  | **参数名** | **类型** | 必填 | **说明** |
1386  | -------- | -------- | -------- | -------- |
1387  | netId | number | 是 | 组的ID。 |
1388
1389**错误码:**
1390
1391以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1392
1393| **错误码ID** | **错误信息** |
1394| -------- | -------- |
1395| 201 | Permission denied.                 |
1396| 202 | System API is not allowed called by Non-system application. |
1397| 401 | Invalid parameters. Possible causes: 1.Incorrect parameter types. |
1398| 801 | Capability not supported.          |
1399| 2801000  | Operation failed. |
1400| 2801001  | Wi-Fi STA disabled. |
1401
1402**示例:**
1403```ts
1404	import { wifiManager } from '@kit.ConnectivityKit';
1405
1406	try {
1407		let netId = 0;
1408		wifiManager.deletePersistentGroup(netId);
1409	}catch(error){
1410		console.error("failed:" + JSON.stringify(error));
1411	}
1412```
1413
1414## wifiManager.getP2pGroups<sup>9+</sup>
1415
1416getP2pGroups(): Promise&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;
1417
1418获取创建的所有P2P群组信息,使用Promise异步回调。
1419
1420**系统接口:** 此接口为系统接口。
1421
1422**需要权限:**
1423
1424API 9:ohos.permission.GET_WIFI_INFOohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
1425
1426API 10起:ohos.permission.GET_WIFI_INFO
1427
1428**系统能力:** SystemCapability.Communication.WiFi.P2P
1429
1430**返回值:**
1431
1432| 类型 | 说明 |
1433| -------- | -------- |
1434| Promise&lt;&nbsp;Array&lt;[WifiP2pGroupInfo](js-apis-wifiManager.md#wifip2pgroupinfo9)&gt;&nbsp;&gt; | Promise对象。表示所有群组信息。如果应用申请了ohos.permission.GET_WIFI_PEERS_MAC权限,则返回结果中的deviceAddress为真实设备地址,否则为随机设备地址。 |
1435
1436**错误码:**
1437
1438以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1439
1440| **错误码ID** | **错误信息** |
1441| -------- | -------- |
1442| 201 | Permission denied.                 |
1443| 202 | System API is not allowed called by Non-system application. |
1444| 801 | Capability not supported.          |
1445| 2801000  | Operation failed. |
1446
1447**示例:**
1448```ts
1449	import { wifiManager } from '@kit.ConnectivityKit';
1450
1451	wifiManager.getP2pGroups((err, data:wifiManager.WifiP2pGroupInfo) => {
1452    if (err) {
1453        console.error("get P2P groups error");
1454        return;
1455    }
1456		console.info("get P2P groups: " + JSON.stringify(data));
1457	});
1458
1459	wifiManager.getP2pGroups().then(data => {
1460		console.info("get P2P groups: " + JSON.stringify(data));
1461	});
1462
1463```
1464
1465
1466## wifiManager.getP2pGroups<sup>9+</sup>
1467
1468getP2pGroups(callback: AsyncCallback&lt;Array&lt;WifiP2pGroupInfo&gt;&gt;): void
1469
1470获取创建的所有P2P群组信息,使用callback方式作为异步方法。
1471
1472**系统接口:** 此接口为系统接口。
1473
1474**需要权限:**
1475
1476API 9:ohos.permission.GET_WIFI_INFOohos.permission.LOCATIONohos.permission.APPROXIMATELY_LOCATION
1477
1478API 10起:ohos.permission.GET_WIFI_INFO
1479
1480**系统能力:** SystemCapability.Communication.WiFi.P2P
1481
1482**参数:**
1483
1484| 参数名 | 类型 | 必填 | 说明 |
1485| -------- | -------- | -------- | -------- |
1486| 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为真实设备地址,否则为随机设备地址。 |
1487
1488**错误码:**
1489
1490以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1491
1492| **错误码ID** | **错误信息** |
1493| -------- | -------- |
1494| 201 | Permission denied.                 |
1495| 202 | System API is not allowed called by Non-system application. |
1496| 801 | Capability not supported.          |
1497| 2801000  | Operation failed. |
1498| 2801001  | Wi-Fi STA disabled. |
1499
1500## wifiManager.setDeviceName<sup>9+</sup>
1501
1502setDeviceName(devName: string): void
1503
1504设置设备名称。
1505
1506**系统接口:** 此接口为系统接口。
1507
1508**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1509
1510**系统能力:** SystemCapability.Communication.WiFi.P2P
1511
1512**参数:**
1513
1514  | **参数名** | **类型** | **必填** | **说明** |
1515  | -------- | -------- | -------- | -------- |
1516  | devName | string | 是 | 设备名称。 |
1517
1518**错误码:**
1519
1520以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1521
1522| **错误码ID** | **错误信息** |
1523| -------- | -------- |
1524| 201 | Permission denied.                 |
1525| 202 | System API is not allowed called by Non-system application. |
1526| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified.<br>2. Incorrect parameter types. 3. Parameter verification failed. |
1527| 801 | Capability not supported.          |
1528| 2801000  | Operation failed. |
1529| 2801001  | Wi-Fi STA disabled. |
1530
1531**示例:**
1532```ts
1533	import { wifiManager } from '@kit.ConnectivityKit';
1534
1535	try {
1536		let name = "****";
1537		wifiManager.setDeviceName(name);
1538	}catch(error){
1539		console.error("failed:" + JSON.stringify(error));
1540	}
1541```
1542
1543
1544## wifiManager.on('streamChange')<sup>9+</sup>
1545
1546on(type: 'streamChange', callback: Callback&lt;number&gt;): void
1547
1548注册WIFI流变更事件,在业务退出时,要调用off(type: 'streamChange', callback?: Callback&lt;number&gt;)接口去掉之前的注册回调。
1549
1550**系统接口:** 此接口为系统接口。
1551
1552**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION
1553
1554**系统能力:** SystemCapability.Communication.WiFi.STA
1555
1556**参数:**
1557
1558| **参数名** | **类型** | **必填** | **说明** |
1559| -------- | -------- | -------- | -------- |
1560| type | string | 是 | 固定填"streamChange"字符串。 |
1561| callback | Callback&lt;number&gt; | 是 | 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 |
1562
1563**错误码:**
1564
1565以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1566
1567| **错误码ID** | **错误信息** |
1568| -------- | -------- |
1569| 201 | Permission denied.                 |
1570| 202 | System API is not allowed called by Non-system application. |
1571| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1572| 801 | Capability not supported.          |
1573| 2501000  | Operation failed.|
1574
1575## wifiManager.off('streamChange')<sup>9+</sup>
1576
1577off(type: 'streamChange', callback?: Callback&lt;number&gt;): void
1578
1579取消注册WIFI流变更事件。
1580
1581**系统接口:** 此接口为系统接口。
1582
1583**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION
1584
1585**系统能力:** SystemCapability.Communication.WiFi.STA
1586
1587**参数:**
1588
1589| **参数名** | **类型** | **必填** | **说明** |
1590| -------- | -------- | -------- | -------- |
1591| type | string | 是 | 固定填"streamChange"字符串。 |
1592| callback | Callback&lt;number&gt; | 否 | 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 |
1593
1594**错误码:**
1595
1596以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1597
1598| **错误码ID** | **错误信息** |
1599| -------- | -------- |
1600| 201 | Permission denied.                 |
1601| 202 | System API is not allowed called by Non-system application. |
1602| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1603| 801 | Capability not supported.          |
1604| 2501000  | Operation failed.|
1605
1606**示例:**
1607```ts
1608import { wifi } from '@kit.ConnectivityKit';
1609
1610let recvStreamChangeFunc = (result:number) => {
1611    console.info("Receive stream change event: " + result);
1612}
1613
1614// Register event
1615wifi.on("streamChange", recvStreamChangeFunc);
1616
1617// Unregister event
1618wifi.off("streamChange", recvStreamChangeFunc);
1619
1620```
1621## wifiManager.on('deviceConfigChange')<sup>9+</sup>
1622
1623on(type: 'deviceConfigChange', callback: Callback&lt;number&gt;): void
1624
1625注册WIFI设备配置更改事件,在业务退出时,要调用off(type: 'deviceConfigChange', callback?: Callback&lt;number&gt;)接口去掉之前的注册回调。
1626
1627**系统接口:** 此接口为系统接口。
1628
1629**需要权限:** ohos.permission.GET_WIFI_INFO
1630
1631**系统能力:** SystemCapability.Communication.WiFi.STA
1632
1633**参数:**
1634
1635| **参数名** | **类型** | **必填** | **说明** |
1636| -------- | -------- | -------- | -------- |
1637| type | string | 是 | 固定填"deviceConfigChange"字符串。 |
1638| callback | Callback&lt;number&gt; | 是 | 状态改变回调函数,返回0: 添加配置, 1: 更改配置, 2: 删除配置. |
1639
1640**错误码:**
1641
1642以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1643
1644| **错误码ID** | **错误信息** |
1645| -------- | -------- |
1646| 201 | Permission denied.                 |
1647| 202 | System API is not allowed called by Non-system application. |
1648| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1649| 801 | Capability not supported.          |
1650| 2501000  | Operation failed.|
1651
1652## wifiManager.off('deviceConfigChange')<sup>9+</sup>
1653
1654off(type: 'deviceConfigChange', callback?: Callback&lt;number&gt;): void
1655
1656取消注册WIFI设备配置更改事件。
1657
1658**系统接口:** 此接口为系统接口。
1659
1660**需要权限:** ohos.permission.GET_WIFI_INFO
1661
1662**系统能力:** SystemCapability.Communication.WiFi.STA
1663
1664**参数:**
1665
1666| **参数名** | **类型** | **必填** | **说明** |
1667| -------- | -------- | -------- | -------- |
1668| type | string | 是 | 固定填"deviceConfigChange"字符串。 |
1669| callback | Callback&lt;number&gt; | 否 | 状态改变回调函数,返回0: 添加配置, 1: 更改配置, 2: 删除配置.|
1670
1671**错误码:**
1672
1673以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1674
1675| **错误码ID** | **错误信息** |
1676| -------- | -------- |
1677| 201 | Permission denied.                 |
1678| 202 | System API is not allowed called by Non-system application. |
1679| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1680| 801 | Capability not supported.          |
1681| 2501000  | Operation failed.|
1682
1683**示例:**
1684```ts
1685import { wifiManager } from '@kit.ConnectivityKit';
1686
1687let recvDeviceConfigChangeFunc = (result:number) => {
1688    console.info("Receive device config change event: " + result);
1689}
1690
1691// Register event
1692wifi.on("deviceConfigChange", recvDeviceConfigChangeFunc);
1693
1694// Unregister event
1695wifi.off("deviceConfigChange", recvDeviceConfigChangeFunc);
1696
1697```
1698
1699## wifiManager.on('hotspotStaJoin')<sup>9+</sup>
1700
1701on(type: 'hotspotStaJoin', callback: Callback&lt;StationInfo&gt;): void
1702
1703注册wifi热点sta加入事件,在业务退出时,要调用off(type: 'hotspotStaJoin', callback?: Callback&lt;StationInfo&gt;)接口去掉之前的注册回调。
1704
1705**系统接口:** 此接口为系统接口。
1706
1707**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
1708
1709**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1710
1711**参数:**
1712
1713| **参数名** | **类型** | **必填** | **说明** |
1714| -------- | -------- | -------- | -------- |
1715| type | string | 是 | 固定填"hotspotStaJoin"字符串。 |
1716| callback | Callback&lt;StationInfo&gt; | 是 | 状态改变回调函数。 |
1717
1718**错误码:**
1719
1720以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1721
1722| **错误码ID** | **错误信息** |
1723| -------- | -------- |
1724| 201 | Permission denied.                 |
1725| 202 | System API is not allowed called by Non-system application. |
1726| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1727| 801 | Capability not supported.          |
1728| 2601000  | Operation failed. |
1729
1730## wifiManager.off('hotspotStaJoin')<sup>9+</sup>
1731
1732off(type: 'hotspotStaJoin', callback?: Callback&lt;StationInfo&gt;): void
1733
1734取消注册wifi热点sta加入事件。
1735
1736**系统接口:** 此接口为系统接口。
1737
1738**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
1739
1740**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1741
1742**参数:**
1743
1744| **参数名** | **类型** | **必填** | **说明** |
1745| -------- | -------- | -------- | -------- |
1746| type | string | 是 | 固定填"hotspotStaJoin"字符串。 |
1747| callback | Callback&lt;StationInfo&gt; | 否 | 状态改变回调函数。 |
1748
1749**错误码:**
1750
1751以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1752
1753| **错误码ID** | **错误信息** |
1754| -------- | -------- |
1755| 201 | Permission denied.                 |
1756| 202 | System API is not allowed called by Non-system application. |
1757| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1758| 801 | Capability not supported.          |
1759| 2601000  | Operation failed. |
1760
1761**示例:**
1762```ts
1763import { wifiManager } from '@kit.ConnectivityKit';
1764
1765let recvHotspotStaJoinFunc = (result:wifiManager.StationInfo) => {
1766    console.info("Receive hotspot sta join event: " + result);
1767}
1768
1769// Register event
1770wifiManager.on("hotspotStaJoin", recvHotspotStaJoinFunc);
1771
1772// Unregister event
1773wifiManager.off("hotspotStaJoin", recvHotspotStaJoinFunc);
1774
1775```
1776
1777## wifiManager.on('hotspotStaLeave')<sup>9+</sup>
1778
1779on(type: 'hotspotStaLeave', callback: Callback&lt;StationInfo&gt;): void
1780
1781注册wifi热点sta离开事件,在业务退出时,要调用off(type: 'hotspotStaLeave', callback?: Callback&lt;StationInfo&gt;)接口去掉之前的注册回调。
1782
1783**系统接口:** 此接口为系统接口。
1784
1785**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
1786
1787**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1788
1789**参数:**
1790
1791  | **参数名** | **类型** | **必填** | **说明** |
1792  | -------- | -------- | -------- | -------- |
1793  | type | string | 是 | 固定填"hotspotStaLeave"字符串。 |
1794  | callback | Callback&lt;StationInf]&gt; | 是 | 状态改变回调函数。 |
1795
1796**错误码:**
1797
1798以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1799
1800| **错误码ID** | **错误信息** |
1801| -------- | -------- |
1802| 201 | Permission denied.                 |
1803| 202 | System API is not allowed called by Non-system application. |
1804| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1805| 801 | Capability not supported.          |
1806| 2601000  | Operation failed. |
1807
1808## wifiManager.off('hotspotStaLeave')<sup>9+</sup>
1809
1810off(type: 'hotspotStaLeave', callback?: Callback&lt;StationInfo&gt;): void
1811
1812取消注册wifi热点sta离开事件。
1813
1814**系统接口:** 此接口为系统接口。
1815
1816**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
1817
1818**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1819
1820**参数:**
1821
1822| **参数名** | **类型** | **必填** | **说明** |
1823| -------- | -------- | -------- | -------- |
1824| type | string | 是 | 固定填"hotspotStaLeave"字符串。 |
1825| callback | Callback&lt;StationInf]&gt; | 否 | 状态改变回调函数。 |
1826
1827**错误码:**
1828
1829以下错误码的详细介绍请参见[WIFI错误码](errorcode-wifi.md)。
1830
1831| **错误码ID** | **错误信息** |
1832| -------- | -------- |
1833| 201 | Permission denied.                 |
1834| 202 | System API is not allowed called by Non-system application. |
1835| 401 | Invalid parameters. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1836| 801 | Capability not supported.          |
1837| 2601000  | Operation failed. |
1838
1839**示例:**
1840```ts
1841import { wifiManager } from '@kit.ConnectivityKit';
1842
1843let recvHotspotStaLeaveFunc = (result:wifiManager.StationInfo) => {
1844    console.info("Receive hotspot sta leave event: " + result);
1845}
1846
1847// Register event
1848wifiManager.on("hotspotStaLeave", recvHotspotStaLeaveFunc);
1849
1850// Unregister event
1851wifiManager.off("hotspotStaLeave", recvHotspotStaLeaveFunc);
1852
1853```
1854
1855