js-apis-telephony-data.md 29.0 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.telephony.data (Cellular Data)
S
shawn_he 已提交
2

S
shawn_he 已提交
3
The **data** module provides basic mobile data management functions. You can obtain and set the default slot of the SIM card used for mobile data, and obtain the uplink and downlink connection status of cellular data services and connection status of the packet switched (PS) domain. Besides, you can check whether cellular data services and data roaming are enabled.
S
shawn_he 已提交
4

S
shawn_he 已提交
5 6 7 8 9 10
>**NOTE**
>
>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.

## Modules to Import

S
shawn_he 已提交
11
```js
S
shawn_he 已提交
12 13 14
import data from '@ohos.telephony.data';
```

S
shawn_he 已提交
15
## data.getDefaultCellularDataSlotId
S
shawn_he 已提交
16 17 18

getDefaultCellularDataSlotId(callback: AsyncCallback\<number\>): void 

S
shawn_he 已提交
19
Obtains the default slot of the SIM card used for mobile data. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
20 21 22 23 24

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
25
| Name  | Type                   | Mandatory| Description                                      |
S
shawn_he 已提交
26
| -------- | ----------------------- | ---- | ------------------------------------------ |
S
shawn_he 已提交
27
| callback | AsyncCallback\<number\> | Yes  | Callback used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
28 29 30

**Example**

S
shawn_he 已提交
31
```js
S
shawn_he 已提交
32 33 34 35 36
data.getDefaultCellularDataSlotId((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

S
shawn_he 已提交
37
## data.getDefaultCellularDataSlotId
S
shawn_he 已提交
38 39 40

getDefaultCellularDataSlotId(): Promise\<number\> 

S
shawn_he 已提交
41
Obtains the default slot of the SIM card used for mobile data. This API uses a promise to return the result. 
S
shawn_he 已提交
42 43 44

**System capability**: SystemCapability.Telephony.CellularData

S
shawn_he 已提交
45
**Return value**
S
shawn_he 已提交
46

S
shawn_he 已提交
47
| Type             | Description                                                        |
S
shawn_he 已提交
48
| ----------------- | ------------------------------------------------------------ |
S
shawn_he 已提交
49
| Promise\<number\> | Promise used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
50 51 52

**Example**

S
shawn_he 已提交
53
```js
S
shawn_he 已提交
54 55
let promise = data.getDefaultCellularDataSlotId();
promise.then((data) => {
S
shawn_he 已提交
56
    console.log(`getDefaultCellularDataSlotId success, promise: data->${JSON.stringify(data)}`);
S
shawn_he 已提交
57
}).catch((err) => {
S
shawn_he 已提交
58 59 60 61
    console.error(`getDefaultCellularDataSlotId fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
62
## data.getDefaultCellularDataSlotIdSync<sup>9+</sup>
S
shawn_he 已提交
63 64 65 66 67 68 69 70 71 72 73

getDefaultCellularDataSlotIdSync(): number

Obtains the default SIM card used for mobile data synchronously.

**System capability**: SystemCapability.Telephony.CellularData

**Return value**

| Type             | Description                                                        |
| ------ | -------------------------------------------------- |
S
shawn_he 已提交
74
| number | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
75 76 77 78 79 80 81

**Example**

```js
console.log("Result: "+ data.getDefaultCellularDataSlotIdSync())
```

S
shawn_he 已提交
82 83
## data.setDefaultCellularDataSlotId

S
shawn_he 已提交
84
setDefaultCellularDataSlotId(slotId: number, callback: AsyncCallback\<void\>): void 
S
shawn_he 已提交
85 86 87

Sets the default slot of the SIM card used for mobile data. This API uses an asynchronous callback to return the result. 

S
shawn_he 已提交
88
**System API**: This is a system API.
S
shawn_he 已提交
89

S
shawn_he 已提交
90
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
91 92 93 94 95 96 97

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name  | Type                 | Mandatory| Description                                                        |
| -------- | --------------------- | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
98
| slotId   | number                | Yes  | SIM card slot ID. <br>**0**: card slot 1.<br>**1**: card slot 2.<br>**-1**: Clears the default configuration.|
S
shawn_he 已提交
99
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                                                  |
S
shawn_he 已提交
100

S
shawn_he 已提交
101 102
**Error codes**

S
shawn_he 已提交
103 104
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
105 106 107 108 109 110 111 112 113 114 115
| ID|                 Error Message                    |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300004  | Do not have sim card.                        |
| 8300999  | Unknown error code.                          |
| 8301001  | SIM card is not activated.                   |

S
shawn_he 已提交
116 117 118
**Example**

```js
S
shawn_he 已提交
119 120
data.setDefaultCellularDataSlotId(0, (err) => {
    console.log(`callback: err->${JSON.stringify(err)}.`);
S
shawn_he 已提交
121 122 123 124 125 126 127 128 129
});
```

## data.setDefaultCellularDataSlotId

setDefaultCellularDataSlotId(slotId: number): Promise\<void\> 

Sets the default slot of the SIM card used for mobile data. This API uses a promise to return the result. 

S
shawn_he 已提交
130
**System API**: This is a system API.
S
shawn_he 已提交
131

S
shawn_he 已提交
132
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
133 134 135 136 137 138 139

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name| Type  | Mandatory| Description                                                        |
| ------ | ------ | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
140
| slotId | number | Yes  | SIM card slot ID. <br>**0**: card slot 1.<br>**1**: card slot 2.<br>**-1**: Clears the default configuration.|
S
shawn_he 已提交
141 142 143

**Return value**

S
shawn_he 已提交
144 145 146
| Type           | Description                           |
| --------------- | ------------------------------- |
| Promise\<void\> | Promise used to return the result.|
S
shawn_he 已提交
147

S
shawn_he 已提交
148 149
**Error codes**

S
shawn_he 已提交
150 151
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
152 153 154 155 156 157 158 159 160 161 162
| ID|                 Error Message                    |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300004  | Do not have sim card.                        |
| 8300999  | Unknown error code.                          |
| 8301001  | SIM card is not activated.                   |

S
shawn_he 已提交
163 164 165 166
**Example**

```js
let promise = data.setDefaultCellularDataSlotId(0);
S
shawn_he 已提交
167 168
promise.then(() => {
    console.log(`setDefaultCellularDataSlotId success.`);
S
shawn_he 已提交
169 170
}).catch((err) => {
    console.error(`setDefaultCellularDataSlotId fail, promise: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
171 172 173
});
```

S
shawn_he 已提交
174
## data.getCellularDataFlowType
S
shawn_he 已提交
175 176 177

getCellularDataFlowType(callback: AsyncCallback\<DataFlowType\>): void

S
shawn_he 已提交
178
Obtains the cellular data flow type, which can be uplink or downlink. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
179 180 181 182 183

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
184
| Name  | Type                                          | Mandatory| Description      |
S
shawn_he 已提交
185
| -------- | ---------------------------------------------- | ---- | ---------- |
S
shawn_he 已提交
186
| callback | AsyncCallback\<[DataFlowType](#dataflowtype)\> | Yes  | Callback used to return the result.|
S
shawn_he 已提交
187 188 189

**Example**

S
shawn_he 已提交
190
```js
S
shawn_he 已提交
191 192 193 194 195
data.getCellularDataFlowType((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

S
shawn_he 已提交
196
## data.getCellularDataFlowType
S
shawn_he 已提交
197 198 199

getCellularDataFlowType(): Promise\<DataFlowType\>

S
shawn_he 已提交
200
Obtains the cellular data flow type, which can be uplink or downlink. This API uses a promise to return the result.
S
shawn_he 已提交
201 202 203

**System capability**: SystemCapability.Telephony.CellularData

S
shawn_he 已提交
204
**Return value**
S
shawn_he 已提交
205

S
shawn_he 已提交
206
| Type                                    | Description                                           |
S
shawn_he 已提交
207
| ---------------------------------------- | ----------------------------------------------- |
S
shawn_he 已提交
208
| Promise\<[DataFlowType](#dataflowtype)\> | Promise used to return the result. |
S
shawn_he 已提交
209 210 211

**Example**

S
shawn_he 已提交
212
```js
S
shawn_he 已提交
213 214 215 216 217 218 219 220
let promise = data.getCellularDataFlowType();
promise.then((data) => {
    console.log(`test success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => {
    console.error(`test fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
221
## data.getCellularDataState
S
shawn_he 已提交
222 223 224

getCellularDataState(callback: AsyncCallback\<DataConnectState\>): void

S
shawn_he 已提交
225
Obtains the connection status of the packet switched (PS) domain. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
226 227 228 229 230

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
231
| Name  | Type                                                  | Mandatory| Description      |
S
shawn_he 已提交
232
| -------- | ------------------------------------------------------ | ---- | ---------- |
S
shawn_he 已提交
233
| callback | AsyncCallback\<[DataConnectState](#dataconnectstate)\> | Yes  | Callback used to return the result.|
S
shawn_he 已提交
234 235 236

**Example**

S
shawn_he 已提交
237
```js
S
shawn_he 已提交
238 239 240 241 242
data.getCellularDataState((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

S
shawn_he 已提交
243
## data.getCellularDataState
S
shawn_he 已提交
244 245 246

getCellularDataState(): Promise\<DataConnectState\>

S
shawn_he 已提交
247
Obtains the connection status of the PS domain. This API uses a promise to return the result.
S
shawn_he 已提交
248 249 250

**System capability**: SystemCapability.Telephony.CellularData

S
shawn_he 已提交
251
**Return value**
S
shawn_he 已提交
252

S
shawn_he 已提交
253
| Type                                            | Description                                 |
S
shawn_he 已提交
254
| ------------------------------------------------ | ------------------------------------- |
S
shawn_he 已提交
255
| Promise\<[DataConnectState](#dataconnectstate)\> | Promise used to return the result.|
S
shawn_he 已提交
256 257 258

**Example**

S
shawn_he 已提交
259
```js
S
shawn_he 已提交
260 261 262 263 264 265 266 267
let promise = data.getCellularDataState();
promise.then((data) => {
    console.log(`test success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => {
    console.error(`test fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
268
## data.isCellularDataEnabled
S
shawn_he 已提交
269 270 271

isCellularDataEnabled(callback: AsyncCallback\<boolean\>): void

S
shawn_he 已提交
272
Checks whether the cellular data service is enabled. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
273 274 275 276 277 278 279

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
280
| Name  | Type                    | Mandatory| Description                                                        |
S
shawn_he 已提交
281
| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
282
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.<br>**true**: The cellular data service is enabled.<br>**false**: The cellular data service is disabled.|
S
shawn_he 已提交
283

S
shawn_he 已提交
284 285
**Error codes**

S
shawn_he 已提交
286 287
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
288 289 290 291 292 293 294 295 296
| ID|                 Error Message                    |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
297 298
**Example**

S
shawn_he 已提交
299
```js
S
shawn_he 已提交
300 301 302 303 304
data.isCellularDataEnabled((err, data) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

S
shawn_he 已提交
305
## data.isCellularDataEnabled
S
shawn_he 已提交
306 307 308

isCellularDataEnabled(): Promise\<boolean\>

S
shawn_he 已提交
309
Checks whether the cellular data service is enabled. This API uses a promise to return the result.
S
shawn_he 已提交
310 311 312 313 314

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Telephony.CellularData

S
shawn_he 已提交
315
**Return value**
S
shawn_he 已提交
316

S
shawn_he 已提交
317
| Type              | Description                                                        |
S
shawn_he 已提交
318
| ------------------ | ------------------------------------------------------------ |
S
shawn_he 已提交
319
| Promise\<boolean\> | Promise used to return the result.<br>**true**: The cellular data service is enabled.<br>**false**: The cellular data service is disabled.|
S
shawn_he 已提交
320

S
shawn_he 已提交
321 322
**Error codes**

S
shawn_he 已提交
323 324
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
325 326 327 328 329 330 331 332 333
| ID|                 Error Message                    |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
334 335
**Example**

S
shawn_he 已提交
336
```js
S
shawn_he 已提交
337 338 339 340 341 342 343 344
let promise = data.isCellularDataEnabled();
promise.then((data) => {
    console.log(`test success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => {
    console.error(`test fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
345
## data.isCellularDataRoamingEnabled
S
shawn_he 已提交
346 347 348

isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback\<boolean\>): void

S
shawn_he 已提交
349
Checks whether roaming is enabled for the cellular data service. This API uses an asynchronous callback to return the result.
S
shawn_he 已提交
350 351 352 353 354 355 356

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
357
| Name  | Type                    | Mandatory| Description                                                        |
S
shawn_he 已提交
358
| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
S
shawn_he 已提交
359
| slotId   | number                   | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.                    |
S
shawn_he 已提交
360
| callback | AsyncCallback\<boolean\> | Yes  | Callback used to return the result.<br>**true**: Roaming is enabled for the cellular data service.<br>**false**: Roaming is disabled for the cellular data service.|
S
shawn_he 已提交
361

S
shawn_he 已提交
362 363
**Error codes**

S
shawn_he 已提交
364 365
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
366 367 368 369 370 371 372 373 374
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
375 376
**Example**

S
shawn_he 已提交
377
```js
S
shawn_he 已提交
378
data.isCellularDataRoamingEnabled(0, (err, data) => {
S
shawn_he 已提交
379 380 381 382
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```

S
shawn_he 已提交
383
## data.isCellularDataRoamingEnabled
S
shawn_he 已提交
384 385 386

isCellularDataRoamingEnabled(slotId: number): Promise\<boolean\>

S
shawn_he 已提交
387
Checks whether roaming is enabled for the cellular data service. This API uses a promise to return the result.
S
shawn_he 已提交
388 389 390 391 392 393 394

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

S
shawn_he 已提交
395
| Name| Type  | Mandatory| Description                                    |
S
shawn_he 已提交
396
| ------ | ------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
397
| slotId | number | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
398

S
shawn_he 已提交
399
**Return value**
S
shawn_he 已提交
400

S
shawn_he 已提交
401
| Type              | Description                                                        |
S
shawn_he 已提交
402
| ------------------ | ------------------------------------------------------------ |
S
shawn_he 已提交
403
| Promise\<boolean\> | Promise used to return the result.<br>**true**: Roaming is enabled for the cellular data service.<br>**false**: Roaming is disabled for the cellular data service.|
S
shawn_he 已提交
404

S
shawn_he 已提交
405 406
**Error codes**

S
shawn_he 已提交
407 408
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
409 410 411 412 413 414 415 416 417
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
418 419
**Example**

S
shawn_he 已提交
420
```js
S
shawn_he 已提交
421 422 423 424 425 426 427 428
let promise = data.isCellularDataRoamingEnabled(0);
promise.then((data) => {
    console.log(`test success, promise: data->${JSON.stringify(data)}`);
}).catch((err) => {
    console.error(`test fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
429 430 431 432 433 434
## data.enableCellularData

enableCellularData(callback: AsyncCallback<void\>): void

Enables the cellular data service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
435
**System API**: This is a system API.
S
shawn_he 已提交
436

S
shawn_he 已提交
437
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
438 439 440 441 442 443 444 445 446

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | --------------------- | ---- | ---------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

S
shawn_he 已提交
447 448
**Error codes**

S
shawn_he 已提交
449 450
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
451 452 453 454 455 456 457 458 459
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
460 461 462
**Example**

```js
S
shawn_he 已提交
463 464
data.enableCellularData((err) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
465 466 467 468 469 470 471 472 473
});
```

## data.enableCellularData

enableCellularData(): Promise<void\>

Enables the cellular data service. This API uses a promise to return the result.

S
shawn_he 已提交
474
**System API**: This is a system API.
S
shawn_he 已提交
475

S
shawn_he 已提交
476
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
477 478 479 480 481 482 483 484 485

**System capability**: SystemCapability.Telephony.CellularData

**Return value**

| Type           | Description                   |
| --------------- | ----------------------- |
| Promise\<void\> | Promise used to return the result.|

S
shawn_he 已提交
486 487
**Error codes**

S
shawn_he 已提交
488 489
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
490 491 492 493 494 495 496 497 498
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
499 500 501 502
**Example**

```js
let promise = data.enableCellularData();
S
shawn_he 已提交
503 504
promise.then(() => {
    console.log(`enableCellularData success.`);
S
shawn_he 已提交
505 506 507 508 509 510 511 512 513 514 515
}).catch((err) => {
    console.error(`enableCellularData fail, promise: err->${JSON.stringify(err)}`);
});
```

## data.disableCellularData

disableCellularData(callback: AsyncCallback<void\>): void

Disables the cellular data service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
516
**System API**: This is a system API.
S
shawn_he 已提交
517

S
shawn_he 已提交
518
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
519 520 521 522 523 524 525 526 527

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name  | Type                 | Mandatory| Description      |
| -------- | --------------------- | ---- | ---------- |
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.|

S
shawn_he 已提交
528 529
**Error codes**

S
shawn_he 已提交
530 531
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
532 533 534 535 536 537 538 539 540
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
541 542 543
**Example**

```js
S
shawn_he 已提交
544 545
data.disableCellularData((err) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
546 547 548 549 550 551 552 553 554
});
```

## data.disableCellularData

disableCellularData(): Promise<void\>

Disables the cellular data service. This API uses a promise to return the result.

S
shawn_he 已提交
555
**System API**: This is a system API.
S
shawn_he 已提交
556

S
shawn_he 已提交
557
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
558 559 560 561 562 563 564 565 566

**System capability**: SystemCapability.Telephony.CellularData

**Return value**

| Type           | Description                       |
| --------------- | --------------------------- |
| Promise\<void\> | Promise used to return the result.|

S
shawn_he 已提交
567 568
**Error codes**

S
shawn_he 已提交
569 570
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
571 572 573 574 575 576 577 578 579
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
580 581 582 583
**Example**

```js
let promise = data.disableCellularData();
S
shawn_he 已提交
584 585
promise.then(() => {
    console.log(`disableCellularData success.`);
S
shawn_he 已提交
586 587 588 589 590 591 592 593 594 595 596
}).catch((err) => {
    console.error(`disableCellularData fail, promise: err->${JSON.stringify(err)}`);
});
```

## data.enableCellularDataRoaming

enableCellularDataRoaming(slotId: number, callback: AsyncCallback<void\>): void

Enables the cellular data roaming service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
597
**System API**: This is a system API.
S
shawn_he 已提交
598

S
shawn_he 已提交
599
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
600 601 602 603 604 605 606

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name  | Type                 | Mandatory| Description                                    |
| -------- | --------------------- | ---- | ---------------------------------------- |
S
shawn_he 已提交
607
| slotId   | number                | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
608 609
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                              |

S
shawn_he 已提交
610 611
**Error codes**

S
shawn_he 已提交
612 613
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
614 615 616 617 618 619 620 621 622
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
623 624 625
**Example**

```js
S
shawn_he 已提交
626 627
data.enableCellularDataRoaming(0, (err) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
628 629 630 631 632 633 634 635 636
});
```

## data.enableCellularDataRoaming

enableCellularDataRoaming(slotId: number): Promise<void\>

Enables the cellular data roaming service. This API uses a promise to return the result.

S
shawn_he 已提交
637
**System API**: This is a system API.
S
shawn_he 已提交
638

S
shawn_he 已提交
639
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
640 641 642 643 644 645 646

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name| Type  | Mandatory| Description                                    |
| ------ | ------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
647
| slotId | number | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
648 649 650 651 652 653 654

**Return value**

| Type           | Description                     |
| --------------- | ------------------------- |
| Promise\<void\> | Promise used to return the result.|

S
shawn_he 已提交
655 656
**Error codes**

S
shawn_he 已提交
657 658
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
659 660 661 662 663 664 665 666 667
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
668 669 670 671
**Example**

```js
let promise = data.enableCellularDataRoaming(0);
S
shawn_he 已提交
672 673
promise.then(() => {
    console.log(`enableCellularDataRoaming success.`);
S
shawn_he 已提交
674 675 676 677 678 679 680 681 682 683 684
}).catch((err) => {
    console.error(`enableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`);
});
```

## data.disableCellularDataRoaming

disableCellularDataRoaming(slotId: number, callback: AsyncCallback<void\>): void

Disables the cellular data roaming service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
685
**System API**: This is a system API.
S
shawn_he 已提交
686

S
shawn_he 已提交
687
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
688 689 690 691 692 693 694

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name  | Type                 | Mandatory| Description                                    |
| -------- | --------------------- | ---- | ---------------------------------------- |
S
shawn_he 已提交
695
| slotId   | number                | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
696 697
| callback | AsyncCallback\<void\> | Yes  | Callback used to return the result.                              |

S
shawn_he 已提交
698 699
**Error codes**

S
shawn_he 已提交
700 701
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
702 703 704 705 706 707 708 709 710
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
711 712 713
**Example**

```js
S
shawn_he 已提交
714 715
data.disableCellularDataRoaming(0, (err) => {
    console.log(`callback: err->${JSON.stringify(err)}`);
S
shawn_he 已提交
716 717 718 719 720 721 722 723 724
});
```

## data.disableCellularDataRoaming

disableCellularDataRoaming(slotId: number): Promise<void\>

Disables the cellular data roaming service. This API uses a promise to return the result.

S
shawn_he 已提交
725
**System API**: This is a system API.
S
shawn_he 已提交
726

S
shawn_he 已提交
727
**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
S
shawn_he 已提交
728 729 730 731 732 733 734

**System capability**: SystemCapability.Telephony.CellularData

**Parameters**

| Name| Type  | Mandatory| Description                                    |
| ------ | ------ | ---- | ---------------------------------------- |
S
shawn_he 已提交
735
| slotId | number | Yes  | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.|
S
shawn_he 已提交
736 737 738 739 740 741 742

**Return value**

| Type           | Description                     |
| --------------- | ------------------------- |
| Promise\<void\> | Promise used to return the result.|

S
shawn_he 已提交
743 744
**Error codes**

S
shawn_he 已提交
745 746
For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).

S
shawn_he 已提交
747 748 749 750 751 752 753 754 755
| ID|                  Error Message                   |
| -------- | -------------------------------------------- |
| 201      | Permission denied.                           |
| 401      | Parameter error.                             |
| 8300001  | Invalid parameter value.                     |
| 8300002  | Operation failed. Cannot connect to service. |
| 8300003  | System internal error.                       |
| 8300999  | Unknown error code.                          |

S
shawn_he 已提交
756 757 758 759
**Example**

```js
let promise = data.disableCellularDataRoaming(0);
S
shawn_he 已提交
760 761
promise.then(() => {
    console.log(`disableCellularDataRoaming success.`);
S
shawn_he 已提交
762 763 764 765 766
}).catch((err) => {
    console.error(`disableCellularDataRoaming fail, promise: err->${JSON.stringify(err)}`);
});
```

S
shawn_he 已提交
767
## DataFlowType
S
shawn_he 已提交
768

S
shawn_he 已提交
769
Defines the cellular data flow type.
S
shawn_he 已提交
770

S
shawn_he 已提交
771 772 773 774 775 776 777
**System capability**: SystemCapability.Telephony.CellularData

| Name                  | Value  | Description                                      |
| ---------------------- | ---- | ------------------------------------------ |
| DATA_FLOW_TYPE_NONE    | 0    | No uplink or downlink data is available.                  |
| DATA_FLOW_TYPE_DOWN    | 1    | Only the downlink data is available.                        |
| DATA_FLOW_TYPE_UP      | 2    | Only the uplink data is available.                        |
S
shawn_he 已提交
778
| DATA_FLOW_TYPE_UP_DOWN | 3    | Both the uplink data and downlink data are available.                        |
S
shawn_he 已提交
779
| DATA_FLOW_TYPE_DORMANT | 4    | No uplink or downlink data is available because the lower-layer link is in the dormant state.|
S
shawn_he 已提交
780

S
shawn_he 已提交
781
## DataConnectState
S
shawn_he 已提交
782

S
shawn_he 已提交
783
Describes the connection status of a cellular data link.
S
shawn_he 已提交
784 785

**System capability**: SystemCapability.Telephony.CellularData
S
shawn_he 已提交
786

S
shawn_he 已提交
787 788
| Name                   | Value  | Description                      |
| ----------------------- | ---- | -------------------------- |
S
shawn_he 已提交
789 790 791 792 793
| DATA_STATE_UNKNOWN      | -1   | The status of the cellular data link is unknown.    |
| DATA_STATE_DISCONNECTED | 0    | The cellular data link is disconnected.    |
| DATA_STATE_CONNECTING   | 1    | The cellular data link is being connected.|
| DATA_STATE_CONNECTED    | 2    | The cellular data link is connected.  |
| DATA_STATE_SUSPENDED    | 3    | The cellular data link is suspended.  |