1# @ohos.telephony.data (Cellular Data) (System API)
2
3The **data** module provides basic mobile data management functions. With the APIs provided by this module, you can set the default slot of the SIM card used for cellular data services and enable or disable cellular data services and data roaming.
4
5>**NOTE**
6>
7>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9>This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.telephony.data (Cellular Data)](js-apis-telephony-data.md).
10
11
12## Modules to Import
13
14```ts
15import { data } from '@kit.TelephonyKit';
16```
17
18
19## data.setDefaultCellularDataSlotId
20
21setDefaultCellularDataSlotId(slotId: number, callback: AsyncCallback\<void\>): void
22
23Sets the default slot of the SIM card used for mobile data. This API uses an asynchronous callback to return the result.
24
25**System API**: This is a system API.
26
27**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
28
29**System capability**: SystemCapability.Telephony.CellularData
30
31**Parameters**
32
33| Name  | Type                 | Mandatory| Description                                                        |
34| -------- | --------------------- | ---- | ------------------------------------------------------------ |
35| slotId   | number                | Yes  | SIM card slot ID. <br>- **0**: card slot 1.<br>- **1**: card slot 2.|
36| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                                                  |
37
38**Error codes**
39
40For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
41
42| ID|                 Error Message                    |
43| -------- | -------------------------------------------- |
44| 201      | Permission denied.                           |
45| 202      | Non-system applications use system APIs.     |
46| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
47| 8300001  | Invalid parameter value.                     |
48| 8300002  | Service connection failed.                   |
49| 8300003  | System internal error.                       |
50| 8300004  | No SIM card found.                           |
51| 8300999  | Unknown error.                               |
52| 8301001  | SIM card is not activated.                   |
53
54**Example**
55
56```ts
57import { data } from '@kit.TelephonyKit';
58import { BusinessError } from '@kit.BasicServicesKit';
59
60data.setDefaultCellularDataSlotId(0, (err: BusinessError) => {
61    if(err){
62        console.error(`setDefaultCellularDataSlotId fail,callback: err->${JSON.stringify(err)}.`);
63    }else{
64        console.log(`setDefaultCellularDataSlotId success`);
65    }
66});
67```
68
69## data.setDefaultCellularDataSlotId
70
71setDefaultCellularDataSlotId(slotId: number): Promise\<void\>
72
73Sets the default slot of the SIM card used for mobile data. This API uses a promise to return the result.
74
75**System API**: This is a system API.
76
77**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
78
79**System capability**: SystemCapability.Telephony.CellularData
80
81**Parameters**
82
83| Name| Type  | Mandatory| Description                                                        |
84| ------ | ------ | ---- | ------------------------------------------------------------ |
85| slotId | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1.<br>- **1**: card slot 2.|
86
87**Return value**
88
89| Type           | Description                           |
90| --------------- | ------------------------------- |
91| Promise\<void\> | Promise used to return the result.|
92
93**Error codes**
94
95For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
96
97| ID|                 Error Message                    |
98| -------- | -------------------------------------------- |
99| 201      | Permission denied.                           |
100| 202      | Non-system applications use system APIs.     |
101| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
102| 8300001  | Invalid parameter value.                     |
103| 8300002  | Service connection failed.                   |
104| 8300003  | System internal error.                       |
105| 8300004  | No SIM card found.                           |
106| 8300999  | Unknown error.                               |
107| 8301001  | SIM card is not activated.                   |
108
109**Example**
110
111```ts
112import { data } from '@kit.TelephonyKit';
113import { BusinessError } from '@kit.BasicServicesKit';
114
115data.setDefaultCellularDataSlotId(0).then(() => {
116    console.log(`setDefaultCellularDataSlotId success.`);
117}).catch((err: BusinessError) => {
118    console.error(`setDefaultCellularDataSlotId fail, promise: err->${JSON.stringify(err)}`);
119});
120```
121
122
123## data.enableCellularData
124
125enableCellularData(callback: AsyncCallback\<void\>): void
126
127Enables the cellular data service. This API uses an asynchronous callback to return the result.
128
129**System API**: This is a system API.
130
131**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
132
133**System capability**: SystemCapability.Telephony.CellularData
134
135**Parameters**
136
137| Name  | Type                 | Mandatory| Description      |
138| -------- | --------------------- | ---- | ---------- |
139| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
140
141**Error codes**
142
143For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
144
145| ID|                  Error Message                   |
146| -------- | -------------------------------------------- |
147| 201      | Permission denied.                           |
148| 202      | Non-system applications use system APIs.     |
149| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
150| 8300001  | Invalid parameter value.                     |
151| 8300002  | Service connection failed.                   |
152| 8300003  | System internal error.                       |
153| 8300999  | Unknown error.                               |
154
155**Example**
156
157```ts
158import { data } from '@kit.TelephonyKit';
159import { BusinessError } from '@kit.BasicServicesKit';
160
161data.enableCellularData((err: BusinessError) => {
162    if(err){
163        console.error(`enableCellularData fail,callback: callback: err->${JSON.stringify(err)}`);
164    }else{
165        console.log(`enableCellularData success`);
166    }
167});
168```
169
170## data.enableCellularData
171
172enableCellularData(): Promise\<void\>
173
174Enables the cellular data service. This API uses a promise to return the result.
175
176**System API**: This is a system API.
177
178**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
179
180**System capability**: SystemCapability.Telephony.CellularData
181
182**Return value**
183
184| Type           | Description                   |
185| --------------- | ----------------------- |
186| Promise\<void\> | Promise used to return the result.|
187
188**Error codes**
189
190For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
191
192| ID|                  Error Message                   |
193| -------- | -------------------------------------------- |
194| 201      | Permission denied.                           |
195| 202      | Non-system applications use system APIs.     |
196| 8300002  | Service connection failed.                   |
197| 8300003  | System internal error.                       |
198| 8300999  | Unknown error.                               |
199
200**Example**
201
202```ts
203import { data } from '@kit.TelephonyKit';
204import { BusinessError } from '@kit.BasicServicesKit';
205
206data.enableCellularData().then(() => {
207    console.log(`enableCellularData success.`);
208}).catch((err: BusinessError) => {
209    console.error(`enableCellularData fail, promise: err->${JSON.stringify(err)}`);
210});
211```
212
213## data.disableCellularData
214
215disableCellularData(callback: AsyncCallback\<void\>): void
216
217Disables the cellular data service. This API uses an asynchronous callback to return the result.
218
219**System API**: This is a system API.
220
221**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
222
223**System capability**: SystemCapability.Telephony.CellularData
224
225**Parameters**
226
227| Name  | Type                 | Mandatory| Description      |
228| -------- | --------------------- | ---- | ---------- |
229| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|
230
231**Error codes**
232
233For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
234
235| ID|                  Error Message                   |
236| -------- | -------------------------------------------- |
237| 201      | Permission denied.                           |
238| 202      | Non-system applications use system APIs.     |
239| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
240| 8300001  | Invalid parameter value.                     |
241| 8300002  | Service connection failed.                   |
242| 8300003  | System internal error.                       |
243| 8300999  | Unknown error.                               |
244
245**Example**
246
247```ts
248import { data } from '@kit.TelephonyKit';
249import { BusinessError } from '@kit.BasicServicesKit';
250
251data.disableCellularData((err: BusinessError) => {
252    if(err){
253        console.error(`disableCellularData fail,callback: callback: err->${JSON.stringify(err)}`);
254    }else{
255        console.log(`disableCellularData success`);
256    }
257});
258```
259
260## data.disableCellularData
261
262disableCellularData(): Promise\<void\>
263
264Disables the cellular data service. This API uses a promise to return the result.
265
266**System API**: This is a system API.
267
268**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
269
270**System capability**: SystemCapability.Telephony.CellularData
271
272**Return value**
273
274| Type           | Description                       |
275| --------------- | --------------------------- |
276| Promise\<void\> | Promise used to return the result.|
277
278**Error codes**
279
280For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
281
282| ID|                  Error Message                   |
283| -------- | -------------------------------------------- |
284| 201      | Permission denied.                           |
285| 202      | Non-system applications use system APIs.     |
286| 8300002  | Service connection failed.                   |
287| 8300003  | System internal error.                       |
288| 8300999  | Unknown error.                               |
289
290**Example**
291
292```ts
293import { data } from '@kit.TelephonyKit';
294import { BusinessError } from '@kit.BasicServicesKit';
295
296data.disableCellularData().then(() => {
297    console.log(`disableCellularData success.`);
298}).catch((err: BusinessError) => {
299    console.error(`disableCellularData fail, promise: err->${JSON.stringify(err)}`);
300});
301```
302
303## data.enableCellularDataRoaming
304
305enableCellularDataRoaming(slotId: number, callback: AsyncCallback\<void\>): void
306
307Enables the cellular data roaming service. This API uses an asynchronous callback to return the result.
308
309**System API**: This is a system API.
310
311**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
312
313**System capability**: SystemCapability.Telephony.CellularData
314
315**Parameters**
316
317| Name  | Type                 | Mandatory| Description                                    |
318| -------- | --------------------- | ---- | ---------------------------------------- |
319| slotId   | number                | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
320| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                              |
321
322**Error codes**
323
324For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
325
326| ID|                  Error Message                   |
327| -------- | -------------------------------------------- |
328| 201      | Permission denied.                           |
329| 202      | Non-system applications use system APIs.     |
330| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
331| 8300001  | Invalid parameter value.                     |
332| 8300002  | Service connection failed.                   |
333| 8300003  | System internal error.                       |
334| 8300999  | Unknown error.                               |
335
336**Example**
337
338```ts
339import { data } from '@kit.TelephonyKit';
340import { BusinessError } from '@kit.BasicServicesKit';
341
342data.enableCellularDataRoaming(0, (err: BusinessError) => {
343    if(err){
344        console.error(`enableCellularDataRoaming fail,callback: err->${JSON.stringify(err)}`);
345    }else{
346        console.log(`enableCellularDataRoaming success`);
347    }
348});
349```
350
351## data.enableCellularDataRoaming
352
353enableCellularDataRoaming(slotId: number): Promise\<void\>
354
355Enables the cellular data roaming service. This API uses a promise to return the result.
356
357**System API**: This is a system API.
358
359**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
360
361**System capability**: SystemCapability.Telephony.CellularData
362
363**Parameters**
364
365| Name| Type  | Mandatory| Description                                    |
366| ------ | ------ | ---- | ---------------------------------------- |
367| slotId | number | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
368
369**Return value**
370
371| Type           | Description                     |
372| --------------- | ------------------------- |
373| Promise\<void\> | Promise used to return the result.|
374
375**Error codes**
376
377For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
378
379| ID|                  Error Message                   |
380| -------- | -------------------------------------------- |
381| 201      | Permission denied.                           |
382| 202      | Non-system applications use system APIs.     |
383| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
384| 8300001  | Invalid parameter value.                     |
385| 8300002  | Service connection failed.                   |
386| 8300003  | System internal error.                       |
387| 8300999  | Unknown error.                               |
388
389**Example**
390
391```ts
392import { data } from '@kit.TelephonyKit';
393import { BusinessError } from '@kit.BasicServicesKit';
394
395data.enableCellularDataRoaming(0).then(() => {
396    console.log(`enableCellularDataRoaming success.`);
397}).catch((err: BusinessError) => {
398    console.error(`enableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`);
399});
400```
401
402## data.disableCellularDataRoaming
403
404disableCellularDataRoaming(slotId: number, callback: AsyncCallback\<void\>): void
405
406Disables the cellular data roaming service. This API uses an asynchronous callback to return the result.
407
408**System API**: This is a system API.
409
410**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
411
412**System capability**: SystemCapability.Telephony.CellularData
413
414**Parameters**
415
416| Name  | Type                 | Mandatory| Description                                    |
417| -------- | --------------------- | ---- | ---------------------------------------- |
418| slotId   | number                | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
419| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                              |
420
421**Error codes**
422
423For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
424
425| ID|                  Error Message                   |
426| -------- | -------------------------------------------- |
427| 201      | Permission denied.                           |
428| 202      | Non-system applications use system APIs.     |
429| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
430| 8300001  | Invalid parameter value.                     |
431| 8300002  | Service connection failed.                   |
432| 8300003  | System internal error.                       |
433| 8300999  | Unknown error.                               |
434
435**Example**
436
437```ts
438import { data } from '@kit.TelephonyKit';
439import { BusinessError } from '@kit.BasicServicesKit';
440
441data.disableCellularDataRoaming(0, (err: BusinessError) => {
442    if(err){
443        console.error(`disableCellularDataRoaming fail,callback: err->${JSON.stringify(err)}`);
444    }else{
445        console.log(`disableCellularDataRoaming success`);
446    }
447});
448```
449
450## data.disableCellularDataRoaming
451
452disableCellularDataRoaming(slotId: number): Promise\<void\>
453
454Disables the cellular data roaming service. This API uses a promise to return the result.
455
456**System API**: This is a system API.
457
458**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
459
460**System capability**: SystemCapability.Telephony.CellularData
461
462**Parameters**
463
464| Name| Type  | Mandatory| Description                                    |
465| ------ | ------ | ---- | ---------------------------------------- |
466| slotId | number | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
467
468**Return value**
469
470| Type           | Description                     |
471| --------------- | ------------------------- |
472| Promise\<void\> | Promise used to return the result.|
473
474**Error codes**
475
476For details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
477
478| ID|                  Error Message                   |
479| -------- | -------------------------------------------- |
480| 201      | Permission denied.                           |
481| 202      | Non-system applications use system APIs.     |
482| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
483| 8300001  | Invalid parameter value.                     |
484| 8300002  | Service connection failed.                   |
485| 8300003  | System internal error.                       |
486| 8300999  | Unknown error.                               |
487
488**Example**
489
490```ts
491import { data } from '@kit.TelephonyKit';
492import { BusinessError } from '@kit.BasicServicesKit';
493
494data.disableCellularDataRoaming(0).then(() => {
495    console.log(`disableCellularDataRoaming success.`);
496}).catch((err: BusinessError) => {
497    console.error(`disableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`);
498});
499```
500