1e41f4b71Sopenharmony_ci# @ohos.telephony.data (Cellular Data) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **data** module provides basic mobile data management functions. You can obtain 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. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci>**NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci>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. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Modules to Import 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## data.getDefaultCellularDataSlotId 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_cigetDefaultCellularDataSlotId(callback: AsyncCallback\<number\>): void 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciObtains the default slot of the SIM card used for mobile data. This API uses an asynchronous callback to return the result. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Parameters** 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 26e41f4b71Sopenharmony_ci| -------- | ----------------------- | ---- | ------------------------------------------ | 27e41f4b71Sopenharmony_ci| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.| 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Example** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci```ts 32e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 33e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_cidata.getDefaultCellularDataSlotId((err: BusinessError, data: number) => { 36e41f4b71Sopenharmony_ci if(err){ 37e41f4b71Sopenharmony_ci console.error(`getDefaultCellularDataSlotId fail,callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 38e41f4b71Sopenharmony_ci }else{ 39e41f4b71Sopenharmony_ci console.log(`getDefaultCellularDataSlotId success`); 40e41f4b71Sopenharmony_ci } 41e41f4b71Sopenharmony_ci}); 42e41f4b71Sopenharmony_ci``` 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci## data.getDefaultCellularDataSlotId 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_cigetDefaultCellularDataSlotId(): Promise\<number\> 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ciObtains the default slot of the SIM card used for mobile data. This API uses a promise to return the result. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**Return value** 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci| Type | Description | 55e41f4b71Sopenharmony_ci| ----------------- | ------------------------------------------------------------ | 56e41f4b71Sopenharmony_ci| Promise\<number\> | Promise used to return the result.<br>**0**: card slot 1.<br>**1**: card slot 2.| 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci**Example** 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci```ts 61e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 62e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_cidata.getDefaultCellularDataSlotId().then((data: number) => { 65e41f4b71Sopenharmony_ci console.log(`getDefaultCellularDataSlotId success, promise: data->${JSON.stringify(data)}`); 66e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 67e41f4b71Sopenharmony_ci console.error(`getDefaultCellularDataSlotId fail, promise: err->${JSON.stringify(err)}`); 68e41f4b71Sopenharmony_ci}); 69e41f4b71Sopenharmony_ci``` 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci## data.getDefaultCellularDataSlotIdSync<sup>9+</sup> 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_cigetDefaultCellularDataSlotIdSync(): number 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ciObtains the default SIM card used for mobile data synchronously. 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**Return value** 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| Type | Description | 82e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | 83e41f4b71Sopenharmony_ci| number | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.| 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**Example** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci```ts 88e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciconsole.log("Result: "+ data.getDefaultCellularDataSlotIdSync()) 91e41f4b71Sopenharmony_ci``` 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci## data.getCellularDataFlowType 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_cigetCellularDataFlowType(callback: AsyncCallback\<DataFlowType\>): void 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ciObtains the cellular data flow type, which can be uplink or downlink. This API uses an asynchronous callback to return the result. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci**Parameters** 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 105e41f4b71Sopenharmony_ci| -------- | ---------------------------------------------- | ---- | ---------- | 106e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[DataFlowType](#dataflowtype)\> | Yes | Callback used to return the result.| 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci**Example** 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci```ts 111e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 112e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_cidata.getCellularDataFlowType((err: BusinessError, data: data.DataFlowType) => { 115e41f4b71Sopenharmony_ci if(err){ 116e41f4b71Sopenharmony_ci console.error(`getCellularDataFlowType fail,callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 117e41f4b71Sopenharmony_ci }else{ 118e41f4b71Sopenharmony_ci console.log(`getCellularDataFlowType success`); 119e41f4b71Sopenharmony_ci } 120e41f4b71Sopenharmony_ci}); 121e41f4b71Sopenharmony_ci``` 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci## data.getCellularDataFlowType 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_cigetCellularDataFlowType(): Promise\<DataFlowType\> 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ciObtains the cellular data flow type, which can be uplink or downlink. This API uses a promise to return the result. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Return value** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci| Type | Description | 134e41f4b71Sopenharmony_ci| ---------------------------------------- | ----------------------------------------------- | 135e41f4b71Sopenharmony_ci| Promise\<[DataFlowType](#dataflowtype)\> | Promise used to return the result. | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**Example** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci```ts 140e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 141e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_cidata.getCellularDataFlowType().then((data: data.DataFlowType) => { 144e41f4b71Sopenharmony_ci console.log(`getCellularDataFlowType success, promise: data->${JSON.stringify(data)}`); 145e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 146e41f4b71Sopenharmony_ci console.error(`getCellularDataFlowType fail, promise: err->${JSON.stringify(err)}`); 147e41f4b71Sopenharmony_ci}); 148e41f4b71Sopenharmony_ci``` 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci## data.getCellularDataState 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_cigetCellularDataState(callback: AsyncCallback\<DataConnectState\>): void 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ciObtains the connection status of the packet switched (PS) domain. This API uses an asynchronous callback to return the result. 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci**Parameters** 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 161e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------ | ---- | ---------- | 162e41f4b71Sopenharmony_ci| callback | AsyncCallback\<[DataConnectState](#dataconnectstate)\> | Yes | Callback used to return the result.| 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci**Example** 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci```ts 167e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 168e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_cidata.getCellularDataState((err: BusinessError, data: data.DataConnectState) => { 171e41f4b71Sopenharmony_ci if(err){ 172e41f4b71Sopenharmony_ci console.error(`getCellularDataState fail,callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 173e41f4b71Sopenharmony_ci }else{ 174e41f4b71Sopenharmony_ci console.log(`getCellularDataState success`); 175e41f4b71Sopenharmony_ci } 176e41f4b71Sopenharmony_ci}); 177e41f4b71Sopenharmony_ci``` 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci## data.getCellularDataState 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_cigetCellularDataState(): Promise\<DataConnectState\> 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ciObtains the connection status of the PS domain. This API uses a promise to return the result. 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**Return value** 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci| Type | Description | 190e41f4b71Sopenharmony_ci| ------------------------------------------------ | ------------------------------------- | 191e41f4b71Sopenharmony_ci| Promise\<[DataConnectState](#dataconnectstate)\> | Promise used to return the result.| 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci**Example** 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci```ts 196e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 197e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_cidata.getCellularDataState().then((data: data.DataConnectState) => { 200e41f4b71Sopenharmony_ci console.log(`getCellularDataState success, promise: data->${JSON.stringify(data)}`); 201e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 202e41f4b71Sopenharmony_ci console.error(`getCellularDataState fail, promise: err->${JSON.stringify(err)}`); 203e41f4b71Sopenharmony_ci}); 204e41f4b71Sopenharmony_ci``` 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci## data.isCellularDataEnabled 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ciisCellularDataEnabled(callback: AsyncCallback\<boolean\>): void 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciChecks whether the cellular data service is enabled. This API uses an asynchronous callback to return the result. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**Parameters** 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 219e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 220e41f4b71Sopenharmony_ci| 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.| 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**Error codes** 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci| ID| Error Message | 227e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 228e41f4b71Sopenharmony_ci| 201 | Permission denied. | 229e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 230e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 231e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 232e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 233e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**Example** 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci```ts 238e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 239e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_cidata.isCellularDataEnabled((err: BusinessError, data: boolean) => { 242e41f4b71Sopenharmony_ci if(err){ 243e41f4b71Sopenharmony_ci console.error(`isCellularDataEnabled fail,callback: callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 244e41f4b71Sopenharmony_ci }else{ 245e41f4b71Sopenharmony_ci console.log(`isCellularDataEnabled success`); 246e41f4b71Sopenharmony_ci } 247e41f4b71Sopenharmony_ci}); 248e41f4b71Sopenharmony_ci``` 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci## data.isCellularDataEnabled 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciisCellularDataEnabled(): Promise\<boolean\> 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ciChecks whether the cellular data service is enabled. This API uses a promise to return the result. 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 259e41f4b71Sopenharmony_ci 260e41f4b71Sopenharmony_ci**Return value** 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci| Type | Description | 263e41f4b71Sopenharmony_ci| ------------------ | ------------------------------------------------------------ | 264e41f4b71Sopenharmony_ci| Promise\<boolean\> | Promise used to return the result.<br>**true**: The cellular data service is enabled.<br>**false**: The cellular data service is disabled.| 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci**Error codes** 267e41f4b71Sopenharmony_ci 268e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci| ID| Error Message | 271e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 272e41f4b71Sopenharmony_ci| 201 | Permission denied. | 273e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 274e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 275e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci**Example** 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci```ts 280e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 281e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_cidata.isCellularDataEnabled().then((data: boolean) => { 284e41f4b71Sopenharmony_ci console.log(`isCellularDataEnabled success, promise: data->${JSON.stringify(data)}`); 285e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 286e41f4b71Sopenharmony_ci console.error(`isCellularDataEnabled fail, promise: err->${JSON.stringify(err)}`); 287e41f4b71Sopenharmony_ci}); 288e41f4b71Sopenharmony_ci``` 289e41f4b71Sopenharmony_ci 290e41f4b71Sopenharmony_ci## data.isCellularDataEnabledSync<sup>12+</sup> 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ciisCellularDataEnabledSync(): boolean 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ciChecks whether the cellular data service is enabled. This API returns the result synchronously. 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 297e41f4b71Sopenharmony_ci 298e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ci**Return value** 301e41f4b71Sopenharmony_ci 302e41f4b71Sopenharmony_ci| Type | Description | 303e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 304e41f4b71Sopenharmony_ci| boolean | Whether the cellular data service is enabled.<br>**true**: The cellular data service is enabled.<br>**false**: The cellular data service is disabled.| 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci**Error codes** 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci| ID| Error Message | 311e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 312e41f4b71Sopenharmony_ci| 201 | Permission denied. | 313e41f4b71Sopenharmony_ci| 8300002 | Operation failed. Cannot connect to service. | 314e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 315e41f4b71Sopenharmony_ci| 8300999 | Unknown error code. | 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci**Example** 318e41f4b71Sopenharmony_ci 319e41f4b71Sopenharmony_ci<!--code_no_check--> 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci```ts 322e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_citry { 325e41f4b71Sopenharmony_ci let isEnabled: boolean = data.isCellularDataEnabledSync(); 326e41f4b71Sopenharmony_ci console.log(`isCellularDataEnabledSync success : ${isEnabled}`); 327e41f4b71Sopenharmony_ci} catch (error) { 328e41f4b71Sopenharmony_ci console.error(`isCellularDataEnabledSync fail : err->${JSON.stringify(error)}`); 329e41f4b71Sopenharmony_ci} 330e41f4b71Sopenharmony_ci``` 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci## data.isCellularDataRoamingEnabled 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ciisCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback\<boolean\>): void 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ciChecks whether roaming is enabled for the cellular data service. This API uses an asynchronous callback to return the result. 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci**Parameters** 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci| Name | Type | Mandatory| Description | 345e41f4b71Sopenharmony_ci| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 346e41f4b71Sopenharmony_ci| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2. | 347e41f4b71Sopenharmony_ci| 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.| 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**Error codes** 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci| ID| Error Message | 354e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 355e41f4b71Sopenharmony_ci| 201 | Permission denied. | 356e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 357e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 358e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 359e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 360e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci**Example** 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci```ts 365e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 366e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_cidata.isCellularDataRoamingEnabled(0, (err: BusinessError, data: boolean) => { 369e41f4b71Sopenharmony_ci if(err){ 370e41f4b71Sopenharmony_ci console.error(`isCellularDataRoamingEnabled fail,callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 371e41f4b71Sopenharmony_ci }else{ 372e41f4b71Sopenharmony_ci console.log(`isCellularDataRoamingEnabled success`); 373e41f4b71Sopenharmony_ci } 374e41f4b71Sopenharmony_ci}); 375e41f4b71Sopenharmony_ci``` 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci## data.isCellularDataRoamingEnabled 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciisCellularDataRoamingEnabled(slotId: number): Promise\<boolean\> 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ciChecks whether roaming is enabled for the cellular data service. This API uses a promise to return the result. 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci**Parameters** 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 390e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------- | 391e41f4b71Sopenharmony_ci| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.| 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**Return value** 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci| Type | Description | 396e41f4b71Sopenharmony_ci| ------------------ | ------------------------------------------------------------ | 397e41f4b71Sopenharmony_ci| 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.| 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**Error codes** 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci| ID| Error Message | 404e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- | 405e41f4b71Sopenharmony_ci| 201 | Permission denied. | 406e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 407e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 408e41f4b71Sopenharmony_ci| 8300002 | Service connection failed. | 409e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 410e41f4b71Sopenharmony_ci| 8300999 | Unknown error. | 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Example** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci```ts 415e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 416e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_cidata.isCellularDataRoamingEnabled(0).then((data: boolean) => { 419e41f4b71Sopenharmony_ci console.log(`isCellularDataRoamingEnabled success, promise: data->${JSON.stringify(data)}`); 420e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 421e41f4b71Sopenharmony_ci console.error(`isCellularDataRoamingEnabled fail, promise: err->${JSON.stringify(err)}`); 422e41f4b71Sopenharmony_ci}); 423e41f4b71Sopenharmony_ci``` 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci## data.isCellularDataRoamingEnabledSync<sup>12+</sup> 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ciisCellularDataRoamingEnabledSync(slotId: number): boolean 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ciChecks whether roaming is enabled for the cellular data service. This API returns the result synchronously. 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ci**Required permission**: ohos.permission.GET_NETWORK_INFO 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci**Parameters** 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 438e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------------- | 439e41f4b71Sopenharmony_ci| slotId | number | Yes | Card slot ID.<br>**0**: card slot 1.<br>**1**: card slot 2.| 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci**Return value** 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci| Type | Description | 444e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | 445e41f4b71Sopenharmony_ci| boolean | Whether roaming is enabled for the cellular data service.<br>**true**: Roaming is enabled for the cellular data service.<br>**false**: Roaming is disabled for the cellular data service.| 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci**Error codes** 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md). 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci| ID| Error Message | 452e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | 453e41f4b71Sopenharmony_ci| 201 | Permission denied. | 454e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; | 455e41f4b71Sopenharmony_ci| 8300001 | Invalid parameter value. | 456e41f4b71Sopenharmony_ci| 8300002 | Operation failed. Cannot connect to service. | 457e41f4b71Sopenharmony_ci| 8300003 | System internal error. | 458e41f4b71Sopenharmony_ci| 8300999 | Unknown error code. | 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci**Example** 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci<!--code_no_check--> 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci```ts 465e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_citry { 468e41f4b71Sopenharmony_ci let isEnabled: boolean = data.isCellularDataRoamingEnabledSync(0); 469e41f4b71Sopenharmony_ci console.log(`isCellularDataRoamingEnabledSync success : ${isEnabled}`); 470e41f4b71Sopenharmony_ci} catch (error) { 471e41f4b71Sopenharmony_ci console.error(`isCellularDataRoamingEnabledSync fail : err->${JSON.stringify(error)}`); 472e41f4b71Sopenharmony_ci} 473e41f4b71Sopenharmony_ci``` 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci## data.getDefaultCellularDataSimId<sup>10+</sup> 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_cigetDefaultCellularDataSimId(): number 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ciObtains the default ID of the SIM card used for mobile data. 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci**Return value** 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| Type | Description | 486e41f4b71Sopenharmony_ci| ------ | -------------------------------------------------- | 487e41f4b71Sopenharmony_ci| number | Obtains the default ID of the SIM card used for mobile data.<br>The return value is bound to the SIM card and increases from 1.| 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci**Example** 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci```ts 492e41f4b71Sopenharmony_ciimport { data } from '@kit.TelephonyKit'; 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ciconsole.log("Result: "+ data.getDefaultCellularDataSimId()); 495e41f4b71Sopenharmony_ci``` 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci## DataFlowType 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciDefines the cellular data flow type. 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci| Name | Value | Description | 504e41f4b71Sopenharmony_ci| ---------------------- | ---- | ------------------------------------------ | 505e41f4b71Sopenharmony_ci| DATA_FLOW_TYPE_NONE | 0 | No uplink or downlink data is available. | 506e41f4b71Sopenharmony_ci| DATA_FLOW_TYPE_DOWN | 1 | Only the downlink data is available. | 507e41f4b71Sopenharmony_ci| DATA_FLOW_TYPE_UP | 2 | Only the uplink data is available. | 508e41f4b71Sopenharmony_ci| DATA_FLOW_TYPE_UP_DOWN | 3 | Both the uplink data and downlink data are available. | 509e41f4b71Sopenharmony_ci| DATA_FLOW_TYPE_DORMANT | 4 | No uplink or downlink data is available because the lower-layer link is in the dormant state.| 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci## DataConnectState 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ciDescribes the connection status of a cellular data link. 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.CellularData 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci| Name | Value | Description | 518e41f4b71Sopenharmony_ci| ----------------------- | ---- | -------------------------- | 519e41f4b71Sopenharmony_ci| DATA_STATE_UNKNOWN | -1 | The status of the cellular data link is unknown. | 520e41f4b71Sopenharmony_ci| DATA_STATE_DISCONNECTED | 0 | The cellular data link is disconnected. | 521e41f4b71Sopenharmony_ci| DATA_STATE_CONNECTING | 1 | The cellular data link is being connected.| 522e41f4b71Sopenharmony_ci| DATA_STATE_CONNECTED | 2 | The cellular data link is connected. | 523e41f4b71Sopenharmony_ci| DATA_STATE_SUSPENDED | 3 | The cellular data link is suspended. | 524