• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.wifi (WLAN)
2
3该模块主要提供WLAN基础功能、P2P(peer-to-peer)功能和WLAN消息通知的相应服务,让应用可以通过WLAN和其他设备互联互通。
4
5> **说明:**
6>
7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9
10## 导入模块
11
12```ts
13import wifi from '@ohos.wifi';
14```
15
16## wifi.enableWifi
17
18enableWifi(): boolean
19
20使能WLAN。
21
22**系统接口:** 此接口为系统接口。
23
24**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
25
26**系统能力:** SystemCapability.Communication.WiFi.STA
27
28**返回值:**
29
30  | **类型** | **说明** |
31  | -------- | -------- |
32  | boolean | true:操作成功, false:操作失败。|
33
34**示例:**
35
36```ts
37import wifi from '@ohos.wifi';
38
39try {
40	wifi.enableWifi();
41}catch(error){
42	console.error("failed:" + JSON.stringify(error));
43}
44```
45
46## wifi.disableWifi
47
48disableWifi(): boolean
49
50去使能WLAN。
51
52**系统接口:** 此接口为系统接口。
53
54**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
55
56**系统能力:** SystemCapability.Communication.WiFi.STA
57
58**返回值:**
59
60  | **类型** | **说明** |
61  | -------- | -------- |
62  | boolean | true:操作成功, false:操作失败。|
63
64**示例:**
65
66```ts
67import wifi from '@ohos.wifi';
68
69try {
70	wifi.disableWifi();
71}catch(error){
72	console.error("failed:" + JSON.stringify(error));
73}
74
75```
76
77## wifi.isWifiActive
78
79isWifiActive(): boolean
80
81查询WLAN是否已使能。
82
83**需要权限:** ohos.permission.GET_WIFI_INFO
84
85**系统能力:** SystemCapability.Communication.WiFi.STA
86
87**返回值:**
88
89  | **类型** | **说明** |
90  | -------- | -------- |
91  | boolean | true:已使能, false:未使能。 |
92
93**示例:**
94
95```ts
96import wifi from '@ohos.wifi';
97
98try {
99	let isWifiActive = wifi.isWifiActive();
100	console.info("isWifiActive:" + isWifiActive);
101}catch(error){
102	console.error("failed:" + JSON.stringify(error));
103}
104```
105
106## wifi.scan
107
108scan(): boolean
109
110启动WLAN扫描。
111
112**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.LOCATION
113
114**系统能力:** SystemCapability.Communication.WiFi.STA
115
116**返回值:**
117
118  | **类型** | **说明** |
119  | -------- | -------- |
120  | boolean | true:扫描操作执行成功, false:扫描操作执行失败。 |
121
122**示例:**
123
124```ts
125import wifi from '@ohos.wifi';
126
127try {
128	wifi.scan();
129}catch(error){
130	console.error("failed:" + JSON.stringify(error));
131}
132```
133
134## wifi.getScanInfos
135
136getScanInfos(): Promise<Array<WifiScanInfo>>
137
138获取扫描结果,使用Promise异步回调。
139
140**需要权限:** ohos.permission.GET_WIFI_INFO 和 (ohos.permission.GET_WIFI_PEERS_MACohos.permission.LOCATION)
141
142**系统能力:** SystemCapability.Communication.WiFi.STA
143
144**返回值:**
145
146  | **类型** | **说明** |
147  | -------- | -------- |
148  | Promise< Array<[WifiScanInfo](#wifiscaninfo)> > | Promise对象。返回扫描到的热点列表。 |
149
150
151## wifi.getScanInfos
152
153getScanInfos(callback: AsyncCallback<Array<WifiScanInfo>>): void
154
155获取扫描结果,使用callback异步回调。
156
157**需要权限:** ohos.permission.GET_WIFI_INFO 和 (ohos.permission.GET_WIFI_PEERS_MACohos.permission.LOCATION)
158
159**系统能力:** SystemCapability.Communication.WiFi.STA
160
161**参数:**
162
163  | **参数名** | **类型** | **必填** | **说明** |
164  | -------- | -------- | -------- | -------- |
165  | callback | AsyncCallback< Array<[WifiScanInfo](#wifiscaninfo)>> | 是 | 回调函数。当成功时,err为0,data为扫描到的热点;否则err为非0值,data为空。 |
166
167**示例:**
168
169```ts
170import wifi from '@ohos.wifi';
171
172wifi.getScanInfos((err, result) => {
173    if (err) {
174        console.error("get scan info error");
175        return;
176    }
177
178    let len = result.length;
179    console.log("wifi received scan info: " + len);
180    for (let i = 0; i < len; ++i) {
181        console.info("ssid: " + result[i].ssid);
182        console.info("bssid: " + result[i].bssid);
183        console.info("capabilities: " + result[i].capabilities);
184        console.info("securityType: " + result[i].securityType);
185        console.info("rssi: " + result[i].rssi);
186        console.info("band: " + result[i].band);
187        console.info("frequency: " + result[i].frequency);
188        console.info("channelWidth: " + result[i].channelWidth);
189        console.info("timestamp: " + result[i].timestamp);
190    }
191});
192
193wifi.getScanInfos().then(result => {
194    let len = result.length;
195    console.log("wifi received scan info: " + len);
196    for (let i = 0; i < len; ++i) {
197        console.info("ssid: " + result[i].ssid);
198        console.info("bssid: " + result[i].bssid);
199        console.info("capabilities: " + result[i].capabilities);
200        console.info("securityType: " + result[i].securityType);
201        console.info("rssi: " + result[i].rssi);
202        console.info("band: " + result[i].band);
203        console.info("frequency: " + result[i].frequency);
204        console.info("channelWidth: " + result[i].channelWidth);
205        console.info("timestamp: " + result[i].timestamp);
206    }
207});
208```
209
210
211## WifiScanInfo
212
213WLAN热点信息。
214
215**系统能力:** SystemCapability.Communication.WiFi.STA
216
217
218| **名称** | **类型** | **可读** | **可写** | **说明** |
219| -------- | -------- | -------- | -------- | -------- |
220| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
221| bssid | string | 是 | 否 | 热点的BSSID。 |
222| capabilities | string | 是 | 否 | 热点能力。 |
223| securityType | [WifiSecurityType](#wifisecuritytype) | 是 | 否 | WLAN加密类型。 |
224| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
225| band | number | 是 | 否 | WLAN接入点的频段。 |
226| frequency | number | 是 | 否 | WLAN接入点的频率。 |
227| channelWidth | number | 是 | 否 | WLAN接入点的带宽。 |
228| timestamp | number | 是 | 否 | 时间戳。 |
229
230
231## WifiSecurityType
232
233表示加密类型的枚举。
234
235**系统能力:** SystemCapability.Communication.WiFi.Core
236
237
238| **名称** | **值** | **说明** |
239| -------- | -------- | -------- |
240| WIFI_SEC_TYPE_INVALID | 0 | 无效加密类型。 |
241| WIFI_SEC_TYPE_OPEN | 1 | 开放加密类型。 |
242| WIFI_SEC_TYPE_WEP | 2 | Wired&nbsp;Equivalent&nbsp;Privacy&nbsp;(WEP)加密类型。 |
243| WIFI_SEC_TYPE_PSK | 3 | Pre-shared&nbsp;key&nbsp;(PSK)加密类型。 |
244| WIFI_SEC_TYPE_SAE | 4 | Simultaneous&nbsp;Authentication&nbsp;of&nbsp;Equals&nbsp;(SAE)加密类型。 |
245
246
247## wifi.addDeviceConfig
248
249addDeviceConfig(config: WifiDeviceConfig): Promise&lt;number&gt;
250
251添加网络配置,使用Promise异步回调。
252
253**系统接口:** 此接口为系统接口。
254
255**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.SET_WIFI_CONFIG
256
257**系统能力:** SystemCapability.Communication.WiFi.STA
258
259**参数:**
260
261  | **参数名** | **类型** | **必填** | **说明** |
262  | -------- | -------- | -------- | -------- |
263  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
264
265**返回值:**
266
267  | **类型** | **说明** |
268  | -------- | -------- |
269  | Promise&lt;number&gt; | Promise对象。返回添加的网络配置ID,如果值为-1表示添加失败。 |
270
271  **示例:**
272
273```ts
274import wifi from '@ohos.wifi';
275
276try {
277	let config:wifi.WifiDeviceConfig = {
278		ssid : "****",
279		bssid:  "****",
280		preSharedKey: "****",
281		isHiddenSsid: false,
282		securityType: 0,
283		creatorUid: 0,
284		disableReason: 0,
285		netId: 0,
286		randomMacType: 0,
287		randomMacAddr:  "****",
288		ipType: 0,
289		staticIp: {
290			ipAddress: 0,
291			gateway: 0,
292			dnsServers: [],
293			domains: []
294		}
295	}
296	wifi.addDeviceConfig(config).then(result => {
297		console.info("result:" + JSON.stringify(result));
298	});
299}catch(error){
300	console.error("failed:" + JSON.stringify(error));
301}
302```
303
304## WifiDeviceConfig
305
306WLAN配置信息。
307
308**系统能力:** SystemCapability.Communication.WiFi.STA
309
310
311| **名称** | **类型** | **可读** | **可写** | **说明** |
312| -------- | -------- | -------- | -------- | -------- |
313| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
314| bssid | string | 是 | 否 | 热点的BSSID。 |
315| preSharedKey | string | 是 | 否 | 热点的密钥。 |
316| isHiddenSsid | boolean | 是 | 否 | 是否是隐藏网络。 |
317| securityType | [WifiSecurityType](#wifisecuritytype) | 是 | 否 | 加密类型。 |
318| creatorUid | number | 是 | 否 | 创建用户的ID。 <br /> **系统接口:** 此接口为系统接口。 |
319| disableReason | number | 是 | 否 | 禁用原因。 <br /> **系统接口:** 此接口为系统接口。 |
320| netId | number | 是 | 否 | 分配的网络ID。 <br /> **系统接口:** 此接口为系统接口。 |
321| randomMacType | number | 是 | 否 | 随机MAC类型。 <br /> **系统接口:** 此接口为系统接口。 |
322| randomMacAddr | string | 是 | 否 | 随机MAC地址。 <br /> **系统接口:** 此接口为系统接口。 |
323| ipType | [IpType](#iptype7) | 是 | 否 | IP地址类型。 <br /> **系统接口:** 此接口为系统接口。 |
324| staticIp | [IpConfig](#ipconfig7) | 是 | 否 | 静态IP配置信息。 <br /> **系统接口:** 此接口为系统接口。 |
325
326
327## IpType<sup>7+</sup>
328
329表示IP类型的枚举。
330
331**系统接口:** 此接口为系统接口。
332
333**系统能力:** SystemCapability.Communication.WiFi.STA
334
335
336| 名称 | 值 | 说明 |
337| -------- | -------- | -------- |
338| STATIC | 0 | 静态IP。 |
339| DHCP | 1 | 通过DHCP获取。 |
340| UNKNOWN | 2 | 未指定。 |
341
342
343## IpConfig<sup>7+</sup>
344
345IP配置信息。
346
347**系统接口:** 此接口为系统接口。
348
349**系统能力:** SystemCapability.Communication.WiFi.STA
350
351| **名称** | **类型** | **可读** | **可写** | **说明** |
352| -------- | -------- | -------- | -------- | -------- |
353| ipAddress | number | 是 | 否 | IP地址。 |
354| gateway | number | 是 | 否 | 网关。 |
355| dnsServers | number[] | 是 | 否 | DNS服务器。 |
356| domains | Array&lt;string&gt; | 是 | 否 | 域信息。 |
357
358
359## wifi.addDeviceConfig
360
361addDeviceConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;number&gt;): void
362
363添加网络配置,使用callback异步回调。
364
365**系统接口:** 此接口为系统接口。
366
367**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.SET_WIFI_CONFIG
368
369**系统能力:** SystemCapability.Communication.WiFi.STA
370
371**参数:**
372
373  | **参数名** | **类型** | **必填** | **说明** |
374  | -------- | -------- | -------- | -------- |
375  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
376  | callback | AsyncCallback&lt;number&gt; | 是 | 回调函数。当操作成功时,err为0,data为添加的网络配置ID,如果data值为-1,表示添加失败。当error为非0,表示处理出现错误。 |
377
378**示例:**
379
380```ts
381import wifi from '@ohos.wifi';
382
383try {
384	let config:wifi.WifiDeviceConfig = {
385		ssid : "****",
386		bssid:  "****",
387		preSharedKey: "****",
388		isHiddenSsid: false,
389		securityType: 0,
390		creatorUid: 0,
391		disableReason: 0,
392		netId: 0,
393		randomMacType: 0,
394		randomMacAddr:  "****",
395		ipType: 0,
396		staticIp: {
397			ipAddress: 0,
398			gateway: 0,
399			dnsServers: [],
400			domains: []
401		}
402	}
403	wifi.addDeviceConfig(config,(error,result) => {
404		console.info("result:" + JSON.stringify(result));
405	});
406}catch(error){
407	console.error("failed:" + JSON.stringify(error));
408}
409```
410## wifi.addUntrustedConfig<sup>7+</sup>
411
412addUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;
413
414添加不可信网络配置,使用Promise异步回调。
415
416**需要权限:** ohos.permission.SET_WIFI_INFO
417
418**系统能力:** SystemCapability.Communication.WiFi.STA
419
420**参数:**
421
422  | **参数名** | **类型** | **必填** | **说明** |
423  | -------- | -------- | -------- | -------- |
424  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
425
426**返回值:**
427
428  | **类型** | **说明** |
429  | -------- | -------- |
430  | Promise&lt;boolean&gt; | Promise对象。表示操作结果,true: 成功, false: 失败。 |
431
432**示例:**
433```ts
434import wifi from '@ohos.wifi';
435
436try {
437	let config:wifi.WifiDeviceConfig = {
438		ssid : "****",
439		bssid:  "****",
440		preSharedKey: "****",
441		isHiddenSsid: false,
442		securityType: 0,
443		creatorUid: 0,
444		disableReason: 0,
445		netId: 0,
446		randomMacType: 0,
447		randomMacAddr:  "****",
448		ipType: 0,
449		staticIp: {
450			ipAddress: 0,
451			gateway: 0,
452			dnsServers: [],
453			domains: []
454		}
455	}
456	wifi.addUntrustedConfig(config).then(result => {
457		console.info("result:" + JSON.stringify(result));
458	});
459}catch(error){
460	console.error("failed:" + JSON.stringify(error));
461}
462```
463
464## wifi.addUntrustedConfig<sup>7+</sup>
465
466addUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void
467
468添加不可信网络配置,使用callback异步回调。
469
470**需要权限:** ohos.permission.SET_WIFI_INFO
471
472**系统能力:** SystemCapability.Communication.WiFi.STA
473
474**参数:**
475
476  | **参数名** | **类型** | **必填** | **说明** |
477  | -------- | -------- | -------- | -------- |
478  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
479  | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
480
481**示例:**
482```ts
483import wifi from '@ohos.wifi';
484
485try {
486	let config:wifi.WifiDeviceConfig = {
487		ssid : "****",
488		bssid:  "****",
489		preSharedKey: "****",
490		isHiddenSsid: false,
491		securityType: 0,
492		creatorUid: 0,
493		disableReason: 0,
494		netId: 0,
495		randomMacType: 0,
496		randomMacAddr:  "****",
497		ipType: 0,
498		staticIp: {
499			ipAddress: 0,
500			gateway: 0,
501			dnsServers: [],
502			domains: []
503		}
504	}
505	wifi.addUntrustedConfig(config,(error,result) => {
506		console.info("result:" + JSON.stringify(result));
507	});
508}catch(error){
509	console.error("failed:" + JSON.stringify(error));
510}
511```
512
513## wifi.removeUntrustedConfig<sup>7+</sup>
514
515removeUntrustedConfig(config: WifiDeviceConfig): Promise&lt;boolean&gt;
516
517移除不可信网络配置,使用Promise异步回调。
518
519**需要权限:** ohos.permission.SET_WIFI_INFO
520
521**系统能力:** SystemCapability.Communication.WiFi.STA
522
523**参数:**
524
525  | **参数名** | **类型** | **必填** | **说明** |
526  | -------- | -------- | -------- | -------- |
527  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
528
529**返回值:**
530
531  | **类型** | **说明** |
532  | -------- | -------- |
533  | Promise&lt;boolean&gt; | Promise对象。表示操作结果,true: 成功, false: 失败。 |
534
535**示例:**
536
537```ts
538import wifi from '@ohos.wifi';
539
540try {
541	let config:wifi.WifiDeviceConfig = {
542		ssid : "****",
543		bssid:  "****",
544		preSharedKey: "****",
545		isHiddenSsid: false,
546		securityType: 0,
547		creatorUid: 0,
548		disableReason: 0,
549		netId: 0,
550		randomMacType: 0,
551		randomMacAddr:  "****",
552		ipType: 0,
553		staticIp: {
554			ipAddress: 0,
555			gateway: 0,
556			dnsServers: [],
557			domains: []
558		}
559	}
560	wifi.removeUntrustedConfig(config).then(result => {
561		console.info("result:" + JSON.stringify(result));
562	});
563}catch(error){
564	console.error("failed:" + JSON.stringify(error));
565}
566```
567
568
569## wifi.removeUntrustedConfig<sup>7+</sup>
570
571removeUntrustedConfig(config: WifiDeviceConfig, callback: AsyncCallback&lt;boolean&gt;): void
572
573移除不可信网络配置,使用callback异步回调。
574
575**需要权限:** ohos.permission.SET_WIFI_INFO
576
577**系统能力:** SystemCapability.Communication.WiFi.STA
578
579**参数:**
580
581  | **参数名** | **类型** | **必填** | **说明** |
582  | -------- | -------- | -------- | -------- |
583  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
584  | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数。当操作成功时,err为0,data表示操作结果,true: 成功, false: 失败。如果error为非0,表示处理出现错误。 |
585
586**示例:**
587```ts
588import wifi from '@ohos.wifi';
589
590try {
591	let config:wifi.WifiDeviceConfig = {
592		ssid : "****",
593		bssid:  "****",
594		preSharedKey: "****",
595		isHiddenSsid: false,
596		securityType: 0,
597		creatorUid: 0,
598		disableReason: 0,
599		netId: 0,
600		randomMacType: 0,
601		randomMacAddr:  "****",
602		ipType: 0,
603		staticIp: {
604			ipAddress: 0,
605			gateway: 0,
606			dnsServers: [],
607			domains: []
608		}
609	}
610	wifi.removeUntrustedConfig(config,(error,result) => {
611	console.info("result:" + JSON.stringify(result));
612	});
613}catch(error){
614	console.error("failed:" + JSON.stringify(error));
615}
616```
617
618## wifi.connectToNetwork
619
620connectToNetwork(networkId: number): boolean
621
622连接到指定网络。
623
624**系统接口:** 此接口为系统接口。
625
626**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
627
628**系统能力:** SystemCapability.Communication.WiFi.STA
629
630**参数:**
631
632  | **参数名** | **类型** | **必填** | **说明** |
633  | -------- | -------- | -------- | -------- |
634  | networkId | number | 是 | 待连接的网络配置ID。 |
635
636**返回值:**
637
638  | **类型** | **说明** |
639  | -------- | -------- |
640  | boolean | true:操作成功,&nbsp;false:操作失败。 |
641
642**示例:**
643
644```ts
645import wifi from '@ohos.wifi';
646
647try {
648	let networkId = 0;
649	wifi.connectToNetwork(networkId);
650}catch(error){
651	console.error("failed:" + JSON.stringify(error));
652}
653```
654
655## wifi.connectToDevice
656
657connectToDevice(config: WifiDeviceConfig): boolean
658
659连接到指定网络。
660
661**系统接口:** 此接口为系统接口。
662
663**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.SET_WIFI_CONFIGohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
664
665**系统能力:**
666  SystemCapability.Communication.WiFi.STA
667
668**参数:**
669
670  | **参数名** | **类型** | **必填** | **说明** |
671  | -------- | -------- | -------- | -------- |
672  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
673
674**返回值:**
675
676  | **类型** | **说明** |
677  | -------- | -------- |
678  | boolean | true:操作成功,&nbsp;false:操作失败。 |
679
680**示例:**
681```ts
682import wifi from '@ohos.wifi';
683
684try {
685	let config:wifi.WifiDeviceConfig = {
686		ssid : "****",
687		bssid:  "****",
688		preSharedKey: "****",
689		isHiddenSsid: false,
690		securityType: 3,
691		creatorUid: 0,
692		disableReason: 0,
693		netId: 0,
694		randomMacType: 0,
695		randomMacAddr:  "****",
696		ipType: 0,
697		staticIp: {
698		ipAddress: 0,
699			gateway: 0,
700			dnsServers: [],
701			domains: []
702		}
703	}
704	wifi.connectToDevice(config);
705
706}catch(error){
707	console.error("failed:" + JSON.stringify(error));
708}
709```
710
711## wifi.disconnect
712
713disconnect(): boolean
714
715断开连接的网络。
716
717**系统接口:** 此接口为系统接口。
718
719**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
720
721**系统能力:**
722  SystemCapability.Communication.WiFi.STA
723
724**返回值:**
725
726  | **类型** | **说明** |
727  | -------- | -------- |
728  | boolean | true:操作成功,&nbsp;false:操作失败。 |
729
730**示例:**
731```ts
732import wifi from '@ohos.wifi';
733
734try {
735	wifi.disconnect();
736}catch(error){
737	console.error("failed:" + JSON.stringify(error));
738}
739```
740
741## wifi.getSignalLevel
742
743getSignalLevel(rssi: number, band: number): number
744
745查询WLAN信号强度。
746
747**需要权限:** ohos.permission.GET_WIFI_INFO
748
749**系统能力:** SystemCapability.Communication.WiFi.STA
750
751**参数:**
752
753  | **参数名** | **类型** | **必填** | **说明** |
754  | -------- | -------- | -------- | -------- |
755  | rssi | number | 是 | 热点的信号强度(dBm)。 |
756  | band | number | 是 | WLAN接入点的频段。 |
757
758**返回值:**
759
760  | **类型** | **说明** |
761  | -------- | -------- |
762  | number | 信号强度,取值范围为[0,&nbsp;4]。 |
763
764**示例:**
765```ts
766import wifi from '@ohos.wifi';
767
768try {
769	let rssi = 0;
770	let band = 0;
771	let level = wifi.getSignalLevel(rssi,band);
772	console.info("level:" + JSON.stringify(level));
773}catch(error){
774	console.error("failed:" + JSON.stringify(error));
775}
776
777```
778
779## wifi.getLinkedInfo
780
781getLinkedInfo(): Promise&lt;WifiLinkedInfo&gt;
782
783获取WLAN连接信息,使用Promise异步回调。
784
785**需要权限:** ohos.permission.GET_WIFI_INFO
786
787**系统能力:** SystemCapability.Communication.WiFi.STA
788
789**返回值:**
790
791  | 类型 | 说明 |
792  | -------- | -------- |
793  | Promise&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | Promise对象。表示WLAN连接信息。 |
794
795
796## wifi.getLinkedInfo
797
798getLinkedInfo(callback: AsyncCallback&lt;WifiLinkedInfo&gt;): void
799
800获取WLAN连接信息,使用callback异步回调。
801
802**需要权限:** ohos.permission.GET_WIFI_INFO
803
804**系统能力:** SystemCapability.Communication.WiFi.STA
805
806**参数:**
807
808  | 参数名 | 类型 | 必填 | 说明 |
809  | -------- | -------- | -------- | -------- |
810  | callback | AsyncCallback&lt;[WifiLinkedInfo](#wifilinkedinfo)&gt; | 是 | 回调函数。当获取成功时,err为0,data表示WLAN连接信息。如果error为非0,表示处理出现错误。 |
811
812**示例:**
813```ts
814import wifi from '@ohos.wifi';
815
816wifi.getLinkedInfo((err, data) => {
817    if (err) {
818        console.error("get linked info error");
819        return;
820    }
821    console.info("get wifi linked info: " + JSON.stringify(data));
822});
823
824wifi.getLinkedInfo().then(data => {
825    console.info("get wifi linked info: " + JSON.stringify(data));
826}).catch((error:number) => {
827    console.info("get linked info error");
828});
829```
830
831
832## WifiLinkedInfo
833
834提供WLAN连接的相关信息。
835
836**系统能力:** SystemCapability.Communication.WiFi.STA
837
838| 名称 | 类型 | 可读 | 可写 | 说明 |
839| -------- | -------- | -------- | -------- | -------- |
840| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
841| bssid | string | 是 | 否 | 热点的BSSID。 |
842| networkId | number | 是 | 否 | 网络配置ID。 <br /> **系统接口:** 此接口为系统接口。 |
843| rssi | number | 是 | 否 | 热点的信号强度(dBm)。 |
844| band | number | 是 | 否 | WLAN接入点的频段。 |
845| linkSpeed | number | 是 | 否 | WLAN接入点的速度。 |
846| frequency | number | 是 | 否 | WLAN接入点的频率。 |
847| isHidden | boolean | 是 | 否 | WLAN接入点是否是隐藏网络。 |
848| isRestricted | boolean | 是 | 否 | WLAN接入点是否限制数据量。 |
849| chload | number | 是 | 否 | 连接负载,值越大表示负载约高。 <br /> **系统接口:** 此接口为系统接口。 |
850| snr | number | 是 | 否 | 信噪比。 <br /> **系统接口:** 此接口为系统接口。 |
851| macAddress | string | 是 | 否 | 设备的MAC地址。 |
852| ipAddress | number | 是 | 否 | WLAN连接的IP地址。 |
853| suppState | [SuppState](#suppstate) | 是 | 否 | 请求状态。 <br /> **系统接口:** 此接口为系统接口。 |
854| connState | [ConnState](#connstate) | 是 | 否 | WLAN连接状态。 |
855
856
857## ConnState
858
859表示WLAN连接状态的枚举。
860
861**系统能力:** SystemCapability.Communication.WiFi.STA
862
863| 名称 | 值 | 说明 |
864| -------- | -------- | -------- |
865| SCANNING | 0 | 设备正在搜索可用的AP。 |
866| CONNECTING | 1 | 正在建立WLAN连接。 |
867| AUTHENTICATING | 2 | WLAN连接正在认证中。 |
868| OBTAINING_IPADDR | 3 | 正在获取WLAN连接的IP地址。 |
869| CONNECTED | 4 | WLAN连接已建立。 |
870| DISCONNECTING | 5 | WLAN连接正在断开。 |
871| DISCONNECTED | 6 | WLAN连接已断开。 |
872| UNKNOWN | 7 | WLAN连接建立失败。 |
873
874
875## SuppState
876
877表示请求状态的枚举。
878
879**系统接口:** 此接口为系统接口。
880
881**系统能力:** SystemCapability.Communication.WiFi.STA
882
883| 名称 | 值 | 说明 |
884| -------- | -------- | -------- |
885| DISCONNECTED | 0 | 已断开。 |
886| INTERFACE_DISABLED | 1 | 接口禁用。 |
887| INACTIVE | 2 | 未激活。 |
888| SCANNING | 3 | 扫描中。 |
889| AUTHENTICATING | 4 | 认证中。 |
890| ASSOCIATING | 5 | 关联中。 |
891| ASSOCIATED | 6 | 已关联。 |
892| FOUR_WAY_HANDSHAKE | 7 | 四次握手。 |
893| GROUP_HANDSHAKE | 8 | 组握手。 |
894| COMPLETED | 9 | 所有认证已完成。 |
895| UNINITIALIZED | 10 | 连接建立失败。 |
896| INVALID | 11 | 无效值。 |
897
898
899## wifi.isConnected<sup>7+</sup>
900
901isConnected(): boolean
902
903查询WLAN是否已连接。
904
905**需要权限:** ohos.permission.GET_WIFI_INFO
906
907**系统能力:** SystemCapability.Communication.WiFi.STA
908
909**返回值:**
910
911  | **类型** | **说明** |
912  | -------- | -------- |
913  | boolean | true:已连接,&nbsp;false:未连接。 |
914
915
916## wifi.getSupportedFeatures<sup>7+</sup>
917
918getSupportedFeatures(): number
919
920查询设备支持的特性。
921
922**系统接口:** 此接口为系统接口。
923
924**需要权限:** ohos.permission.GET_WIFI_INFO
925
926**系统能力:** SystemCapability.Communication.WiFi.Core
927
928**返回值:**
929
930  | **类型** | **说明** |
931  | -------- | -------- |
932  | number | 支持的特性值。 |
933
934**特性ID值枚举:**
935
936| 枚举值 | 说明 |
937| -------- | -------- |
938| 0x0001 | 基础结构模式特性。 |
939| 0x0002 | 5&nbsp;GHz带宽特性。 |
940| 0x0004 | GAS/ANQP特性。 |
941| 0x0008 | Wifi-Direct特性。 |
942| 0x0010 | Soft&nbsp;AP特性。 |
943| 0x0040 | Wi-Fi&nbsp;AWare组网特性。 |
944| 0x8000 | AP&nbsp;STA共存特性。 |
945| 0x8000000 | WPA3-Personal&nbsp;SAE特性。 |
946| 0x10000000 | WPA3-Enterprise&nbsp;Suite-B |
947| 0x20000000 | 增强开放特性。 |
948
949
950## wifi.isFeatureSupported<sup>7+</sup>
951
952isFeatureSupported(featureId: number): boolean
953
954判断设备是否支持相关WLAN特性。
955
956**需要权限:** ohos.permission.GET_WIFI_INFO
957
958**系统能力:** SystemCapability.Communication.WiFi.Core
959
960**参数:**
961
962
963  | **参数名** | **类型** | 必填 | **说明** |
964  | -------- | -------- | -------- | -------- |
965  | featureId | number | 是 | 特性ID值。 |
966
967**返回值:**
968
969  | **类型** | **说明** |
970  | -------- | -------- |
971  | boolean | true:支持,&nbsp;false:不支持。 |
972
973**示例:**
974```ts
975import wifi from '@ohos.wifi';
976
977try {
978	let featureId = 0;
979	let ret = wifi.isFeatureSupported(featureId);
980	console.info("isFeatureSupported:" + ret);
981}catch(error){
982	console.error("failed:" + JSON.stringify(error));
983}
984
985```
986
987## wifi.getDeviceMacAddress<sup>7+</sup>
988
989getDeviceMacAddress(): string[]
990
991获取设备的MAC地址。
992
993**系统接口:** 此接口为系统接口。
994
995**需要权限:** ohos.permission.GET_WIFI_LOCAL_MACohos.permission.GET_WIFI_INFO,仅系统应用可用。
996
997**系统能力:** SystemCapability.Communication.WiFi.STA
998
999**返回值:**
1000
1001  | **类型** | **说明** |
1002  | -------- | -------- |
1003  | string[] | MAC地址。 |
1004
1005**示例:**
1006```ts
1007import wifi from '@ohos.wifi';
1008
1009try {
1010	let ret = wifi.getDeviceMacAddress();
1011	console.info("deviceMacAddress:" + JSON.stringify(ret));
1012}catch(error){
1013	console.error("failed:" + JSON.stringify(error));
1014}
1015
1016```
1017
1018## wifi.getIpInfo<sup>7+</sup>
1019
1020getIpInfo(): IpInfo
1021
1022获取IP信息。
1023
1024**需要权限:** ohos.permission.GET_WIFI_INFO
1025
1026**系统能力:** SystemCapability.Communication.WiFi.STA
1027
1028**返回值:**
1029
1030  | **类型** | **说明** |
1031  | -------- | -------- |
1032  | [IpInfo](#ipinfo7) | IP信息。 |
1033
1034**示例:**
1035```ts
1036import wifi from '@ohos.wifi';
1037
1038try {
1039	let info = wifi.getIpInfo();
1040	console.info("info:" + JSON.stringify(info));
1041}catch(error){
1042	console.error("failed:" + JSON.stringify(error));
1043}
1044```
1045
1046## IpInfo<sup>7+</sup>
1047
1048IP信息。
1049
1050**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1051
1052| **名称** | **类型** | **可读** | **可写** | **说明** |
1053| -------- | -------- | -------- | -------- | -------- |
1054| ipAddress | number | 是 | 否 | IP地址。 |
1055| gateway | number | 是 | 否 | 网关。 |
1056| netmask | number | 是 | 否 | 掩码。 |
1057| primaryDns | number | 是 | 否 | 主DNS服务器IP地址。 |
1058| secondDns | number | 是 | 否 | 备DNS服务器IP地址。 |
1059| serverIp | number | 是 | 否 | DHCP服务端IP地址。 |
1060| leaseDuration | number | 是 | 否 | IP地址租用时长。 |
1061
1062
1063## wifi.getCountryCode<sup>7+</sup>
1064
1065getCountryCode(): string
1066
1067获取国家码信息。
1068
1069**需要权限:** ohos.permission.GET_WIFI_INFO
1070
1071**系统能力:** SystemCapability.Communication.WiFi.Core
1072
1073**返回值:**
1074
1075  | **类型** | **说明** |
1076  | -------- | -------- |
1077  | string | 国家码。 |
1078
1079**示例:**
1080```ts
1081import wifi from '@ohos.wifi';
1082
1083try {
1084	let code = wifi.getCountryCode();
1085	console.info("code:" + code);
1086}catch(error){
1087	console.error("failed:" + JSON.stringify(error));
1088}
1089```
1090
1091## wifi.reassociate<sup>7+</sup>
1092
1093reassociate(): boolean
1094
1095重新关联网络。
1096
1097**系统接口:** 此接口为系统接口。
1098
1099**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1100
1101**系统能力:** SystemCapability.Communication.WiFi.STA
1102
1103**返回值:**
1104
1105  | **类型** | **说明** |
1106  | -------- | -------- |
1107  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1108
1109**示例:**
1110```ts
1111import wifi from '@ohos.wifi';
1112
1113try {
1114	wifi.reassociate();
1115}catch(error){
1116	console.error("failed:" + JSON.stringify(error));
1117}
1118```
1119
1120## wifi.reconnect<sup>7+</sup>
1121
1122reconnect(): boolean
1123
1124重新连接网络。
1125
1126**系统接口:** 此接口为系统接口。
1127
1128**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1129
1130**系统能力:** SystemCapability.Communication.WiFi.STA
1131
1132**返回值:**
1133
1134  | **类型** | **说明** |
1135  | -------- | -------- |
1136  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1137
1138**示例:**
1139```ts
1140import wifi from '@ohos.wifi';
1141
1142try {
1143	wifi.reconnect();
1144}catch(error){
1145	console.error("failed:" + JSON.stringify(error));
1146}
1147```
1148
1149## wifi.getDeviceConfigs<sup>7+</sup>
1150
1151getDeviceConfigs(): &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt;
1152
1153获取网络配置。
1154
1155**系统接口:** 此接口为系统接口。
1156
1157**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATIONohos.permission.GET_WIFI_CONFIG
1158
1159**系统能力:** SystemCapability.Communication.WiFi.STA
1160
1161**返回值:**
1162
1163  | **类型** | **说明** |
1164  | -------- | -------- |
1165  | &nbsp;Array&lt;[WifiDeviceConfig](#wifideviceconfig)&gt; | 网络配置信息的数组。 |
1166
1167**示例:**
1168```ts
1169import wifi from '@ohos.wifi';
1170
1171try {
1172	let configs = wifi.getDeviceConfigs();
1173	console.info("configs:" + JSON.stringify(configs));
1174}catch(error){
1175	console.error("failed:" + JSON.stringify(error));
1176}
1177```
1178
1179## wifi.updateNetwork<sup>7+</sup>
1180
1181updateNetwork(config: WifiDeviceConfig): number
1182
1183更新网络配置。
1184
1185**系统接口:** 此接口为系统接口。
1186
1187**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.SET_WIFI_CONFIG
1188
1189**系统能力:** SystemCapability.Communication.WiFi.STA
1190
1191**参数:**
1192
1193  | **参数名** | **类型** | **必填** | **说明** |
1194  | -------- | -------- | -------- | -------- |
1195  | config | [WifiDeviceConfig](#wifideviceconfig) | 是 | WLAN配置信息。 |
1196
1197**返回值:**
1198
1199  | **类型** | **说明** |
1200  | -------- | -------- |
1201  | number | 返回更新的网络配置ID,如果值为-1表示更新失败。 |
1202
1203**示例:**
1204```ts
1205import wifi from '@ohos.wifi';
1206
1207try {
1208	let config:wifi.WifiDeviceConfig = {
1209		ssid : "****",
1210		bssid:  "****",
1211		preSharedKey: "****",
1212		isHiddenSsid: false,
1213		securityType: 3,
1214		creatorUid: 0,
1215		disableReason: 0,
1216		netId: 0,
1217		randomMacType: 0,
1218		randomMacAddr:  "****",
1219		ipType: 0,
1220		staticIp: {
1221			ipAddress: 0,
1222			gateway: 0,
1223			dnsServers: [],
1224			domains: []
1225		}
1226	}
1227	let ret = wifi.updateNetwork(config);
1228	console.error("ret:" + ret);
1229}catch(error){
1230	console.error("failed:" + JSON.stringify(error));
1231}
1232```
1233
1234## wifi.disableNetwork<sup>7+</sup>
1235
1236disableNetwork(netId: number): boolean
1237
1238去使能网络配置。
1239
1240**系统接口:** 此接口为系统接口。
1241
1242**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1243
1244**系统能力:** SystemCapability.Communication.WiFi.STA
1245
1246**参数:**
1247
1248  | **参数名** | **类型** | **必填** | **说明** |
1249  | -------- | -------- | -------- | -------- |
1250  | netId | number | 是 | 网络配置ID。 |
1251
1252**返回值:**
1253
1254  | **类型** | **说明** |
1255  | -------- | -------- |
1256  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1257
1258**示例:**
1259```ts
1260import wifi from '@ohos.wifi';
1261
1262try {
1263	let netId = 0;
1264	wifi.disableNetwork(netId);
1265}catch(error){
1266	console.error("failed:" + JSON.stringify(error));
1267}
1268```
1269
1270## wifi.removeAllNetwork<sup>7+</sup>
1271
1272removeAllNetwork(): boolean
1273
1274移除所有网络配置。
1275
1276**系统接口:** 此接口为系统接口。
1277
1278**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1279
1280**系统能力:** SystemCapability.Communication.WiFi.STA
1281
1282**返回值:**
1283
1284  | **类型** | **说明** |
1285  | -------- | -------- |
1286  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1287
1288**示例:**
1289```ts
1290import wifi from '@ohos.wifi';
1291
1292try {
1293	wifi.removeAllNetwork();
1294}catch(error){
1295	console.error("failed:" + JSON.stringify(error));
1296}
1297```
1298
1299## wifi.removeDevice<sup>7+</sup>
1300
1301removeDevice(id: number): boolean
1302
1303移除指定的网络配置。
1304
1305**系统接口:** 此接口为系统接口。
1306
1307**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
1308
1309**系统能力:** SystemCapability.Communication.WiFi.STA
1310
1311**参数:**
1312
1313  | **参数名** | **类型** | **必填** | **说明** |
1314  | -------- | -------- | -------- | -------- |
1315  | id | number | 是 | 网络配置ID。 |
1316
1317**返回值:**
1318
1319  | **类型** | **说明** |
1320  | -------- | -------- |
1321  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1322
1323**示例:**
1324```ts
1325import wifi from '@ohos.wifi';
1326
1327try {
1328	let id = 0;
1329	wifi.removeDevice(id);
1330}catch(error){
1331	console.error("failed:" + JSON.stringify(error));
1332}
1333```
1334
1335## wifi.enableHotspot<sup>7+</sup>
1336
1337enableHotspot(): boolean
1338
1339使能热点。
1340
1341**系统接口:** 此接口为系统接口。
1342
1343**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1344
1345**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1346
1347**返回值:**
1348
1349  | **类型** | **说明** |
1350  | -------- | -------- |
1351  | boolean | true:操作成功,&nbsp;false:操作失败。|
1352
1353**示例:**
1354```ts
1355import wifi from '@ohos.wifi';
1356
1357try {
1358	wifi.enableHotspot();
1359}catch(error){
1360	console.error("failed:" + JSON.stringify(error));
1361}
1362```
1363
1364## wifi.disableHotspot<sup>7+</sup>
1365
1366disableHotspot(): boolean
1367
1368去使能热点。
1369
1370**系统接口:** 此接口为系统接口。
1371
1372**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1373
1374**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1375
1376**返回值:**
1377
1378  | **类型** | **说明** |
1379  | -------- | -------- |
1380  | boolean | true:操作成功,&nbsp;false:操作失败。|
1381
1382**示例:**
1383```ts
1384import wifi from '@ohos.wifi';
1385
1386try {
1387	wifi.disableHotspot();
1388}catch(error){
1389	console.error("failed:" + JSON.stringify(error));
1390}
1391```
1392
1393## wifi.isHotspotDualBandSupported<sup>7+</sup>
1394
1395isHotspotDualBandSupported(): boolean
1396
1397热点是否支持双频。
1398
1399**系统接口:** 此接口为系统接口。
1400
1401**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1402
1403**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1404
1405**返回值:**
1406
1407  | **类型** | **说明** |
1408  | -------- | -------- |
1409  | boolean | true:支持,&nbsp;false:不支持。|
1410
1411**示例:**
1412```ts
1413import wifi from '@ohos.wifi';
1414
1415try {
1416	let ret = wifi.isHotspotDualBandSupported();
1417	console.info("result:" + ret);
1418}catch(error){
1419	console.error("failed:" + JSON.stringify(error));
1420}
1421```
1422
1423## wifi.isHotspotActive<sup>7+</sup>
1424
1425isHotspotActive(): boolean
1426
1427热点是否已使能。
1428
1429**系统接口:** 此接口为系统接口。
1430
1431**需要权限:** ohos.permission.GET_WIFI_INFO
1432
1433**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1434
1435**返回值:**
1436
1437  | **类型** | **说明** |
1438  | -------- | -------- |
1439  | boolean | true:已使能,&nbsp;false:未使能。|
1440
1441**示例:**
1442```ts
1443import wifi from '@ohos.wifi';
1444
1445try {
1446	let ret = wifi.isHotspotActive();
1447	console.info("result:" + ret);
1448}catch(error){
1449	console.error("failed:" + JSON.stringify(error));
1450}
1451```
1452
1453## wifi.setHotspotConfig<sup>7+</sup>
1454
1455setHotspotConfig(config: HotspotConfig): boolean
1456
1457设置热点配置信息。
1458
1459**系统接口:** 此接口为系统接口。
1460
1461**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.GET_WIFI_CONFIG
1462
1463**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1464
1465**参数:**
1466
1467  | **参数名** | **类型** | **必填** | **说明** |
1468  | -------- | -------- | -------- | -------- |
1469  | config | [HotspotConfig](#hotspotconfig7) | 是 | 热点配置信息。 |
1470
1471**返回值:**
1472
1473  | **类型** | **说明** |
1474  | -------- | -------- |
1475  | boolean | true:操作成功,&nbsp;false:操作失败。 |
1476
1477**示例:**
1478```ts
1479import wifi from '@ohos.wifi';
1480
1481try {
1482	let config:wifi.HotspotConfig = {
1483		ssid: "****",
1484		securityType: 3,
1485		band: 0,
1486		preSharedKey: "****",
1487		maxConn: 0
1488	}
1489	let ret = wifi.setHotspotConfig(config);
1490	console.info("result:" + ret);
1491}catch(error){
1492	console.error("failed:" + JSON.stringify(error));
1493}
1494```
1495
1496## HotspotConfig<sup>7+</sup>
1497
1498热点配置信息。
1499
1500**系统接口:** 此接口为系统接口。
1501
1502**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1503
1504| **名称** | **类型** | **可读** | **可写** | **说明** |
1505| -------- | -------- | -------- | -------- | -------- |
1506| ssid | string | 是 | 否 | 热点的SSID,编码格式为UTF-8。 |
1507| securityType | [WifiSecurityType](#wifisecuritytype) | 是 | 否 | 加密类型。 |
1508| band | number | 是 | 否 | 热点的带宽。1: 2.4G, 2: 5G, 3: 双模频段 |
1509| preSharedKey | string | 是 | 否 | 热点的密钥。 |
1510| maxConn | number | 是 | 否 | 最大设备连接数。 |
1511
1512
1513## wifi.getHotspotConfig<sup>7+</sup>
1514
1515getHotspotConfig(): HotspotConfig
1516
1517获取热点配置信息。
1518
1519**系统接口:** 此接口为系统接口。
1520
1521**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.GET_WIFI_CONFIG
1522
1523**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1524
1525**返回值:**
1526
1527  | **类型** | **说明** |
1528  | -------- | -------- |
1529  | [HotspotConfig](#hotspotconfig7) | 热点的配置信息。 |
1530
1531**示例:**
1532```ts
1533import wifi from '@ohos.wifi';
1534
1535try {
1536	let config = wifi.getHotspotConfig();
1537	console.info("result:" + JSON.stringify(config));
1538}catch(error){
1539	console.error("failed:" + JSON.stringify(error));
1540}
1541```
1542
1543## wifi.getStations<sup>7+</sup>
1544
1545getStations(): &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt;
1546
1547获取连接的设备。
1548
1549**系统接口:** 此接口为系统接口。
1550
1551**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATIONohos.permission.MANAGE_WIFI_HOTSPOT,仅系统应用可用。
1552
1553**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1554
1555**返回值:**
1556
1557  | **类型** | **说明** |
1558  | -------- | -------- |
1559  | &nbsp;Array&lt;[StationInfo](#stationinfo7)&gt; | 连接的设备数组。 |
1560
1561**示例:**
1562```ts
1563import wifi from '@ohos.wifi';
1564
1565try {
1566	let stations = wifi.getStations();
1567	console.info("result:" + JSON.stringify(stations));
1568}catch(error){
1569	console.error("failed:" + JSON.stringify(error));
1570}
1571```
1572
1573## StationInfo<sup>7+</sup>
1574
1575接入的设备信息。
1576
1577**系统接口:** 此接口为系统接口。
1578
1579**系统能力:** SystemCapability.Communication.WiFi.AP.Core
1580
1581| **名称** | **类型** | **可读** | **可写** | **说明** |
1582| -------- | -------- | -------- | -------- | -------- |
1583| name | string | 是 | 否 | 设备名称。 |
1584| macAddress | string | 是 | 否 | MAC地址。 |
1585| ipAddress | string | 是 | 否 | IP地址。 |
1586
1587
1588## wifi.getP2pLinkedInfo<sup>8+</sup>
1589
1590getP2pLinkedInfo(): Promise&lt;WifiP2pLinkedInfo&gt;
1591
1592获取P2P连接信息,使用Promise异步回调。
1593
1594**需要权限:** ohos.permission.GET_WIFI_INFO
1595
1596**系统能力:** SystemCapability.Communication.WiFi.P2P
1597
1598**返回值:**
1599
1600  | 类型 | 说明 |
1601  | -------- | -------- |
1602  | Promise&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | Promise对象。表示P2P连接信息。 |
1603
1604
1605
1606## WifiP2pLinkedInfo<sup>8+</sup>
1607
1608提供WLAN连接的相关信息。
1609
1610**系统能力:** SystemCapability.Communication.WiFi.P2P
1611
1612| 名称 | 类型 | 可读 | 可写 | 说明 |
1613| -------- | -------- | -------- | -------- | -------- |
1614| connectState | [P2pConnectState](#p2pconnectstate8) | 是 | 否 | P2P连接状态。 |
1615| isGroupOwner | boolean | 是 | 否 | 是否是群主。 |
1616| groupOwnerAddr | string | 是 | 否 | 群组MAC地址。
1617
1618
1619## P2pConnectState<sup>8+</sup>
1620
1621表示P2P连接状态的枚举。
1622
1623**系统能力:** SystemCapability.Communication.WiFi.P2P
1624
1625| 名称 | 值 | 说明 |
1626| -------- | -------- | -------- |
1627| DISCONNECTED | 0 | 断开状态。 |
1628| CONNECTED | 1 | 连接状态。 |
1629
1630
1631## wifi.getP2pLinkedInfo<sup>8+</sup>
1632
1633getP2pLinkedInfo(callback: AsyncCallback&lt;WifiP2pLinkedInfo&gt;): void
1634
1635获取P2P连接信息,使用callback异步回调。
1636
1637**需要权限:** ohos.permission.GET_WIFI_INFO
1638
1639**系统能力:** SystemCapability.Communication.WiFi.P2P
1640
1641**参数:**
1642
1643  | 参数名 | 类型 | 必填 | 说明 |
1644  | -------- | -------- | -------- | -------- |
1645  | callback | AsyncCallback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | 是 | 回调函数。当操作成功时,err为0,data表示P2P连接信息。如果error为非0,表示处理出现错误。 |
1646
1647**示例:**
1648```ts
1649import wifi from '@ohos.wifi';
1650
1651wifi.getP2pLinkedInfo((err, data) => {
1652   if (err) {
1653       console.error("get p2p linked info error");
1654       return;
1655   }
1656	console.info("get wifi p2p linked info: " + JSON.stringify(data));
1657});
1658
1659wifi.getP2pLinkedInfo().then(data => {
1660	console.info("get wifi p2p linked info: " + JSON.stringify(data));
1661});
1662```
1663
1664## wifi.getCurrentGroup<sup>8+</sup>
1665
1666getCurrentGroup(): Promise&lt;WifiP2pGroupInfo&gt;
1667
1668获取P2P当前组信息,使用Promise异步回调。
1669
1670**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
1671
1672**系统能力:** SystemCapability.Communication.WiFi.P2P
1673
1674**返回值:**
1675
1676  | 类型 | 说明 |
1677  | -------- | -------- |
1678  | Promise&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt; | Promise对象。表示当前组信息。 |
1679
1680
1681## wifi.getCurrentGroup<sup>8+</sup>
1682
1683getCurrentGroup(callback: AsyncCallback&lt;WifiP2pGroupInfo&gt;): void
1684
1685获取P2P当前组信息,使用callback异步回调。
1686
1687**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
1688
1689**系统能力:** SystemCapability.Communication.WiFi.P2P
1690
1691**参数:**
1692
1693  | 参数名 | 类型 | 必填 | 说明 |
1694  | -------- | -------- | -------- | -------- |
1695  | callback | AsyncCallback&lt;[WifiP2pGroupInfo](#wifip2pgroupinfo8)&gt; | 是 | 回调函数。当操作成功时,err为0,data表示当前组信息。如果error为非0,表示处理出现错误。 |
1696
1697**示例:**
1698```ts
1699import wifi from '@ohos.wifi';
1700
1701wifi.getCurrentGroup((err, data) => {
1702   if (err) {
1703       console.error("get current P2P group error");
1704       return;
1705   }
1706	console.info("get current P2P group: " + JSON.stringify(data));
1707});
1708
1709wifi.getCurrentGroup().then(data => {
1710	console.info("get current P2P group: " + JSON.stringify(data));
1711});
1712```
1713
1714## wifi.getP2pPeerDevices<sup>8+</sup>
1715
1716getP2pPeerDevices(): Promise&lt;WifiP2pDevice[]&gt;
1717
1718获取P2P对端设备列表信息,使用Promise异步回调。
1719
1720**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
1721
1722**系统能力:** SystemCapability.Communication.WiFi.P2P
1723
1724**返回值:**
1725
1726  | 类型 | 说明 |
1727  | -------- | -------- |
1728  | Promise&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | Promise对象。表示对端设备列表信息。 |
1729
1730
1731## wifi.getP2pPeerDevices<sup>8+</sup>
1732
1733getP2pPeerDevices(callback: AsyncCallback&lt;WifiP2pDevice[]&gt;): void
1734
1735获取P2P对端设备列表信息,使用callback异步回调。
1736
1737**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
1738
1739**系统能力:** SystemCapability.Communication.WiFi.P2P
1740
1741**参数:**
1742
1743  | 参数名 | 类型 | 必填 | 说明 |
1744  | -------- | -------- | -------- | -------- |
1745  | callback | AsyncCallback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | 是 | 回调函数。当操作成功时,err为0,data表示对端设备列表信息。如果error为非0,表示处理出现错误。 |
1746
1747**示例:**
1748```ts
1749import wifi from '@ohos.wifi';
1750
1751wifi.getP2pPeerDevices((err, data) => {
1752   if (err) {
1753       console.error("get P2P peer devices error");
1754       return;
1755   }
1756	console.info("get P2P peer devices: " + JSON.stringify(data));
1757});
1758
1759wifi.getP2pPeerDevices().then(data => {
1760	console.info("get P2P peer devices: " + JSON.stringify(data));
1761});
1762```
1763
1764## WifiP2pDevice<sup>8+</sup>
1765
1766表示P2P设备信息。
1767
1768**系统能力:** SystemCapability.Communication.WiFi.P2P
1769
1770| 名称 | 类型 | 可读 | 可写 | 说明 |
1771| -------- | -------- | -------- | -------- | -------- |
1772| deviceName | string | 是 | 否 | 设备名称。 |
1773| deviceAddress | string | 是 | 否 | 设备MAC地址。 |
1774| primaryDeviceType | string | 是 | 否 | 主设备类型。 |
1775| deviceStatus | [P2pDeviceStatus](#p2pdevicestatus8) | 是 | 否 | 设备状态。 |
1776| groupCapabilitys | number | 是 | 否 | 群组能力。 |
1777
1778
1779## P2pDeviceStatus<sup>8+</sup>
1780
1781表示设备状态的枚举。
1782
1783**系统能力:** SystemCapability.Communication.WiFi.P2P
1784
1785| 名称 | 值 | 说明 |
1786| -------- | -------- | -------- |
1787| CONNECTED | 0 | 连接状态。 |
1788| INVITED | 1 | 邀请状态。 |
1789| FAILED | 2 | 失败状态。 |
1790| AVAILABLE | 3 | 可用状态。 |
1791| UNAVAILABLE | 4 | 不可用状态。 |
1792
1793
1794## wifi.createGroup<sup>8+</sup>
1795
1796createGroup(config: WifiP2PConfig): boolean
1797
1798创建群组。
1799
1800**需要权限:** ohos.permission.GET_WIFI_INFO
1801
1802**系统能力:** SystemCapability.Communication.WiFi.P2P
1803
1804**参数:**
1805
1806  | **参数名** | **类型** | 必填 | **说明** |
1807  | -------- | -------- | -------- | -------- |
1808  | config | [WifiP2PConfig](#wifip2pconfig8) | 是 | 群组配置信息。 |
1809
1810**返回值:**
1811
1812  | 类型 | 说明 |
1813  | -------- | -------- |
1814  | boolean | true:创建群组操作执行成功,&nbsp;false:创建群组操作执行失败。 |
1815
1816**示例:**
1817```ts
1818import wifi from '@ohos.wifi';
1819
1820try {
1821	let config:wifi.WifiP2PConfig = {
1822		deviceAddress: "****",
1823		netId: 0,
1824		passphrase: "*****",
1825		groupName: "****",
1826		goBand: 0
1827	}
1828	wifi.createGroup(config);
1829
1830}catch(error){
1831	console.error("failed:" + JSON.stringify(error));
1832}
1833```
1834
1835## WifiP2PConfig<sup>8+</sup>
1836
1837表示P2P配置信息。
1838
1839**系统能力:** SystemCapability.Communication.WiFi.P2P
1840
1841| 名称 | 类型 | 可读 | 可写 | 说明 |
1842| -------- | -------- | -------- | -------- | -------- |
1843| deviceAddress | string | 是 | 否 | 设备地址。 |
1844| netId | number | 是 | 否 | 网络ID。创建群组时-1表示创建临时组,-2表示创建永久组。 |
1845| passphrase | string | 是 | 否 | 群组密钥。 |
1846| groupName | string | 是 | 否 | 群组名称。 |
1847| goBand | [GroupOwnerBand](#groupownerband8) | 是 | 否 | 群组带宽。 |
1848
1849
1850## GroupOwnerBand<sup>8+</sup>
1851
1852表示群组带宽的枚举。
1853
1854**系统能力:** SystemCapability.Communication.WiFi.P2P
1855
1856| 名称 | 值 | 说明 |
1857| -------- | -------- | -------- |
1858| GO_BAND_AUTO | 0 | 自动模式。 |
1859| GO_BAND_2GHZ | 1 | 2GHZ。 |
1860| GO_BAND_5GHZ | 2 | 5GHZ。 |
1861
1862
1863## wifi.removeGroup<sup>8+</sup>
1864
1865removeGroup(): boolean
1866
1867移除群组。
1868
1869**需要权限:** ohos.permission.GET_WIFI_INFO
1870
1871**系统能力:** SystemCapability.Communication.WiFi.P2P
1872
1873**返回值:**
1874
1875  | 类型 | 说明 |
1876  | -------- | -------- |
1877  | boolean | true:操作执行成功,&nbsp;false:操作执行失败。 |
1878
1879**示例:**
1880```ts
1881import wifi from '@ohos.wifi';
1882
1883try {
1884	wifi.removeGroup();
1885}catch(error){
1886	console.error("failed:" + JSON.stringify(error));
1887}
1888```
1889
1890## wifi.p2pConnect<sup>8+</sup>
1891
1892p2pConnect(config: WifiP2PConfig): boolean
1893
1894执行P2P连接。
1895
1896**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
1897
1898**系统能力:** SystemCapability.Communication.WiFi.P2P
1899
1900**参数:**
1901
1902
1903  | **参数名** | **类型** | 必填 | **说明** |
1904  | -------- | -------- | -------- | -------- |
1905  | config | [WifiP2PConfig](#wifip2pconfig8) | 是 | 连接配置信息。 |
1906
1907**返回值:**
1908
1909  | 类型 | 说明 |
1910  | -------- | -------- |
1911  | boolean | true:操作执行成功,&nbsp;false:操作执行失败。 |
1912
1913
1914**示例:**
1915```ts
1916import wifi from '@ohos.wifi';
1917
1918let recvP2pConnectionChangeFunc = (result:wifi.WifiP2pLinkedInfo) => {
1919    console.info("p2p connection change receive event: " + JSON.stringify(result));
1920    wifi.getP2pLinkedInfo((err, data) => {
1921        if (err) {
1922            console.error('failed to get getP2pLinkedInfo: ' + JSON.stringify(err));
1923            return;
1924        }
1925        console.info("get getP2pLinkedInfo: " + JSON.stringify(data));
1926    });
1927}
1928wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
1929
1930let recvP2pDeviceChangeFunc = (result:wifi.WifiP2pDevice) => {
1931    console.info("p2p device change receive event: " + JSON.stringify(result));
1932}
1933wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
1934
1935let recvP2pPeerDeviceChangeFunc = (result:wifi.WifiP2pDevice[]) => {
1936    console.info("p2p peer device change receive event: " + JSON.stringify(result));
1937    wifi.getP2pPeerDevices((err, data) => {
1938        if (err) {
1939            console.error('failed to get peer devices: ' + JSON.stringify(err));
1940            return;
1941        }
1942        console.info("get peer devices: " + JSON.stringify(data));
1943        let len = data.length;
1944        for (let i = 0; i < len; ++i) {
1945            if (data[i].deviceName === "my_test_device") {
1946                console.info("p2p connect to test device: " + data[i].deviceAddress);
1947                let config:wifi.WifiP2PConfig = {
1948                    deviceAddress:data[i].deviceAddress,
1949                    netId:-2,
1950                    passphrase:"",
1951                    groupName:"",
1952                    goBand:0,
1953                }
1954                wifi.p2pConnect(config);
1955            }
1956        }
1957    });
1958}
1959wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
1960
1961let recvP2pPersistentGroupChangeFunc = () => {
1962    console.info("p2p persistent group change receive event");
1963
1964    wifi.getCurrentGroup((err, data) => {
1965        if (err) {
1966            console.error('failed to get current group: ' + JSON.stringify(err));
1967            return;
1968        }
1969        console.info("get current group: " + JSON.stringify(data));
1970    });
1971}
1972wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
1973
1974setTimeout(() => {wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);}, 125 * 1000);
1975setTimeout(() => {wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);}, 125 * 1000);
1976setTimeout(() => {wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);}, 125 * 1000);
1977setTimeout(() => {wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);}, 125 * 1000);
1978console.info("start discover devices -> " + wifi.startDiscoverDevices());
1979```
1980
1981## wifi.p2pCancelConnect<sup>8+</sup>
1982
1983p2pCancelConnect(): boolean
1984
1985取消P2P连接。
1986
1987**需要权限:** ohos.permission.GET_WIFI_INFO
1988
1989**系统能力:** SystemCapability.Communication.WiFi.P2P
1990
1991**返回值:**
1992
1993  | 类型 | 说明 |
1994  | -------- | -------- |
1995  | boolean | true:操作执行成功,&nbsp;false:操作执行失败。 |
1996
1997**示例:**
1998```ts
1999import wifi from '@ohos.wifi';
2000
2001try {
2002	wifi.p2pCancelConnect();
2003}catch(error){
2004	console.error("failed:" + JSON.stringify(error));
2005}
2006```
2007
2008## wifi.startDiscoverDevices<sup>8+</sup>
2009
2010startDiscoverDevices(): boolean
2011
2012开始发现设备。
2013
2014**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
2015
2016**系统能力:** SystemCapability.Communication.WiFi.P2P
2017
2018**返回值:**
2019
2020  | 类型 | 说明 |
2021  | -------- | -------- |
2022  | boolean | true:操作执行成功,&nbsp;false:操作执行失败。 |
2023
2024**示例:**
2025```ts
2026import wifi from '@ohos.wifi';
2027
2028try {
2029	wifi.startDiscoverDevices();
2030}catch(error){
2031	console.error("failed:" + JSON.stringify(error));
2032}
2033```
2034
2035## wifi.stopDiscoverDevices<sup>8+</sup>
2036
2037stopDiscoverDevices(): boolean
2038
2039停止发现设备。
2040
2041**需要权限:** ohos.permission.GET_WIFI_INFO
2042
2043**系统能力:** SystemCapability.Communication.WiFi.P2P
2044
2045**返回值:**
2046
2047  | 类型 | 说明 |
2048  | -------- | -------- |
2049  | boolean | true:操作执行成功,操作执行失败。 |
2050
2051**示例:**
2052```ts
2053import wifi from '@ohos.wifi';
2054
2055try {
2056	wifi.stopDiscoverDevices();
2057}catch(error){
2058	console.error("failed:" + JSON.stringify(error));
2059}
2060```
2061
2062## wifi.deletePersistentGroup<sup>8+</sup>
2063
2064deletePersistentGroup(netId: number): boolean
2065
2066删除永久组。
2067
2068**系统接口:** 此接口为系统接口。
2069
2070**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION
2071
2072**系统能力:** SystemCapability.Communication.WiFi.P2P
2073
2074**参数:**
2075
2076
2077  | **参数名** | **类型** | 必填 | **说明** |
2078  | -------- | -------- | -------- | -------- |
2079  | netId | number | 是 | 组的ID。 |
2080
2081**返回值:**
2082
2083  | 类型 | 说明 |
2084  | -------- | -------- |
2085  | boolean | true:操作执行成功,操作执行失败。 |
2086
2087**示例:**
2088```ts
2089import wifi from '@ohos.wifi';
2090
2091try {
2092	let netId = 0;
2093	wifi.deletePersistentGroup(netId);
2094}catch(error){
2095	console.error("failed:" + JSON.stringify(error));
2096}
2097```
2098
2099## WifiP2pGroupInfo<sup>8+</sup>
2100
2101表示P2P群组相关信息。
2102
2103**系统能力:** SystemCapability.Communication.WiFi.P2P
2104
2105| 名称 | 类型 | 可读 | 可写 | 说明 |
2106| -------- | -------- | -------- | -------- | -------- |
2107| isP2pGo | boolean | 是 | 否 | 是否是群主。 |
2108| ownerInfo | [WifiP2pDevice](#wifip2pdevice8) | 是 | 否 | 群组的设备信息。 |
2109| passphrase | string | 是 | 否 | 群组密钥。 |
2110| interface | string | 是 | 否 | 接口名称。 |
2111| groupName | string | 是 | 否 | 群组名称。 |
2112| networkId | number | 是 | 否 | 网络ID。 |
2113| frequency | number | 是 | 否 | 群组的频率。 |
2114| clientDevices | [WifiP2pDevice[]](#wifip2pdevice8) | 是 | 否 | 接入的设备列表信息。 |
2115| goIpAddress | string | 是 | 否 | 群组IP地址。 |
2116
2117
2118## wifi.setDeviceName<sup>8+</sup>
2119
2120setDeviceName(devName: string): boolean
2121
2122设置设备名称。
2123
2124**系统接口:** 此接口为系统接口。
2125
2126**需要权限:** ohos.permission.SET_WIFI_INFOohos.permission.MANAGE_WIFI_CONNECTION,仅系统应用可用。
2127
2128**系统能力:** SystemCapability.Communication.WiFi.P2P
2129
2130**参数:**
2131
2132  | **参数名** | **类型** | **必填** | **说明** |
2133  | -------- | -------- | -------- | -------- |
2134  | devName | string | 是 | 设备名称。 |
2135
2136**返回值:**
2137
2138  | **类型** | **说明** |
2139  | -------- | -------- |
2140  | boolean | true:操作成功,&nbsp;false:操作失败。 |
2141
2142**示例:**
2143```ts
2144import wifi from '@ohos.wifi';
2145
2146try {
2147	let name = "****";
2148	wifi.setDeviceName(name);
2149}catch(error){
2150	console.error("failed:" + JSON.stringify(error));
2151}
2152```
2153
2154## wifi.on('wifiStateChange')<sup>7+</sup>
2155
2156on(type: "wifiStateChange", callback: Callback&lt;number&gt;): void
2157
2158注册WLAN状态改变事件。
2159
2160**需要权限:** ohos.permission.GET_WIFI_INFO
2161
2162**系统能力:** SystemCapability.Communication.WiFi.STA
2163
2164**参数:**
2165
2166  | **参数名** | **类型** | **必填** | **说明** |
2167  | -------- | -------- | -------- | -------- |
2168  | type | string | 是 | 固定填"wifiStateChange"字符串。 |
2169  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2170
2171**状态改变事件的枚举:**
2172
2173| **枚举值** | **说明** |
2174| -------- | -------- |
2175| 0 | 未激活。 |
2176| 1 | 已激活。 |
2177| 2 | 激活中。 |
2178| 3 | 去激活中。 |
2179
2180
2181## wifi.off('wifiStateChange')<sup>7+</sup>
2182
2183off(type: "wifiStateChange", callback?: Callback&lt;number&gt;): void
2184
2185取消注册WLAN状态改变事件。
2186
2187**需要权限:** ohos.permission.GET_WIFI_INFO
2188
2189**系统能力:** SystemCapability.Communication.WiFi.STA
2190
2191**参数:**
2192
2193  | **参数名** | **类型** | **必填** | **说明** |
2194  | -------- | -------- | -------- | -------- |
2195  | type | string | 是 | 固定填"wifiStateChange"字符串。 |
2196  | callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2197
2198**示例:**
2199```ts
2200import wifi from '@ohos.wifi';
2201
2202let recvPowerNotifyFunc = (result:number) => {
2203    console.info("Receive power state change event: " + result);
2204}
2205
2206// Register event
2207wifi.on("wifiStateChange", recvPowerNotifyFunc);
2208
2209// Unregister event
2210wifi.off("wifiStateChange", recvPowerNotifyFunc);
2211```
2212
2213
2214## wifi.on('wifiConnectionChange')<sup>7+</sup>
2215
2216on(type: "wifiConnectionChange", callback: Callback&lt;number&gt;): void
2217
2218注册WLAN连接状态改变事件。
2219
2220**需要权限:** ohos.permission.GET_WIFI_INFO
2221
2222**系统能力:** SystemCapability.Communication.WiFi.STA
2223
2224**参数:**
2225
2226  | **参数名** | **类型** | **必填** | **说明** |
2227  | -------- | -------- | -------- | -------- |
2228  | type | string | 是 | 固定填"wifiConnectionChange"字符串。 |
2229  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2230
2231**连接状态改变事件的枚举:**
2232
2233| **枚举值** | **说明** |
2234| -------- | -------- |
2235| 0 | 已断开。 |
2236| 1 | 已连接。 |
2237
2238
2239## wifi.off('wifiConnectionChange')<sup>7+</sup>
2240
2241off(type: "wifiConnectionChange", callback?: Callback&lt;number&gt;): void
2242
2243取消注册WLAN连接状态改变事件。
2244
2245**需要权限:** ohos.permission.GET_WIFI_INFO
2246
2247**系统能力:** SystemCapability.Communication.WiFi.STA
2248
2249**参数:**
2250
2251  | **参数名** | **类型** | **必填** | **说明** |
2252  | -------- | -------- | -------- | -------- |
2253  | type | string | 是 | 固定填"wifiConnectionChange"字符串。 |
2254  | callback | Callback&lt;number&gt; | 否 | 连接状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2255
2256**示例:**
2257```ts
2258import wifi from '@ohos.wifi';
2259
2260let recvWifiConnectionChangeFunc = (result:number) => {
2261    console.info("Receive wifi connection change event: " + result);
2262}
2263
2264// Register event
2265wifi.on("wifiConnectionChange", recvWifiConnectionChangeFunc);
2266
2267// Unregister event
2268wifi.off("wifiConnectionChange", recvWifiConnectionChangeFunc);
2269```
2270
2271## wifi.on('wifiScanStateChange')<sup>7+</sup>
2272
2273on(type: "wifiScanStateChange", callback: Callback&lt;number&gt;): void
2274
2275注册扫描状态改变事件。
2276
2277**需要权限:** ohos.permission.GET_WIFI_INFO
2278
2279**系统能力:** SystemCapability.Communication.WiFi.STA
2280
2281**参数:**
2282
2283  | **参数名** | **类型** | **必填** | **说明** |
2284  | -------- | -------- | -------- | -------- |
2285  | type | string | 是 | 固定填"wifiScanStateChange"字符串。 |
2286  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2287
2288**扫描状态改变事件的枚举:**
2289
2290| **枚举值** | **说明** |
2291| -------- | -------- |
2292| 0 | 扫描失败。 |
2293| 1 | 扫描成功。 |
2294
2295
2296## wifi.off('wifiScanStateChange')<sup>7+</sup>
2297
2298off(type: "wifiScanStateChange", callback?: Callback&lt;number&gt;): void
2299
2300取消注册扫描状态改变事件。
2301
2302**需要权限:** ohos.permission.GET_WIFI_INFO
2303
2304**系统能力:** SystemCapability.Communication.WiFi.STA
2305
2306**参数:**
2307
2308| **参数名** | **类型** | **必填** | **说明** |
2309| -------- | -------- | -------- | -------- |
2310| type | string | 是 | 固定填"wifiScanStateChange"字符串。 |
2311| callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2312
2313**示例:**
2314```ts
2315import wifi from '@ohos.wifi';
2316
2317let recvWifiScanStateChangeFunc = (result:number) => {
2318    console.info("Receive Wifi scan state change event: " + result);
2319}
2320
2321// Register event
2322wifi.on("wifiScanStateChange", recvWifiScanStateChangeFunc);
2323
2324// Unregister event
2325wifi.off("wifiScanStateChange", recvWifiScanStateChangeFunc);
2326```
2327
2328## wifi.on('wifiRssiChange')<sup>7+</sup>
2329
2330on(type: "wifiRssiChange", callback: Callback&lt;number&gt;): void
2331
2332注册RSSI状态改变事件。
2333
2334**需要权限:** ohos.permission.GET_WIFI_INFO
2335
2336**系统能力:** SystemCapability.Communication.WiFi.STA
2337
2338**参数:**
2339
2340  | **参数名** | **类型** | **必填** | **说明** |
2341  | -------- | -------- | -------- | -------- |
2342  | type | string | 是 | 固定填"wifiRssiChange"字符串。 |
2343  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数,返回以dBm为单位的RSSI值。 |
2344
2345
2346## wifi.off('wifiRssiChange')<sup>7+</sup>
2347
2348off(type: "wifiRssiChange", callback?: Callback&lt;number&gt;): void
2349
2350取消注册RSSI状态改变事件。
2351
2352**需要权限:** ohos.permission.GET_WIFI_INFO
2353
2354**系统能力:** SystemCapability.Communication.WiFi.STA
2355
2356**参数:**
2357
2358  | **参数名** | **类型** | **必填** | **说明** |
2359  | -------- | -------- | -------- | -------- |
2360  | type | string | 是 | 固定填"wifiRssiChange"字符串。 |
2361  | callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2362
2363**示例:**
2364```ts
2365import wifi from '@ohos.wifi';
2366
2367let recvWifiRssiChangeFunc = (result:number) => {
2368    console.info("Receive wifi rssi change event: " + result);
2369}
2370
2371// Register event
2372wifi.on("wifiRssiChange", recvWifiRssiChangeFunc);
2373
2374// Unregister event
2375wifi.off("wifiRssiChange", recvWifiRssiChangeFunc);
2376
2377```
2378## wifi.on('streamChange')<sup>7+</sup>
2379
2380on(type: "streamChange", callback: Callback&lt;number&gt;): void
2381
2382注册WIFI流更改事件。
2383
2384**系统接口:** 此接口为系统接口。
2385
2386**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION
2387
2388**系统能力:** SystemCapability.Communication.WiFi.STA
2389
2390**参数:**
2391
2392  | **参数名** | **类型** | **必填** | **说明** |
2393  | -------- | -------- | -------- | -------- |
2394  | type | string | 是 | 固定填"streamChange"字符串。 |
2395  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 |
2396
2397## wifi.off('streamChange')<sup>7+</sup>
2398
2399off(type: "streamChange", callback?: Callback&lt;number&gt;): void
2400
2401取消注册WIFI流更改事件。
2402
2403**系统接口:** 此接口为系统接口。
2404
2405**需要权限:** ohos.permission.MANAGE_WIFI_CONNECTION
2406
2407**系统能力:** SystemCapability.Communication.WiFi.STA
2408
2409**参数:**
2410
2411| **参数名** | **类型** | **必填** | **说明** |
2412| -------- | -------- | -------- | -------- |
2413| type | string | 是 | 固定填"streamChange"字符串。 |
2414| callback | Callback&lt;number&gt; | 否| 状态改变回调函数,返回0:无,1:向下,2:向上,3:双向。 |
2415
2416**示例:**
2417```ts
2418import wifi from '@ohos.wifi';
2419
2420let recvStreamChangeFunc = (result:number) => {
2421    console.info("Receive stream change event: " + result);
2422}
2423
2424// Register event
2425wifi.on("streamChange", recvStreamChangeFunc);
2426
2427// Unregister event
2428wifi.off("streamChange", recvStreamChangeFunc);
2429
2430```
2431
2432## wifi.on('hotspotStateChange')<sup>7+</sup>
2433
2434on(type: "hotspotStateChange", callback: Callback&lt;number&gt;): void
2435
2436注册热点状态改变事件。
2437
2438**需要权限:** ohos.permission.GET_WIFI_INFO
2439
2440**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2441
2442**参数:**
2443
2444  | **参数名** | **类型** | **必填** | **说明** |
2445  | -------- | -------- | -------- | -------- |
2446  | type | string | 是 | 固定填"hotspotStateChange"字符串。 |
2447  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2448
2449**热点状态改变事件的枚举:**
2450
2451| **枚举值** | **说明** |
2452| -------- | -------- |
2453| 0 | 未激活。 |
2454| 1 | 已激活。 |
2455| 2 | 激活中。 |
2456| 3 | 去激活中。 |
2457
2458**示例:**
2459```ts
2460import wifi from '@ohos.wifi';
2461
2462let recvHotspotStateChangeFunc = (result:number) => {
2463    console.info("Receive hotspot state change event: " + result);
2464}
2465
2466// Register event
2467wifi.on("hotspotStateChange", recvHotspotStateChangeFunc);
2468
2469// Unregister event
2470wifi.off("hotspotStateChange", recvHotspotStateChangeFunc);
2471```
2472
2473## wifi.off('hotspotStateChange')<sup>7+</sup>
2474
2475off(type: "hotspotStateChange", callback?: Callback&lt;number&gt;): void
2476
2477取消注册热点状态改变事件。
2478
2479**需要权限:** ohos.permission.GET_WIFI_INFO
2480
2481**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2482
2483**参数:**
2484
2485  | **参数名** | **类型** | **必填** | **说明** |
2486  | -------- | -------- | -------- | -------- |
2487  | type | string | 是 | 固定填"hotspotStateChange"字符串。 |
2488  | callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2489
2490## wifi.on('hotspotStaJoin')<sup>7+</sup>
2491
2492on(type: "hotspotStaJoin", callback: Callback&lt;StationInfo&gt;): void
2493
2494注册wifi热点sta加入事件。
2495
2496**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
2497
2498**系统接口:** 此接口为系统接口。
2499
2500**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2501
2502**参数:**
2503
2504  | **参数名** | **类型** | **必填** | **说明** |
2505  | -------- | -------- | -------- | -------- |
2506  | type | string | 是 | 固定填"hotspotStaJoin"字符串。 |
2507  | callback | Callback&lt;StationInfo&gt; | 是 | 状态改变回调函数。 |
2508
2509## wifi.off('hotspotStaJoin')<sup>7+</sup>
2510
2511off(type: "hotspotStaJoin", callback?: Callback&lt;StationInfo&gt;): void
2512
2513取消注册wifi热点sta加入事件。
2514
2515**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
2516
2517**系统接口:** 此接口为系统接口。
2518
2519**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2520
2521**参数:**
2522
2523  | **参数名** | **类型** | **必填** | **说明** |
2524  | -------- | -------- | -------- | -------- |
2525  | type | string | 是 | 固定填"hotspotStaJoin"字符串。 |
2526  | callback | Callback&lt;StationInfo&gt; | 否 | 状态改变回调函数。 |
2527
2528  **示例:**
2529```ts
2530import wifi from '@ohos.wifi';
2531
2532let recvHotspotStaJoinFunc = (result:wifi.StationInfo) => {
2533    console.info("Receive hotspot sta join event: " + result);
2534}
2535
2536// Register event
2537wifi.on("hotspotStaJoin", recvHotspotStaJoinFunc);
2538
2539// Unregister event
2540wifi.off("hotspotStaJoin", recvHotspotStaJoinFunc);
2541
2542```
2543
2544## wifi.on('hotspotStaLeave')<sup>7+</sup>
2545
2546on(type: "hotspotStaLeave", callback: Callback&lt;StationInfo&gt;): void
2547
2548注册wifi热点sta离开事件。
2549
2550**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
2551
2552**系统接口:** 此接口为系统接口。
2553
2554**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2555
2556**参数:**
2557
2558  | **参数名** | **类型** | **必填** | **说明** |
2559  | -------- | -------- | -------- | -------- |
2560  | type | string | 是 | 固定填"hotspotStaLeave"字符串。 |
2561  | callback | Callback&lt;StationInf]&gt; | 是 | 状态改变回调函数。 |
2562
2563## wifi.off('hotspotStaLeave')<sup>7+</sup>
2564
2565off(type: "hotspotStaLeave", callback?: Callback&lt;StationInfo&gt;): void
2566
2567取消注册wifi热点sta离开事件。
2568
2569**需要权限:** ohos.permission.MANAGE_WIFI_HOTSPOT
2570
2571**系统接口:** 此接口为系统接口。
2572
2573**系统能力:** SystemCapability.Communication.WiFi.AP.Core
2574
2575**参数:**
2576
2577  | **参数名** | **类型** | **必填** | **说明** |
2578  | -------- | -------- | -------- | -------- |
2579  | type | string | 是 | 固定填"hotspotStaLeave"字符串。 |
2580  | callback | Callback&lt;StationInf]&gt; | 否 | 状态改变回调函数。 |
2581
2582  **示例:**
2583```ts
2584import wifi from '@ohos.wifi';
2585
2586let recvHotspotStaLeaveFunc = (result:wifi.StationInfo) => {
2587    console.info("Receive hotspot sta leave event: " + result);
2588}
2589
2590// Register event
2591wifi.on("hotspotStaLeave", recvHotspotStaLeaveFunc);
2592
2593// Unregister event
2594wifi.off("hotspotStaLeave", recvHotspotStaLeaveFunc);
2595
2596```
2597
2598## wifi.on('p2pStateChange')<sup>8+</sup>
2599
2600on(type: "p2pStateChange", callback: Callback&lt;number&gt;): void
2601
2602注册P2P开关状态改变事件。
2603
2604**需要权限:** ohos.permission.GET_WIFI_INFO
2605
2606**系统能力:** SystemCapability.Communication.WiFi.P2P
2607
2608**参数:**
2609
2610  | **参数名** | **类型** | **必填** | **说明** |
2611  | -------- | -------- | -------- | -------- |
2612  | type | string | 是 | 固定填"p2pStateChange"字符串。 |
2613  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2614
2615**P2P状态改变事件的枚举:**
2616
2617| **枚举值** | **说明** |
2618| -------- | -------- |
2619| 1 | 空闲。 |
2620| 2 | 打开中。 |
2621| 3 | 已打开。 |
2622| 4 | 关闭中。 |
2623| 5 | 已关闭。 |
2624
2625## wifi.off('p2pStateChange')<sup>8+</sup>
2626
2627off(type: "p2pStateChange", callback?: Callback&lt;number&gt;): void
2628
2629取消注册P2P开关状态改变事件。
2630
2631**需要权限:** ohos.permission.GET_WIFI_INFO
2632
2633**系统能力:** SystemCapability.Communication.WiFi.P2P
2634
2635**参数:**
2636
2637  | **参数名** | **类型** | **必填** | **说明** |
2638  | -------- | -------- | -------- | -------- |
2639  | type | string | 是 | 固定填"p2pStateChange"字符串。 |
2640  | callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2641
2642**示例:**
2643```ts
2644import wifi from '@ohos.wifi';
2645
2646let recvP2pStateChangeFunc = (result:number) => {
2647    console.info("Receive p2p state change event: " + result);
2648}
2649
2650// Register event
2651wifi.on("p2pStateChange", recvP2pStateChangeFunc);
2652
2653// Unregister event
2654wifi.off("p2pStateChange", recvP2pStateChangeFunc);
2655```
2656
2657## wifi.on('p2pConnectionChange')<sup>8+</sup>
2658
2659on(type: "p2pConnectionChange", callback: Callback&lt;WifiP2pLinkedInfo&gt;): void
2660
2661注册P2P连接状态改变事件。
2662
2663**需要权限:** ohos.permission.GET_WIFI_INFO
2664
2665**系统能力:** SystemCapability.Communication.WiFi.P2P
2666
2667**参数:**
2668
2669  | **参数名** | **类型** | **必填** | **说明** |
2670  | -------- | -------- | -------- | -------- |
2671  | type | string | 是 | 固定填"p2pConnectionChange"字符串。 |
2672  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | 是 | 状态改变回调函数。 |
2673
2674
2675## wifi.off('p2pConnectionChange')<sup>8+</sup>
2676
2677off(type: "p2pConnectionChange", callback?: Callback&lt;WifiP2pLinkedInfo&gt;): void
2678
2679取消注册P2P连接状态改变事件。
2680
2681**需要权限:** ohos.permission.GET_WIFI_INFO
2682
2683**系统能力:** SystemCapability.Communication.WiFi.P2P
2684
2685**参数:**
2686
2687  | **参数名** | **类型** | **必填** | **说明** |
2688  | -------- | -------- | -------- | -------- |
2689  | type | string | 是 | 固定填"p2pConnectionChange"字符串。 |
2690  | callback | Callback&lt;[WifiP2pLinkedInfo](#wifip2plinkedinfo8)&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2691
2692**示例:**
2693```ts
2694import wifi from '@ohos.wifi';
2695
2696let recvP2pConnectionChangeFunc = (result:wifi.WifiP2pLinkedInfo) => {
2697    console.info("Receive p2p connection change event: " + result);
2698}
2699
2700// Register event
2701wifi.on("p2pConnectionChange", recvP2pConnectionChangeFunc);
2702
2703// Unregister event
2704wifi.off("p2pConnectionChange", recvP2pConnectionChangeFunc);
2705```
2706
2707## wifi.on('p2pDeviceChange')<sup>8+</sup>
2708
2709on(type: "p2pDeviceChange", callback: Callback&lt;WifiP2pDevice&gt;): void
2710
2711注册P2P设备状态改变事件。
2712
2713**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
2714
2715**系统能力:** SystemCapability.Communication.WiFi.P2P
2716
2717**参数:**
2718
2719  | **参数名** | **类型** | **必填** | **说明** |
2720  | -------- | -------- | -------- | -------- |
2721  | type | string | 是 | 固定填"p2pDeviceChange"字符串。 |
2722  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | 是 | 状态改变回调函数。 |
2723
2724
2725## wifi.off('p2pDeviceChange')<sup>8+</sup>
2726
2727off(type: "p2pDeviceChange", callback?: Callback&lt;WifiP2pDevice&gt;): void
2728
2729取消注册P2P设备状态改变事件。
2730
2731**需要权限:** ohos.permission.LOCATION
2732
2733**系统能力:** SystemCapability.Communication.WiFi.P2P
2734
2735**参数:**
2736
2737  | **参数名** | **类型** | **必填** | **说明** |
2738  | -------- | -------- | -------- | -------- |
2739  | type | string | 是 | 固定填"p2pDeviceChange"字符串。 |
2740  | callback | Callback&lt;[WifiP2pDevice](#wifip2pdevice8)&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2741
2742**示例:**
2743```ts
2744import wifi from '@ohos.wifi';
2745
2746let recvP2pDeviceChangeFunc = (result:wifi.WifiP2pDevice) => {
2747    console.info("Receive p2p device change event: " + result);
2748}
2749
2750// Register event
2751wifi.on("p2pDeviceChange", recvP2pDeviceChangeFunc);
2752
2753// Unregister event
2754wifi.off("p2pDeviceChange", recvP2pDeviceChangeFunc);
2755```
2756
2757## wifi.on('p2pPeerDeviceChange')<sup>8+</sup>
2758
2759on(type: "p2pPeerDeviceChange", callback: Callback&lt;WifiP2pDevice[]&gt;): void
2760
2761注册P2P对端设备状态改变事件。
2762
2763**需要权限:** ohos.permission.GET_WIFI_INFOohos.permission.LOCATION
2764
2765**系统能力:** SystemCapability.Communication.WiFi.P2P
2766
2767**参数:**
2768
2769  | **参数名** | **类型** | **必填** | **说明** |
2770  | -------- | -------- | -------- | -------- |
2771  | type | string | 是 | 固定填"p2pPeerDeviceChange"字符串。 |
2772  | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | 是 | 状态改变回调函数。 |
2773
2774
2775## wifi.off('p2pPeerDeviceChange')<sup>8+</sup>
2776
2777off(type: "p2pPeerDeviceChange", callback?: Callback&lt;WifiP2pDevice[]&gt;): void
2778
2779取消注册P2P对端设备状态改变事件。
2780
2781**需要权限:** ohos.permission.LOCATION
2782
2783**系统能力:** SystemCapability.Communication.WiFi.P2P
2784
2785**参数:**
2786
2787  | **参数名** | **类型** | **必填** | **说明** |
2788  | -------- | -------- | -------- | -------- |
2789  | type | string | 是 | 固定填"p2pPeerDeviceChange"字符串。 |
2790  | callback | Callback&lt;[WifiP2pDevice[]](#wifip2pdevice8)&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2791
2792**示例:**
2793```ts
2794import wifi from '@ohos.wifi';
2795
2796let recvP2pPeerDeviceChangeFunc = (result:wifi.WifiP2pDevice[]) => {
2797    console.info("Receive p2p peer device change event: " + result);
2798}
2799
2800// Register event
2801wifi.on("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
2802
2803// Unregister event
2804wifi.off("p2pPeerDeviceChange", recvP2pPeerDeviceChangeFunc);
2805```
2806
2807## wifi.on('p2pPersistentGroupChange')<sup>8+</sup>
2808
2809on(type: "p2pPersistentGroupChange", callback: Callback&lt;void&gt;): void
2810
2811注册P2P永久组状态改变事件。
2812
2813**需要权限:** ohos.permission.GET_WIFI_INFO
2814
2815**系统能力:** SystemCapability.Communication.WiFi.P2P
2816
2817**参数:**
2818
2819  | **参数名** | **类型** | **必填** | **说明** |
2820  | -------- | -------- | -------- | -------- |
2821  | type | string | 是 | 固定填"p2pPersistentGroupChange"字符串。 |
2822  | callback | Callback&lt;void&gt; | 是 | 状态改变回调函数。 |
2823
2824
2825## wifi.off('p2pPersistentGroupChange')<sup>8+</sup>
2826
2827off(type: "p2pPersistentGroupChange", callback?: Callback&lt;void&gt;): void
2828
2829取消注册P2P永久组状态改变事件。
2830
2831**需要权限:** ohos.permission.GET_WIFI_INFO
2832
2833**系统能力:** SystemCapability.Communication.WiFi.P2P
2834
2835**参数:**
2836
2837  | **参数名** | **类型** | **必填** | **说明** |
2838  | -------- | -------- | -------- | -------- |
2839  | type | string | 是 | 固定填"p2pPersistentGroupChange"字符串。 |
2840  | callback | Callback&lt;void&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2841
2842**示例:**
2843```ts
2844import wifi from '@ohos.wifi';
2845
2846let recvP2pPersistentGroupChangeFunc = (result:void) => {
2847    console.info("Receive p2p persistent group change event: " + result);
2848}
2849
2850// Register event
2851wifi.on("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
2852
2853// Unregister event
2854wifi.off("p2pPersistentGroupChange", recvP2pPersistentGroupChangeFunc);
2855
2856```
2857
2858## wifi.on('p2pDiscoveryChange')<sup>8+</sup>
2859
2860on(type: "p2pDiscoveryChange", callback: Callback&lt;number&gt;): void
2861
2862注册发现设备状态改变事件。
2863
2864**需要权限:** ohos.permission.GET_WIFI_INFO
2865
2866**系统能力:** SystemCapability.Communication.WiFi.P2P
2867
2868**参数:**
2869
2870  | **参数名** | **类型** | **必填** | **说明** |
2871  | -------- | -------- | -------- | -------- |
2872  | type | string | 是 | 固定填"p2pDiscoveryChange"字符串。 |
2873  | callback | Callback&lt;number&gt; | 是 | 状态改变回调函数。 |
2874
2875**发现设备状态改变事件的枚举:**
2876
2877| **枚举值** | **说明** |
2878| -------- | -------- |
2879| 0 | 初始状态。 |
2880| 1 | 发现成功。 |
2881
2882
2883## wifi.off('p2pDiscoveryChange')<sup>8+</sup>
2884
2885off(type: "p2pDiscoveryChange", callback?: Callback&lt;number&gt;): void
2886
2887取消注册发现设备状态改变事件。
2888
2889**需要权限:** ohos.permission.GET_WIFI_INFO
2890
2891**系统能力:** SystemCapability.Communication.WiFi.P2P
2892
2893**参数:**
2894
2895  | **参数名** | **类型** | **必填** | **说明** |
2896  | -------- | -------- | -------- | -------- |
2897  | type | string | 是 | 固定填"p2pDiscoveryChange"字符串。 |
2898  | callback | Callback&lt;number&gt; | 否 | 状态改变回调函数。如果callback不填,将取消注册该事件关联的所有回调函数。 |
2899
2900**示例:**
2901```ts
2902import wifi from '@ohos.wifi';
2903
2904let recvP2pDiscoveryChangeFunc = (result:number) => {
2905    console.info("Receive p2p discovery change event: " + result);
2906}
2907
2908// Register event
2909wifi.on("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
2910
2911// Unregister event
2912wifi.off("p2pDiscoveryChange", recvP2pDiscoveryChangeFunc);
2913```