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