1# Cellular Data 2 3> **NOTE**<br> 4> 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. 5 6## Modules to Import 7 8``` 9import data from '@ohos.telephony.data'; 10``` 11 12## data.getDefaultCellularDataSlotId 13 14getDefaultCellularDataSlotId(callback: AsyncCallback\<number\>): void 15 16Obtains the default SIM card used for mobile data. This API uses an asynchronous callback to return the result. 17 18**Required permission**: ohos.permission.GET_NETWORK_INFO 19 20**System capability**: SystemCapability.Telephony.CellularData 21 22**Parameters** 23 24| Name | Type | Mandatory| Description | 25| -------- | ----------------------- | ---- | ------------------------------------------ | 26| callback | AsyncCallback\<number\> | Yes | Callback used to return the result.<br>**0**: card slot 1<br>**1**: card slot 2| 27 28**Example** 29 30``` 31data.getDefaultCellularDataSlotId((err, data) => { 32 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 33}); 34``` 35 36## data.getDefaultCellularDataSlotId 37 38getDefaultCellularDataSlotId(): Promise\<number\> 39 40Obtains the default SIM card used for mobile data. This API uses a promise to return the result. 41 42**Required permission**: ohos.permission.GET_NETWORK_INFO 43 44**System capability**: SystemCapability.Telephony.CellularData 45 46**Return Value** 47 48| Type | Description | 49| ----------------- | ------------------------------------------------------------ | 50| Promise\<number\> | Promise used to return the result.<br>**0**: card slot 1<br>**1**: card slot 2| 51 52**Example** 53 54``` 55let promise = data.getDefaultCellularDataSlotId(); 56promise.then((data) => { 57 console.log(`test success, promise: data->${JSON.stringify(data)}`); 58}).catch((err) => { 59 console.error(`test fail, promise: err->${JSON.stringify(err)}`); 60}); 61``` 62 63## data.getCellularDataFlowType 64 65getCellularDataFlowType(callback: AsyncCallback\<DataFlowType\>): void 66 67Obtains the cellular data flow type, which can be uplink or downlink. This API uses an asynchronous callback to return the result. 68 69**System capability**: SystemCapability.Telephony.CellularData 70 71**Parameters** 72 73| Name | Type | Mandatory| Description | 74| -------- | ---------------------------------------------- | ---- | ---------- | 75| callback | AsyncCallback\<[DataFlowType](#dataflowtype)\> | Yes | Callback used to return the result.| 76 77**Example** 78 79``` 80data.getCellularDataFlowType((err, data) => { 81 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 82}); 83``` 84 85## data.getCellularDataFlowType 86 87getCellularDataFlowType(): Promise\<DataFlowType\> 88 89Obtains the cellular data flow type, which can be uplink or downlink. This API uses a promise to return the result. 90 91**System capability**: SystemCapability.Telephony.CellularData 92 93**Return Value** 94 95| Type | Description | 96| ---------------------------------------- | ----------------------------------------------- | 97| Promise\<[DataFlowType](#dataflowtype)\> | Promise used to return the result. | 98 99**Example** 100 101``` 102let promise = data.getCellularDataFlowType(); 103promise.then((data) => { 104 console.log(`test success, promise: data->${JSON.stringify(data)}`); 105}).catch((err) => { 106 console.error(`test fail, promise: err->${JSON.stringify(err)}`); 107}); 108``` 109 110## data.getCellularDataState 111 112getCellularDataState(callback: AsyncCallback\<DataConnectState\>): void 113 114Obtains the connection status of the packet switched (PS) domain. This API uses an asynchronous callback to return the result. 115 116**System capability**: SystemCapability.Telephony.CellularData 117 118**Parameters** 119 120| Name | Type | Mandatory| Description | 121| -------- | ------------------------------------------------------ | ---- | ---------- | 122| callback | AsyncCallback\<[DataConnectState](#dataconnectstate)\> | Yes | Callback used to return the result.| 123 124**Example** 125 126``` 127data.getCellularDataState((err, data) => { 128 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 129}); 130``` 131 132## data.getCellularDataState 133 134getCellularDataState(): Promise\<DataConnectState\> 135 136Obtains the connection status of the PS domain. This API uses a promise to return the result. 137 138**System capability**: SystemCapability.Telephony.CellularData 139 140**Return Value** 141 142| Type | Description | 143| ------------------------------------------------ | ------------------------------------- | 144| Promise\<[DataConnectState](#dataconnectstate)\> | Promise used to return the result.| 145 146**Example** 147 148``` 149let promise = data.getCellularDataState(); 150promise.then((data) => { 151 console.log(`test success, promise: data->${JSON.stringify(data)}`); 152}).catch((err) => { 153 console.error(`test fail, promise: err->${JSON.stringify(err)}`); 154}); 155``` 156 157## data.isCellularDataEnabled 158 159isCellularDataEnabled(callback: AsyncCallback\<boolean\>): void 160 161Checks whether the cellular data service is enabled. This API uses an asynchronous callback to return the result. 162 163**Required permission**: ohos.permission.GET_NETWORK_INFO 164 165**System capability**: SystemCapability.Telephony.CellularData 166 167**Parameters** 168 169| Name | Type | Mandatory| Description | 170| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 171| 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.| 172 173**Example** 174 175``` 176data.isCellularDataEnabled((err, data) => { 177 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 178}); 179``` 180 181## data.isCellularDataEnabled 182 183isCellularDataEnabled(): Promise\<boolean\> 184 185Checks whether the cellular data service is enabled. This API uses a promise to return the result. 186 187**Required permission**: ohos.permission.GET_NETWORK_INFO 188 189**System capability**: SystemCapability.Telephony.CellularData 190 191**Return Value** 192 193| Type | Description | 194| ------------------ | ------------------------------------------------------------ | 195| Promise\<boolean\> | Promise used to return the result.<br>**true**: The cellular data service is enabled.<br>**false**: The cellular data service is disabled.| 196 197**Example** 198 199``` 200let promise = data.isCellularDataEnabled(); 201promise.then((data) => { 202 console.log(`test success, promise: data->${JSON.stringify(data)}`); 203}).catch((err) => { 204 console.error(`test fail, promise: err->${JSON.stringify(err)}`); 205}); 206``` 207 208## data.isCellularDataRoamingEnabled 209 210isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback\<boolean\>): void 211 212Checks whether roaming is enabled for the cellular data service. This API uses an asynchronous callback to return the result. 213 214**Required permission**: ohos.permission.GET_NETWORK_INFO 215 216**System capability**: SystemCapability.Telephony.CellularData 217 218**Parameters** 219 220| Name | Type | Mandatory| Description | 221| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 222| slotId | number | Yes | Card slot ID. <br>**0**: card slot 1<br>**1**: card slot 2 | 223| 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.| 224 225**Example** 226 227``` 228data.isCellularDataRoamingEnabled(0,(err, data) => { 229 console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 230}); 231``` 232 233## data.isCellularDataRoamingEnabled 234 235isCellularDataRoamingEnabled(slotId: number): Promise\<boolean\> 236 237Checks whether roaming is enabled for the cellular data service. This API uses a promise to return the result. 238 239**Required permission**: ohos.permission.GET_NETWORK_INFO 240 241**System capability**: SystemCapability.Telephony.CellularData 242 243**Parameters** 244 245| Name| Type | Mandatory| Description | 246| ------ | ------ | ---- | ---------------------------------------- | 247| slotId | number | Yes | Card slot ID. <br>**0**: card slot 1<br>**1**: card slot 2| 248 249**Return Value** 250 251| Type | Description | 252| ------------------ | ------------------------------------------------------------ | 253| 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.| 254 255**Example** 256 257``` 258let promise = data.isCellularDataRoamingEnabled(0); 259promise.then((data) => { 260 console.log(`test success, promise: data->${JSON.stringify(data)}`); 261}).catch((err) => { 262 console.error(`test fail, promise: err->${JSON.stringify(err)}`); 263}); 264``` 265 266## DataFlowType 267 268Defines the cellular data flow type. 269 270**System capability**: SystemCapability.Telephony.CellularData 271 272| Name | Value | Description | 273| ---------------------- | ---- | ------------------------------------------ | 274| DATA_FLOW_TYPE_NONE | 0 | No uplink or downlink data is available. | 275| DATA_FLOW_TYPE_DOWN | 1 | Only the downlink data is available. | 276| DATA_FLOW_TYPE_UP | 2 | Only the uplink data is available. | 277| DATA_FLOW_TYPE_UP_DOWN | 3 | Both uplink data and downlink data are available. | 278| DATA_FLOW_TYPE_DORMANT | 4 | No uplink or downlink data is available because the lower-layer link is in the dormant state.| 279 280## DataConnectState 281 282Describes the connection status of a cellular data link. 283 284**System capability**: SystemCapability.Telephony.CellularData 285 286| Name | Value | Description | 287| ----------------------- | ---- | -------------------------- | 288| DATA_STATE_UNKNOWN | -1 | The status of the cellular data link is unknown. | 289| DATA_STATE_DISCONNECTED | 0 | The cellular data link is disconnected. | 290| DATA_STATE_CONNECTING | 1 | The cellular data link is being connected.| 291| DATA_STATE_CONNECTED | 2 | The cellular data link is connected. | 292| DATA_STATE_SUSPENDED | 3 | The cellular data link is suspended. | 293