1e41f4b71Sopenharmony_ci# @ohos.net.sharing (Network Sharing Management) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe Network Sharing module allows you to share your device's Internet connection with other connected devices by means of Wi-Fi hotspot, Bluetooth, and USB sharing. It also allows you to query the network sharing state and shared mobile data volume.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci```js
13e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci## sharing.isSharingSupported
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ciisSharingSupported(callback: AsyncCallback\<boolean>): void
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciChecks whether network sharing is supported. This API uses an asynchronous callback to return the result.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**System API**: This is a system API.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci**Parameters**
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                                  |
31e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | -------------------------------------- |
32e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that network sharing is supported, and **false** means the opposite.|
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**Error codes**
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci| ID| Error Message                                    |
37e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
38e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
39e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
40e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
41e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
42e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Example**
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci```js
47e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
48e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_cisharing.isSharingSupported((error: BusinessError, data: boolean) => {
51e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
52e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
53e41f4b71Sopenharmony_ci});
54e41f4b71Sopenharmony_ci```
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci## sharing.isSharingSupported
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ciisSharingSupported(): Promise\<boolean>
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ciChecks whether network sharing is supported. This API uses a promise to return the result.
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci**System API**: This is a system API.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**Return value**
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci| Type             | Description                                 |
71e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------- |
72e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means that network sharing is supported, and **false** means the opposite.|
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci**Error codes**
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci| ID| Error Message                                    |
77e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
78e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
79e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
80e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
81e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
82e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Example**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci```js
87e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
88e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_cisharing
91e41f4b71Sopenharmony_ci  .isSharingSupported()
92e41f4b71Sopenharmony_ci  .then((data: boolean) => {
93e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
94e41f4b71Sopenharmony_ci  })
95e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
96e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
97e41f4b71Sopenharmony_ci  });
98e41f4b71Sopenharmony_ci```
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci## sharing.isSharing
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ciisSharing(callback: AsyncCallback\<boolean>): void
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ciChecks whether network sharing is in progress. This API uses an asynchronous callback to return the result.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci**System API**: This is a system API.
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**Parameters**
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                                |
115e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------------------ |
116e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes  | Callback used to return the result. The value **true** means that network sharing is in progress, and **false** means the opposite.|
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci**Error codes**
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci| ID| Error Message                                    |
121e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
122e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
123e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
124e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
125e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
126e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ci**Example**
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ci```js
131e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
132e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_cisharing.isSharing((error: BusinessError, data: boolean) => {
135e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
136e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
137e41f4b71Sopenharmony_ci});
138e41f4b71Sopenharmony_ci```
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci## sharing.isSharing
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ciisSharing(): Promise\<boolean>
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ciChecks whether network sharing is in progress. This API uses a promise to return the result.
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci**System API**: This is a system API.
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci**Return value**
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci| Type             | Description                                                           |
155e41f4b71Sopenharmony_ci| ----------------- | --------------------------------------------------------------- |
156e41f4b71Sopenharmony_ci| Promise\<boolean> | Promise used to return the result. The value **true** means that network sharing is in progress, and **false** means the opposite.|
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**Error codes**
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci| ID| Error Message                                    |
161e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
162e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
163e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
164e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
165e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
166e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci**Example**
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci```js
171e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
172e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_cisharing
175e41f4b71Sopenharmony_ci  .isSharing()
176e41f4b71Sopenharmony_ci  .then((data: boolean) => {
177e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
178e41f4b71Sopenharmony_ci  })
179e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
180e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
181e41f4b71Sopenharmony_ci  });
182e41f4b71Sopenharmony_ci```
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci## sharing.startSharing
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_cistartSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ciStarts network sharing of a specified type. This API uses an asynchronous callback to return the result.
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci**System API**: This is a system API.
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**Parameters**
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                    |
199e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ---------------------------------------- |
200e41f4b71Sopenharmony_ci| type     | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
201e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result.        |
202e41f4b71Sopenharmony_ci
203e41f4b71Sopenharmony_ci**Error codes**
204e41f4b71Sopenharmony_ci
205e41f4b71Sopenharmony_ci| ID| Error Message                                    |
206e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
207e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
208e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
209e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
210e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
211e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
212e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
213e41f4b71Sopenharmony_ci| 2202004   | Try to share an unavailable iface.           |
214e41f4b71Sopenharmony_ci| 2202005   | WiFi sharing failed.                         |
215e41f4b71Sopenharmony_ci| 2202006   | Bluetooth sharing failed.                    |
216e41f4b71Sopenharmony_ci| 2202009   | Failed to enable forwarding for network sharing.       |
217e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**Example**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci```js
222e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
223e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
226e41f4b71Sopenharmony_cisharing.startSharing(SHARING_WIFI, (error: BusinessError) => {
227e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
228e41f4b71Sopenharmony_ci});
229e41f4b71Sopenharmony_ci```
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci## sharing.startSharing
232e41f4b71Sopenharmony_ci
233e41f4b71Sopenharmony_cistartSharing(type: SharingIfaceType): Promise\<void>
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ciStarts network sharing of a specified type. This API uses a promise to return the result.
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_ci**System API**: This is a system API.
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
242e41f4b71Sopenharmony_ci
243e41f4b71Sopenharmony_ci**Parameters**
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci| Name| Type                                 | Mandatory| Description                                    |
246e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | ---------------------------------------- |
247e41f4b71Sopenharmony_ci| type   | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
248e41f4b71Sopenharmony_ci
249e41f4b71Sopenharmony_ci**Return value**
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci| Type          | Description                                 |
252e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
253e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.|
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci**Error codes**
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci| ID| Error Message                                    |
258e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
259e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
260e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
261e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
262e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
263e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
264e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
265e41f4b71Sopenharmony_ci| 2202004   | Try to share an unavailable iface.           |
266e41f4b71Sopenharmony_ci| 2202005   | WiFi sharing failed.                         |
267e41f4b71Sopenharmony_ci| 2202006   | Bluetooth sharing failed.                    |
268e41f4b71Sopenharmony_ci| 2202009   | Failed to enable forwarding for network sharing.       |
269e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci**Example**
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci```js
274e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
275e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
278e41f4b71Sopenharmony_cisharing
279e41f4b71Sopenharmony_ci  .startSharing(SHARING_WIFI)
280e41f4b71Sopenharmony_ci  .then(() => {
281e41f4b71Sopenharmony_ci    console.log('start wifi sharing successful');
282e41f4b71Sopenharmony_ci  })
283e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
284e41f4b71Sopenharmony_ci    console.log('start wifi sharing failed');
285e41f4b71Sopenharmony_ci  });
286e41f4b71Sopenharmony_ci```
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci## sharing.stopSharing
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_cistopSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ciStops network sharing of a specified type. This API uses an asynchronous callback to return the result.
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**System API**: This is a system API.
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci**Parameters**
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                    |
303e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ---------------------------------------- |
304e41f4b71Sopenharmony_ci| type     | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
305e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result.         |
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci**Error codes**
308e41f4b71Sopenharmony_ci
309e41f4b71Sopenharmony_ci| ID| Error Message                                    |
310e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
311e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
312e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
313e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
314e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
315e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
316e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
317e41f4b71Sopenharmony_ci| 2202004   | Try to share an unavailable iface.           |
318e41f4b71Sopenharmony_ci| 2202005   | WiFi sharing failed.                         |
319e41f4b71Sopenharmony_ci| 2202006   | Bluetooth sharing failed.                    |
320e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci**Example**
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci```js
325e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
326e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
329e41f4b71Sopenharmony_cisharing.stopSharing(SHARING_WIFI, (error: BusinessError) => {
330e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
331e41f4b71Sopenharmony_ci});
332e41f4b71Sopenharmony_ci```
333e41f4b71Sopenharmony_ci
334e41f4b71Sopenharmony_ci## sharing.stopSharing
335e41f4b71Sopenharmony_ci
336e41f4b71Sopenharmony_cistopSharing(type: SharingIfaceType): Promise\<void>
337e41f4b71Sopenharmony_ci
338e41f4b71Sopenharmony_ciStops network sharing of a specified type. This API uses a promise to return the result.
339e41f4b71Sopenharmony_ci
340e41f4b71Sopenharmony_ci**System API**: This is a system API.
341e41f4b71Sopenharmony_ci
342e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
345e41f4b71Sopenharmony_ci
346e41f4b71Sopenharmony_ci**Parameters**
347e41f4b71Sopenharmony_ci
348e41f4b71Sopenharmony_ci| Name| Type                                 | Mandatory| Description                                    |
349e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | ---------------------------------------- |
350e41f4b71Sopenharmony_ci| type   | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
351e41f4b71Sopenharmony_ci
352e41f4b71Sopenharmony_ci**Return value**
353e41f4b71Sopenharmony_ci
354e41f4b71Sopenharmony_ci| Type          | Description                                 |
355e41f4b71Sopenharmony_ci| -------------- | ------------------------------------- |
356e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result.|
357e41f4b71Sopenharmony_ci
358e41f4b71Sopenharmony_ci**Error codes**
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci| ID| Error Message                                    |
361e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
362e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
363e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
364e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
365e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
366e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
367e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
368e41f4b71Sopenharmony_ci| 2202004   | Try to share an unavailable iface.           |
369e41f4b71Sopenharmony_ci| 2202005   | WiFi sharing failed.                         |
370e41f4b71Sopenharmony_ci| 2202006   | Bluetooth sharing failed.                    |
371e41f4b71Sopenharmony_ci| 2202011   | Cannot get network sharing configuration.    |
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**Example**
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci```js
376e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
377e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
378e41f4b71Sopenharmony_ci
379e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
380e41f4b71Sopenharmony_cisharing
381e41f4b71Sopenharmony_ci  .stopSharing(SHARING_WIFI)
382e41f4b71Sopenharmony_ci  .then(() => {
383e41f4b71Sopenharmony_ci    console.log('stop wifi sharing successful');
384e41f4b71Sopenharmony_ci  })
385e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
386e41f4b71Sopenharmony_ci    console.log('stop wifi sharing failed');
387e41f4b71Sopenharmony_ci  });
388e41f4b71Sopenharmony_ci```
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci## sharing.getStatsRxBytes
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_cigetStatsRxBytes(callback: AsyncCallback\<number>): void
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic received via network sharing. This API uses an asynchronous callback to return the result.
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_ci**System API**: This is a system API.
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci**Parameters**
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                   |
405e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------------------- |
406e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the data volume, in KB.|
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci**Error codes**
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci| ID| Error Message                                    |
411e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
412e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
413e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
414e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
415e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
416e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci**Example**
419e41f4b71Sopenharmony_ci
420e41f4b71Sopenharmony_ci```js
421e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
422e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_cisharing.getStatsRxBytes((error: BusinessError, data: number) => {
425e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
426e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
427e41f4b71Sopenharmony_ci});
428e41f4b71Sopenharmony_ci```
429e41f4b71Sopenharmony_ci
430e41f4b71Sopenharmony_ci## sharing.getStatsRxBytes
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_cigetStatsRxBytes(): Promise\<number>
433e41f4b71Sopenharmony_ci
434e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic received via network sharing. This API uses a promise to return the result.
435e41f4b71Sopenharmony_ci
436e41f4b71Sopenharmony_ci**System API**: This is a system API.
437e41f4b71Sopenharmony_ci
438e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
439e41f4b71Sopenharmony_ci
440e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci**Return value**
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ci| Type            | Description                                             |
445e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------- |
446e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the data volume, in KB.|
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_ci**Error codes**
449e41f4b71Sopenharmony_ci
450e41f4b71Sopenharmony_ci| ID| Error Message                                    |
451e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
452e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
453e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
454e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
455e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
456e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci**Example**
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci```js
461e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
462e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_cisharing
465e41f4b71Sopenharmony_ci  .getStatsRxBytes()
466e41f4b71Sopenharmony_ci  .then((data: number) => {
467e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
468e41f4b71Sopenharmony_ci  })
469e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
470e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
471e41f4b71Sopenharmony_ci  });
472e41f4b71Sopenharmony_ci```
473e41f4b71Sopenharmony_ci
474e41f4b71Sopenharmony_ci## sharing.getStatsTxBytes
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_cigetStatsTxBytes(callback: AsyncCallback\<number>): void
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic sent via network sharing. This API uses an asynchronous callback to return the result.
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci**System API**: This is a system API.
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
485e41f4b71Sopenharmony_ci
486e41f4b71Sopenharmony_ci**Parameters**
487e41f4b71Sopenharmony_ci
488e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                   |
489e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------------------- |
490e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the data volume, in KB.|
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci**Error codes**
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci| ID| Error Message                                    |
495e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
496e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
497e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
498e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
499e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
500e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci**Example**
503e41f4b71Sopenharmony_ci
504e41f4b71Sopenharmony_ci```js
505e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
506e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_cisharing.getStatsTxBytes((error: BusinessError, data: number) => {
509e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
510e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
511e41f4b71Sopenharmony_ci});
512e41f4b71Sopenharmony_ci```
513e41f4b71Sopenharmony_ci
514e41f4b71Sopenharmony_ci## sharing.getStatsTxBytes
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_cigetStatsTxBytes(): Promise\<number>
517e41f4b71Sopenharmony_ci
518e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic sent via network sharing. This API uses a promise to return the result.
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci**System API**: This is a system API.
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci**Return value**
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci| Type            | Description                                             |
529e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------- |
530e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the data volume, in KB.|
531e41f4b71Sopenharmony_ci
532e41f4b71Sopenharmony_ci**Error codes**
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci| ID| Error Message                                    |
535e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
536e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
537e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
538e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
539e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
540e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci**Example**
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci```js
545e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
546e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_cisharing
549e41f4b71Sopenharmony_ci  .getStatsTxBytes()
550e41f4b71Sopenharmony_ci  .then((data: number) => {
551e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
552e41f4b71Sopenharmony_ci  })
553e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
554e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
555e41f4b71Sopenharmony_ci  });
556e41f4b71Sopenharmony_ci```
557e41f4b71Sopenharmony_ci
558e41f4b71Sopenharmony_ci## sharing.getStatsTotalBytes
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_cigetStatsTotalBytes(callback: AsyncCallback\<number>): void
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic sent and received via network sharing. This API uses an asynchronous callback to return the result.
563e41f4b71Sopenharmony_ci
564e41f4b71Sopenharmony_ci**System API**: This is a system API.
565e41f4b71Sopenharmony_ci
566e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci**Parameters**
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_ci| Name  | Type                  | Mandatory| Description                                   |
573e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | --------------------------------------- |
574e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number> | Yes  | Callback used to return the data volume, in KB.|
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci**Error codes**
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci| ID| Error Message                                    |
579e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
580e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
581e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
582e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
583e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
584e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci**Example**
587e41f4b71Sopenharmony_ci
588e41f4b71Sopenharmony_ci```js
589e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
590e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
591e41f4b71Sopenharmony_ci
592e41f4b71Sopenharmony_cisharing.getStatsTotalBytes((error: BusinessError, data: number) => {
593e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
594e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
595e41f4b71Sopenharmony_ci});
596e41f4b71Sopenharmony_ci```
597e41f4b71Sopenharmony_ci
598e41f4b71Sopenharmony_ci## sharing.getStatsTotalBytes
599e41f4b71Sopenharmony_ci
600e41f4b71Sopenharmony_cigetStatsTotalBytes(): Promise\<number>
601e41f4b71Sopenharmony_ci
602e41f4b71Sopenharmony_ciObtains the volume of mobile data traffic sent and received via network sharing. This API uses a promise to return the result.
603e41f4b71Sopenharmony_ci
604e41f4b71Sopenharmony_ci**System API**: This is a system API.
605e41f4b71Sopenharmony_ci
606e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
607e41f4b71Sopenharmony_ci
608e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
609e41f4b71Sopenharmony_ci
610e41f4b71Sopenharmony_ci**Return value**
611e41f4b71Sopenharmony_ci
612e41f4b71Sopenharmony_ci| Type            | Description                                           |
613e41f4b71Sopenharmony_ci| ---------------- | ----------------------------------------------- |
614e41f4b71Sopenharmony_ci| Promise\<number> | Promise used to return the data volume, in KB.|
615e41f4b71Sopenharmony_ci
616e41f4b71Sopenharmony_ci**Error codes**
617e41f4b71Sopenharmony_ci
618e41f4b71Sopenharmony_ci| ID| Error Message                                    |
619e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
620e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
621e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
622e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
623e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
624e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ci**Example**
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci```js
629e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
630e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_cisharing
633e41f4b71Sopenharmony_ci  .getStatsTotalBytes()
634e41f4b71Sopenharmony_ci  .then((data: number) => {
635e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
636e41f4b71Sopenharmony_ci  })
637e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
638e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
639e41f4b71Sopenharmony_ci  });
640e41f4b71Sopenharmony_ci```
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci## sharing.getSharingIfaces
643e41f4b71Sopenharmony_ci
644e41f4b71Sopenharmony_cigetSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\<Array\<string>>): void
645e41f4b71Sopenharmony_ci
646e41f4b71Sopenharmony_ciObtains the names of NICs in the specified network sharing state. This API uses an asynchronous callback to return the result.
647e41f4b71Sopenharmony_ci
648e41f4b71Sopenharmony_ci**System API**: This is a system API.
649e41f4b71Sopenharmony_ci
650e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
651e41f4b71Sopenharmony_ci
652e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
653e41f4b71Sopenharmony_ci
654e41f4b71Sopenharmony_ci**Parameters**
655e41f4b71Sopenharmony_ci
656e41f4b71Sopenharmony_ci| Name  | Type                                   | Mandatory| Description                                  |
657e41f4b71Sopenharmony_ci| -------- | --------------------------------------- | ---- | -------------------------------------- |
658e41f4b71Sopenharmony_ci| state    | [SharingIfaceState](#sharingifacestate) | Yes  | Network sharing state.                        |
659e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<string>>          | Yes  | Callback used to return an array of NIC names.|
660e41f4b71Sopenharmony_ci
661e41f4b71Sopenharmony_ci**Error codes**
662e41f4b71Sopenharmony_ci
663e41f4b71Sopenharmony_ci| ID| Error Message                                    |
664e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
665e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
666e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
667e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
668e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
669e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
670e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ci**Example**
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci```js
675e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
676e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
677e41f4b71Sopenharmony_ci
678e41f4b71Sopenharmony_cilet SHARING_BLUETOOTH = 2;
679e41f4b71Sopenharmony_cisharing.getSharingIfaces(SHARING_BLUETOOTH, (error: BusinessError, data: string[]) => {
680e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
681e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
682e41f4b71Sopenharmony_ci});
683e41f4b71Sopenharmony_ci```
684e41f4b71Sopenharmony_ci
685e41f4b71Sopenharmony_ci## sharing.getSharingIfaces
686e41f4b71Sopenharmony_ci
687e41f4b71Sopenharmony_cigetSharingIfaces(state: SharingIfaceState): Promise\<Array\<string>>
688e41f4b71Sopenharmony_ci
689e41f4b71Sopenharmony_ciObtains the names of NICs in the specified network sharing state. This API uses a promise to return the result.
690e41f4b71Sopenharmony_ci
691e41f4b71Sopenharmony_ci**System API**: This is a system API.
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
694e41f4b71Sopenharmony_ci
695e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
696e41f4b71Sopenharmony_ci
697e41f4b71Sopenharmony_ci**Parameters**
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci| Name| Type                                   | Mandatory| Description          |
700e41f4b71Sopenharmony_ci| ------ | --------------------------------------- | ---- | -------------- |
701e41f4b71Sopenharmony_ci| state  | [SharingIfaceState](#sharingifacestate) | Yes  | Network sharing state.|
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**Return value**
704e41f4b71Sopenharmony_ci
705e41f4b71Sopenharmony_ci| Type                    | Description                                     |
706e41f4b71Sopenharmony_ci| ------------------------ | ----------------------------------------- |
707e41f4b71Sopenharmony_ci| Promise\<Array\<string>> | Promise used to return an array of NIC names.|
708e41f4b71Sopenharmony_ci
709e41f4b71Sopenharmony_ci**Error codes**
710e41f4b71Sopenharmony_ci
711e41f4b71Sopenharmony_ci| ID| Error Message                                    |
712e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
713e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
714e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
715e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
716e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
717e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
718e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci**Example**
721e41f4b71Sopenharmony_ci
722e41f4b71Sopenharmony_ci```js
723e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
724e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_cilet SHARING_BLUETOOTH = 2;
727e41f4b71Sopenharmony_cisharing
728e41f4b71Sopenharmony_ci  .getSharingIfaces(SHARING_BLUETOOTH)
729e41f4b71Sopenharmony_ci  .then((data: string[]) => {
730e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
731e41f4b71Sopenharmony_ci  })
732e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
733e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
734e41f4b71Sopenharmony_ci  });
735e41f4b71Sopenharmony_ci```
736e41f4b71Sopenharmony_ci
737e41f4b71Sopenharmony_ci## sharing.getSharingState
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_cigetSharingState(type: SharingIfaceType, callback: AsyncCallback\<SharingIfaceState\>): void
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ciObtains the network sharing state of the specified type. This API uses an asynchronous callback to return the result.
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci**System API**: This is a system API.
744e41f4b71Sopenharmony_ci
745e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
746e41f4b71Sopenharmony_ci
747e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
748e41f4b71Sopenharmony_ci
749e41f4b71Sopenharmony_ci**Parameters**
750e41f4b71Sopenharmony_ci
751e41f4b71Sopenharmony_ci| Name  | Type                                                   | Mandatory| Description                                    |
752e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------- | ---- | ---------------------------------------- |
753e41f4b71Sopenharmony_ci| type     | [SharingIfaceType](#sharingifacetype)                   | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
754e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[SharingIfaceState](#sharingifacestate)> | Yes  | Callback used to return the network sharing state.    |
755e41f4b71Sopenharmony_ci
756e41f4b71Sopenharmony_ci**Error codes**
757e41f4b71Sopenharmony_ci
758e41f4b71Sopenharmony_ci| ID| Error Message                                    |
759e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
760e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
761e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
762e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
763e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
764e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
765e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci**Example**
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_ci```js
770e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
771e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
774e41f4b71Sopenharmony_cisharing.getSharingState(SHARING_WIFI, (error: BusinessError, data: sharing.SharingIfaceState) => {
775e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
776e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
777e41f4b71Sopenharmony_ci});
778e41f4b71Sopenharmony_ci```
779e41f4b71Sopenharmony_ci
780e41f4b71Sopenharmony_ci## sharing.getSharingState
781e41f4b71Sopenharmony_ci
782e41f4b71Sopenharmony_cigetSharingState(type: SharingIfaceType): Promise\<SharingIfaceState\>
783e41f4b71Sopenharmony_ci
784e41f4b71Sopenharmony_ciObtains the network sharing state of the specified type. This API uses a promise to return the result.
785e41f4b71Sopenharmony_ci
786e41f4b71Sopenharmony_ci**System API**: This is a system API.
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
789e41f4b71Sopenharmony_ci
790e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
791e41f4b71Sopenharmony_ci
792e41f4b71Sopenharmony_ci**Parameters**
793e41f4b71Sopenharmony_ci
794e41f4b71Sopenharmony_ci| Name| Type                                 | Mandatory| Description                                    |
795e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | ---------------------------------------- |
796e41f4b71Sopenharmony_ci| type   | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
797e41f4b71Sopenharmony_ci
798e41f4b71Sopenharmony_ci**Error codes**
799e41f4b71Sopenharmony_ci
800e41f4b71Sopenharmony_ci| ID| Error Message                                    |
801e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
802e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
803e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
804e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
805e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
806e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
807e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
808e41f4b71Sopenharmony_ci
809e41f4b71Sopenharmony_ci**Return value**
810e41f4b71Sopenharmony_ci
811e41f4b71Sopenharmony_ci| Type                                             | Description                                     |
812e41f4b71Sopenharmony_ci| ------------------------------------------------- | ----------------------------------------- |
813e41f4b71Sopenharmony_ci| Promise\<[SharingIfaceState](#sharingifacestate)> | Promise used to return the network sharing state.|
814e41f4b71Sopenharmony_ci
815e41f4b71Sopenharmony_ci**Example**
816e41f4b71Sopenharmony_ci
817e41f4b71Sopenharmony_ci```js
818e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
819e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
820e41f4b71Sopenharmony_ci
821e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
822e41f4b71Sopenharmony_cisharing
823e41f4b71Sopenharmony_ci  .getSharingState(SHARING_WIFI)
824e41f4b71Sopenharmony_ci  .then((data: sharing.SharingIfaceState) => {
825e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
826e41f4b71Sopenharmony_ci  })
827e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
828e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
829e41f4b71Sopenharmony_ci  });
830e41f4b71Sopenharmony_ci```
831e41f4b71Sopenharmony_ci
832e41f4b71Sopenharmony_ci## sharing.getSharableRegexes
833e41f4b71Sopenharmony_ci
834e41f4b71Sopenharmony_cigetSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\<Array\<string\>\>): void
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ciObtains regular expressions of NICs of a specified type. This API uses an asynchronous callback to return the result.
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_ci**System API**: This is a system API.
839e41f4b71Sopenharmony_ci
840e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci**Parameters**
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_ci| Name  | Type                                 | Mandatory| Description                                          |
847e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ---------------------------------------------- |
848e41f4b71Sopenharmony_ci| type     | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.      |
849e41f4b71Sopenharmony_ci| callback | AsyncCallback\<Array\<string>>        | Yes  | Callback used to return an array of regular expressions.|
850e41f4b71Sopenharmony_ci
851e41f4b71Sopenharmony_ci**Error codes**
852e41f4b71Sopenharmony_ci
853e41f4b71Sopenharmony_ci| ID| Error Message                                    |
854e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
855e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
856e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
857e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
858e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
859e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
860e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**Example**
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci```js
865e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
866e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
869e41f4b71Sopenharmony_cisharing.getSharableRegexes(SHARING_WIFI, (error: BusinessError, data: string[]) => {
870e41f4b71Sopenharmony_ci  console.log(JSON.stringify(error));
871e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
872e41f4b71Sopenharmony_ci});
873e41f4b71Sopenharmony_ci```
874e41f4b71Sopenharmony_ci
875e41f4b71Sopenharmony_ci## sharing.getSharableRegexes
876e41f4b71Sopenharmony_ci
877e41f4b71Sopenharmony_cigetSharableRegexes(type: SharingIfaceType): Promise\<Array\<string>>
878e41f4b71Sopenharmony_ci
879e41f4b71Sopenharmony_ciObtains regular expressions of NICs of a specified type. This API uses a promise to return the result.
880e41f4b71Sopenharmony_ci
881e41f4b71Sopenharmony_ci**System API**: This is a system API.
882e41f4b71Sopenharmony_ci
883e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
884e41f4b71Sopenharmony_ci
885e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
886e41f4b71Sopenharmony_ci
887e41f4b71Sopenharmony_ci**Parameters**
888e41f4b71Sopenharmony_ci
889e41f4b71Sopenharmony_ci| Name| Type                                 | Mandatory| Description                                    |
890e41f4b71Sopenharmony_ci| ------ | ------------------------------------- | ---- | ---------------------------------------- |
891e41f4b71Sopenharmony_ci| type   | [SharingIfaceType](#sharingifacetype) | Yes  | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci**Return value**
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_ci| Type                    | Description                               |
896e41f4b71Sopenharmony_ci| ------------------------ | ----------------------------------- |
897e41f4b71Sopenharmony_ci| Promise\<Array\<string>> | Promise used to return an array of regular expressions.|
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci**Error codes**
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_ci| ID| Error Message                                    |
902e41f4b71Sopenharmony_ci| --------- | -------------------------------------------- |
903e41f4b71Sopenharmony_ci| 201       | Permission denied.                           |
904e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs.     |
905e41f4b71Sopenharmony_ci| 401       | Parameter error.                             |
906e41f4b71Sopenharmony_ci| 2200001   | Invalid parameter value.                     |
907e41f4b71Sopenharmony_ci| 2200002   | Failed to connect to the service.            |
908e41f4b71Sopenharmony_ci| 2200003   | System internal error.                       |
909e41f4b71Sopenharmony_ci
910e41f4b71Sopenharmony_ci**Example**
911e41f4b71Sopenharmony_ci
912e41f4b71Sopenharmony_ci```js
913e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
914e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
915e41f4b71Sopenharmony_ci
916e41f4b71Sopenharmony_cilet SHARING_WIFI = 0;
917e41f4b71Sopenharmony_cisharing
918e41f4b71Sopenharmony_ci  .getSharableRegexes(SHARING_WIFI)
919e41f4b71Sopenharmony_ci  .then((data: string[]) => {
920e41f4b71Sopenharmony_ci    console.log(JSON.stringify(data));
921e41f4b71Sopenharmony_ci  })
922e41f4b71Sopenharmony_ci  .catch((error: BusinessError) => {
923e41f4b71Sopenharmony_ci    console.log(JSON.stringify(error));
924e41f4b71Sopenharmony_ci  });
925e41f4b71Sopenharmony_ci```
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_ci## sharing.on('sharingStateChange')
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_cion(type: 'sharingStateChange', callback: Callback\<boolean>): void
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ciSubscribes to network sharing state changes. This API uses an asynchronous callback to return the result.
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**System API**: This is a system API.
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
938e41f4b71Sopenharmony_ci
939e41f4b71Sopenharmony_ci**Parameters**
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                        |
942e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ---------------------------- |
943e41f4b71Sopenharmony_ci| type     | string                  | Yes  | Event name.                  |
944e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | Yes  | Callback invoked when the network sharing state changes.|
945e41f4b71Sopenharmony_ci
946e41f4b71Sopenharmony_ci**Error codes**
947e41f4b71Sopenharmony_ci
948e41f4b71Sopenharmony_ci| ID| Error Message                                |
949e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
950e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
951e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
952e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
953e41f4b71Sopenharmony_ci
954e41f4b71Sopenharmony_ci**Example**
955e41f4b71Sopenharmony_ci
956e41f4b71Sopenharmony_ci```js
957e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
958e41f4b71Sopenharmony_ci
959e41f4b71Sopenharmony_cisharing.on('sharingStateChange', (data: boolean) => {
960e41f4b71Sopenharmony_ci  console.log('on sharingStateChange: ' + JSON.stringify(data));
961e41f4b71Sopenharmony_ci});
962e41f4b71Sopenharmony_ci```
963e41f4b71Sopenharmony_ci
964e41f4b71Sopenharmony_ci## sharing.off('sharingStateChange')
965e41f4b71Sopenharmony_ci
966e41f4b71Sopenharmony_cioff(type: 'sharingStateChange', callback?: Callback\<boolean>): void
967e41f4b71Sopenharmony_ci
968e41f4b71Sopenharmony_ciUnsubscribes from network sharing state changes. This API uses an asynchronous callback to return the result.
969e41f4b71Sopenharmony_ci
970e41f4b71Sopenharmony_ci**System API**: This is a system API.
971e41f4b71Sopenharmony_ci
972e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
973e41f4b71Sopenharmony_ci
974e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
975e41f4b71Sopenharmony_ci
976e41f4b71Sopenharmony_ci**Parameters**
977e41f4b71Sopenharmony_ci
978e41f4b71Sopenharmony_ci| Name  | Type                   | Mandatory| Description                        |
979e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ---------------------------- |
980e41f4b71Sopenharmony_ci| type     | string                  | Yes  | Event name.                  |
981e41f4b71Sopenharmony_ci| callback | AsyncCallback\<boolean> | No  | Callback invoked when the network sharing state changes.|
982e41f4b71Sopenharmony_ci
983e41f4b71Sopenharmony_ci**Error codes**
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_ci| ID| Error Message                                |
986e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
987e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
988e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
989e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
990e41f4b71Sopenharmony_ci
991e41f4b71Sopenharmony_ci**Example**
992e41f4b71Sopenharmony_ci
993e41f4b71Sopenharmony_ci```js
994e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
995e41f4b71Sopenharmony_ci
996e41f4b71Sopenharmony_cisharing.off('sharingStateChange', (data: boolean) => {
997e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
998e41f4b71Sopenharmony_ci});
999e41f4b71Sopenharmony_ci```
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci## sharing.on('interfaceSharingStateChange')
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_cion(type: 'interfaceSharingStateChange', callback: Callback\<InterfaceSharingStateInfo\>): void
1004e41f4b71Sopenharmony_ci
1005e41f4b71Sopenharmony_ciSubscribes to network sharing state changes of a specified NIC. This API uses an asynchronous callback to return the result.
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ci**System API**: This is a system API.
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci**Parameters**
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci| Name  | Type                                                                  | Mandatory| Description                                 |
1016e41f4b71Sopenharmony_ci| -------- | -------------------------------------------------------------------- | ---- | ------------------------------------- |
1017e41f4b71Sopenharmony_ci| type     | string                                                                | Yes  | Event name.                           |
1018e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[InterfaceSharingStateInfo](#interfacesharingstateinfo11)> | Yes  | Callback used to return the result. It is called when the network sharing state of a specified NIC changes.|
1019e41f4b71Sopenharmony_ci
1020e41f4b71Sopenharmony_ci**Error codes**
1021e41f4b71Sopenharmony_ci
1022e41f4b71Sopenharmony_ci| ID| Error Message                                |
1023e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
1024e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
1025e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
1026e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
1027e41f4b71Sopenharmony_ci
1028e41f4b71Sopenharmony_ci**Example**
1029e41f4b71Sopenharmony_ci
1030e41f4b71Sopenharmony_ci```js
1031e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
1032e41f4b71Sopenharmony_ci
1033e41f4b71Sopenharmony_cisharing.on('interfaceSharingStateChange', (data: object) => {
1034e41f4b71Sopenharmony_ci  console.log('on interfaceSharingStateChange:' + JSON.stringify(data));
1035e41f4b71Sopenharmony_ci});
1036e41f4b71Sopenharmony_ci```
1037e41f4b71Sopenharmony_ci
1038e41f4b71Sopenharmony_ci## sharing.off('interfaceSharingStateChange')
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_cioff(type: 'interfaceSharingStateChange', callback?: Callback\<InterfaceSharingStateInfo\>): void
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_ciUnsubscribes from network sharing status changes of a specified NIC. This API uses an asynchronous callback to return the result.
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ci**System API**: This is a system API.
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci**Parameters**
1051e41f4b71Sopenharmony_ci
1052e41f4b71Sopenharmony_ci| Name  | Type                                                                       | Mandatory| Description                                    |
1053e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------------------------- | ---- | ---------------------------------------- |
1054e41f4b71Sopenharmony_ci| type     | string                                                                     | Yes  | Event name.                              |
1055e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[InterfaceSharingStateInfo](#interfacesharingstateinfo11)> | No  | Callback used to return the result.|
1056e41f4b71Sopenharmony_ci
1057e41f4b71Sopenharmony_ci**Error codes**
1058e41f4b71Sopenharmony_ci
1059e41f4b71Sopenharmony_ci| ID| Error Message                                |
1060e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
1061e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
1062e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
1063e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
1064e41f4b71Sopenharmony_ci
1065e41f4b71Sopenharmony_ci**Example**
1066e41f4b71Sopenharmony_ci
1067e41f4b71Sopenharmony_ci```js
1068e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
1069e41f4b71Sopenharmony_ci
1070e41f4b71Sopenharmony_cisharing.off('interfaceSharingStateChange', (data: object) => {
1071e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
1072e41f4b71Sopenharmony_ci});
1073e41f4b71Sopenharmony_ci```
1074e41f4b71Sopenharmony_ci
1075e41f4b71Sopenharmony_ci## sharing.on('sharingUpstreamChange')
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_cion(type: 'sharingUpstreamChange', callback: Callback\<NetHandle>): void
1078e41f4b71Sopenharmony_ci
1079e41f4b71Sopenharmony_ciSubscribes to upstream network changes. This API uses an asynchronous callback to return the result.
1080e41f4b71Sopenharmony_ci
1081e41f4b71Sopenharmony_ci**System API**: This is a system API.
1082e41f4b71Sopenharmony_ci
1083e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1084e41f4b71Sopenharmony_ci
1085e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1086e41f4b71Sopenharmony_ci
1087e41f4b71Sopenharmony_ci**Parameters**
1088e41f4b71Sopenharmony_ci
1089e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                          |
1090e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ------------------------------ |
1091e41f4b71Sopenharmony_ci| type     | string                    | Yes  | Event name.                    |
1092e41f4b71Sopenharmony_ci| callback | AsyncCallback\<NetHandle> | Yes  | Callback invoked when the upstream network changes.|
1093e41f4b71Sopenharmony_ci
1094e41f4b71Sopenharmony_ci**Error codes**
1095e41f4b71Sopenharmony_ci
1096e41f4b71Sopenharmony_ci| ID| Error Message                                |
1097e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
1098e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
1099e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
1100e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
1101e41f4b71Sopenharmony_ci
1102e41f4b71Sopenharmony_ci**Example**
1103e41f4b71Sopenharmony_ci
1104e41f4b71Sopenharmony_ci```js
1105e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_cisharing.on('sharingUpstreamChange', (data: object) => {
1108e41f4b71Sopenharmony_ci  console.log('on sharingUpstreamChange:' + JSON.stringify(data));
1109e41f4b71Sopenharmony_ci});
1110e41f4b71Sopenharmony_ci```
1111e41f4b71Sopenharmony_ci
1112e41f4b71Sopenharmony_ci## sharing.off('sharingUpstreamChange')
1113e41f4b71Sopenharmony_ci
1114e41f4b71Sopenharmony_cioff(type: 'sharingUpstreamChange', callback?: Callback\<NetHandle>): void
1115e41f4b71Sopenharmony_ci
1116e41f4b71Sopenharmony_ciUnsubscribes from upstream network changes. This API uses an asynchronous callback to return the result.
1117e41f4b71Sopenharmony_ci
1118e41f4b71Sopenharmony_ci**System API**: This is a system API.
1119e41f4b71Sopenharmony_ci
1120e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
1121e41f4b71Sopenharmony_ci
1122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1123e41f4b71Sopenharmony_ci
1124e41f4b71Sopenharmony_ci**Parameters**
1125e41f4b71Sopenharmony_ci
1126e41f4b71Sopenharmony_ci| Name  | Type                     | Mandatory| Description                            |
1127e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | -------------------------------- |
1128e41f4b71Sopenharmony_ci| type     | string                    | Yes  | Event name.                      |
1129e41f4b71Sopenharmony_ci| callback | AsyncCallback\<NetHandle> | No  | Callback used for unsubscription from upstream network changes.|
1130e41f4b71Sopenharmony_ci
1131e41f4b71Sopenharmony_ci**Error codes**
1132e41f4b71Sopenharmony_ci
1133e41f4b71Sopenharmony_ci| ID| Error Message                                |
1134e41f4b71Sopenharmony_ci| --------- | ---------------------------------------- |
1135e41f4b71Sopenharmony_ci| 201       | Permission denied.                       |
1136e41f4b71Sopenharmony_ci| 202       | Non-system applications use system APIs. |
1137e41f4b71Sopenharmony_ci| 401       | Parameter error.                         |
1138e41f4b71Sopenharmony_ci
1139e41f4b71Sopenharmony_ci**Example**
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci```js
1142e41f4b71Sopenharmony_ciimport { sharing } from '@kit.NetworkKit';
1143e41f4b71Sopenharmony_ci
1144e41f4b71Sopenharmony_cisharing.off('sharingUpstreamChange', (data: object) => {
1145e41f4b71Sopenharmony_ci  console.log(JSON.stringify(data));
1146e41f4b71Sopenharmony_ci});
1147e41f4b71Sopenharmony_ci```
1148e41f4b71Sopenharmony_ci
1149e41f4b71Sopenharmony_ci## InterfaceSharingStateInfo<sup>11+</sup>
1150e41f4b71Sopenharmony_ci
1151e41f4b71Sopenharmony_ciWakes up the listener for network sharing state changes of an NIC.
1152e41f4b71Sopenharmony_ci
1153e41f4b71Sopenharmony_ci**System API**: This is a system API.
1154e41f4b71Sopenharmony_ci
1155e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1156e41f4b71Sopenharmony_ci
1157e41f4b71Sopenharmony_ci| Name    | Type                                             | Mandatory| Description                |
1158e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- | ---- | ------------------- |
1159e41f4b71Sopenharmony_ci| type     | [SharingIfaceType](#sharingifacetype)             | Yes  | Enumerates the network sharing types of an NIC.      |
1160e41f4b71Sopenharmony_ci| iface    | string                                            | Yes  | NIC name.|
1161e41f4b71Sopenharmony_ci| state    | [SharingIfaceState](#sharingifacestate)           | Yes  | Network sharing state of the NIC.      |
1162e41f4b71Sopenharmony_ci
1163e41f4b71Sopenharmony_ci## SharingIfaceState
1164e41f4b71Sopenharmony_ci
1165e41f4b71Sopenharmony_ciEnumerates the network sharing states of an NIC.
1166e41f4b71Sopenharmony_ci
1167e41f4b71Sopenharmony_ci**System API**: This is a system API.
1168e41f4b71Sopenharmony_ci
1169e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1170e41f4b71Sopenharmony_ci
1171e41f4b71Sopenharmony_ci| Name                  | Value | Description            |
1172e41f4b71Sopenharmony_ci| ---------------------- | --- | ---------------- |
1173e41f4b71Sopenharmony_ci| SHARING_NIC_SERVING    | 1   | Network sharing is in progress.  |
1174e41f4b71Sopenharmony_ci| SHARING_NIC_CAN_SERVER | 2   | Network sharing is supported.|
1175e41f4b71Sopenharmony_ci| SHARING_NIC_ERROR      | 3   | An error occurred during network sharing.  |
1176e41f4b71Sopenharmony_ci
1177e41f4b71Sopenharmony_ci## SharingIfaceType
1178e41f4b71Sopenharmony_ci
1179e41f4b71Sopenharmony_ciEnumerates the network sharing types of an NIC.
1180e41f4b71Sopenharmony_ci
1181e41f4b71Sopenharmony_ci**System API**: This is a system API.
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Communication.NetManager.NetSharing
1184e41f4b71Sopenharmony_ci
1185e41f4b71Sopenharmony_ci| Name             | Value | Description                |
1186e41f4b71Sopenharmony_ci| ----------------- | --- | -------------------- |
1187e41f4b71Sopenharmony_ci| SHARING_WIFI      | 0   | Wi-Fi hotspot sharing.|
1188e41f4b71Sopenharmony_ci| SHARING_USB       | 1   | USB sharing.  |
1189e41f4b71Sopenharmony_ci| SHARING_BLUETOOTH | 2   | Bluetooth sharing.  |
1190