diff --git a/en/application-dev/reference/apis/js-apis-call.md b/en/application-dev/reference/apis/js-apis-call.md index cb8927953871984a8f7784697f61071d96715b94..dc54b14b351dc85a09abd394681bd1dd2d182568 100644 --- a/en/application-dev/reference/apis/js-apis-call.md +++ b/en/application-dev/reference/apis/js-apis-call.md @@ -17,7 +17,9 @@ dial\(phoneNumber: string, callback: AsyncCallback\): void Initiates a call. This function uses an asynchronous callback to return the execution result. -Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). +**Required permission**: ohos.permission.PLACE\_CALL (a system permission) + +**System capability**: SystemCapability.Telephony.CallManager **Parameters** @@ -41,7 +43,9 @@ dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback Initiates a call. You can set call options as needed. This function uses a promise to return the execution result. -Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). +**Required permission**: ohos.permission.PLACE\_CALL (a system permission) + +**System capability**: SystemCapability.Telephony.CallManager **Parameters** @@ -102,6 +108,8 @@ hasCall\(callback: AsyncCallback\): void Checks whether a call is in progress. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -123,6 +131,8 @@ hasCall\(\): Promise Checks whether a call is in progress. This function uses a promise to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Return value** | Type| Description| @@ -147,6 +157,8 @@ getCallState\(callback: AsyncCallback\): void Obtains the call status. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -168,6 +180,8 @@ getCallState\(\): Promise Obtains the call status. This function uses a promise to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Return value** | Type| Description| @@ -191,6 +205,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback\) Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -213,6 +229,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, ca Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -236,6 +254,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Checks whether the call number of the SIM card in the specified slot is an emergency number. This function uses a promise to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -266,6 +286,8 @@ formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback\): void Formats a phone number based on the specified ISO country code. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -288,6 +310,8 @@ formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: Formats a phone number based on specified formatting options. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -313,6 +337,8 @@ formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise Formats a phone number based on specified formatting options. This function uses a promise to return the result. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -349,6 +375,8 @@ The phone number must match the specified country code. For example, for a China All country codes are supported. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -378,6 +406,8 @@ The phone number must match the specified country code. For example, for a China All country codes are supported. +**System capability**: SystemCapability.Telephony.CallManager + **Parameters** | Name| Type| Mandatory| Description| @@ -407,30 +437,40 @@ promise.then(data => { ## DialOptions Provides an option for determining whether a call is a video call. -| Parameter| Type| Mandatory| Description| + +**System capability**: SystemCapability.Telephony.CallManager + +| Name| Type| Mandatory| Description| | ------ | ------- | ---- | ------------------------------------------------------------ | | extras | boolean | No| Indication of a video call. The options are as follows:
- **true**: video call
- **false**: voice call| ## CallState Enumerates call states. + | Variable| Value| Description| | ------------------ | ---- | ------------------------------------------------------------ | -| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.| -| CALL_STATE_IDLE | 0 | No call is in progress.| -| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.| -| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.| +| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.
**System capability**: SystemCapability.Telephony.CallManager| +| CALL_STATE_IDLE | 0 | No call is in progress.
**System capability**: SystemCapability.Telephony.CallManager| +| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.
**System capability**: SystemCapability.Telephony.CallManager| +| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.
**System capability**: SystemCapability.Telephony.CallManager| ## EmergencyNumberOptions7+ Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot. -| Parameter| Type| Mandatory| Description| + +**System capability**: SystemCapability.Telephony.CallManager + +| Name| Type| Mandatory| Description| | ------ | ------ | ---- | ------------------------------------------ | | slotId | number | No| SIM card slot ID.
- **0**: slot 1
- **1**: slot 2| ## NumberFormatOptions7+ Provides an option for number formatting. -| Parameter| Type| Mandatory| Description| + +**System capability**: SystemCapability.Telephony.CallManager + +| Name| Type| Mandatory| Description| | ----------- | ------ | ---- | ---------------------------------------------------------- | | countryCode | string | No| Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.| diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md new file mode 100644 index 0000000000000000000000000000000000000000..bb658c1fbd35dcf714092ef915d9c6792a432dcc --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-observer.md @@ -0,0 +1,265 @@ +# Observer + +>**NOTE** +> +>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +## Modules to Import + +``` +import observer from '@ohos.telephony.observer' +``` + +## observer.on('networkStateChange') + +on\(type: \'networkStateChange\', callback: Callback\): void; + +Registers an observer for network status change events. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ----------------------------------------- | ---- | --------------------------------- | +| type | string | Yes| Network status change event.| +| callback | Callback\<[NetworkState](js-apis-radio.md#NetworkState)\> | Yes| Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#NetworkState).| + +**Example** + +``` +observer.on('networkStateChange', data =>{ + console.log("on networkStateChange, data:" + JSON.stringify(data)); +}); +``` + + +## observer.on('networkStateChange') + +on\(type: \'networkStateChange\', options: { slotId: number }, callback: Callback\): void; + +Registers an observer for network status change events of the SIM card in the specified slot. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | -------------------------------------- | +| type | string | Yes| Network status change event.| +| slotId | number | Yes| Card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| +| callback | Callback\<[NetworkState](js-apis-radio.md#NetworkState)\> | Yes| Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#NetworkState).| + +**Example** + +``` +observer.on('networkStateChange', {slotId: 0}, data =>{ + console.log("on networkStateChange, data:" + JSON.stringify(data)); +}); +``` + + +## observer.off('networkStateChange') + +off\(type: \'networkStateChange\', callback?: Callback\): void; + +Unregisters the observer for network status change events. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +>**NOTE** +> +>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------ | ---- | --------------------------------- | +| type | string | Yes| Network status change event.| +| callback | Callback\<[NetworkState](js-apis-radio.md#NetworkState)\> | No| Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#NetworkState).| + +**Example** + +``` +let callback = data => { + console.log("on networkStateChange, data:" + JSON.stringify(data)); +} +observer.on('networkStateChange', callback); +// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +observer.off('networkStateChange', callback); +observer.off('networkStateChange'); +``` + +## observer.on('signalInfoChange') + +on\(type: \'signalInfoChange\', callback: Callback\>): void; + +Registers an observer for signal status change events. This function uses an asynchronous callback to return the execution result. + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes| Signal status change event.| +| callback | Callback\> | Yes| Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#SignalInformation).| + +**Example** + +``` +observer.on('signalInfoChange', data =>{ + console.log("on signalInfoChange, data:" + JSON.stringify(data)); +}); +``` + + +## observer.on('signalInfoChange') + +on\(type: \'signalInfoChange\', options: { slotId: number }, callback: Callback\>): void; + +Registers an observer for signal status change events of the SIM card in the specified slot. This function uses an asynchronous callback to return the execution result. + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | -------------------------------------- | +| type | string | Yes| Signal status change event.| +| slotId | number | Yes| Card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| +| callback | Callback\> | Yes| Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#SignalInformation).| + +**Example** + +``` +observer.on('signalInfoChange', {slotId: 0}, data =>{ + console.log("on signalInfoChange, data:" + JSON.stringify(data)); +}); +``` + + +## observer.off('signalInfoChange') + +off\(type: \'signalInfoChange\', callback?: Callback\>): void; + +Unregisters the observer for signal status change events. This function uses an asynchronous callback to return the execution result. + +>**NOTE** +> +>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes| Signal status change event.| +| callback | Callback\> | No| Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#SignalInformation).| + +**Example** + +``` +let callback = data => { + console.log("on signalInfoChange, data:" + JSON.stringify(data)); +} +observer.on('signalInfoChange', callback); +// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +observer.off('signalInfoChange', callback); +observer.off('signalInfoChange'); +``` + + +## observer.on('callStateChange') + +on(type: 'callStateChange', callback: Callback\<{ state: [CallState](js-apis-call.md#CallState), number: string }\>): void; + +Registers an observer for call status change events. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.READ_CALL_LOG + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes| Call status change event.| +| callback | Callback\<{ state: [CallState](js-apis-call.md#CallState), number: string }\> | Yes| Callback used to return the result. For details, see [CallState](js-apis-call.md#CallState)
**number**: phone number.| + +**Example** + +``` +observer.on('callStateChange', value =>{ + console.log("on callStateChange, state:" + value.state + ", number:" + value.number); +}); +``` + + +## observer.on('callStateChange') + +on(type: 'callStateChange', options: { slotId: number }, callback: Callback<{ state: [CallState](js-apis-call.md#CallState), number: string }>): void; + +Registers an observer for call status change events. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.READ_CALL_LOG + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes| Call status change event.| +| slotId | number | Yes| Card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| +| callback | Callback\<{ state: [CallState](js-apis-call.md#CallState), number: string }\> | Yes| Callback used to return the result. For details, see [CallState](js-apis-call.md#CallState)
**number**: phone number.| + +**Example** + +``` +observer.on('callStateChange', {slotId: 0}, value =>{ + console.log("on callStateChange, state:" + value.state + ", number:" + value.number); +}); +``` + + +## observer.off('callStateChange') + +off(type: 'callStateChange', callback?: Callback<{ state: [CallState](js-apis-call.md#CallState), number: string }>): void; + +Unregisters the observer for call status change events. This function uses an asynchronous callback to return the execution result. + +**Required permission**: ohos.permission.READ_CALL_LOG + +>**NOTE** +> +>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. + +**System capability**: SystemCapability.Telephony.StateRegistry + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | Yes| Call status change event.| +| callback | Callback\<{ state: [CallState](js-apis-call.md#CallState), number: string }\> | No| Callback used to return the result. For details, see [CallState](js-apis-call.md#CallState)
**number**: phone number.| + +**Example** + +``` +let callback = value => { + console.log("on callStateChange, state:" + value.state + ", number:" + value.number); +} +observer.on('callStateChange', callback); +// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. +observer.off('callStateChange', callback); +observer.off('callStateChange'); +``` diff --git a/en/application-dev/reference/apis/js-apis-sms.md b/en/application-dev/reference/apis/js-apis-sms.md index 65fcef6b4fb590a5ead28ede1f2f502f7bd2b513..b3cca70e284d04d0c3f4ad09dae27a42de549252 100644 --- a/en/application-dev/reference/apis/js-apis-sms.md +++ b/en/application-dev/reference/apis/js-apis-sms.md @@ -16,6 +16,8 @@ createMessage\(pdu: Array, specification: string, callback: AsyncCallba Creates an SMS message instance based on the protocol data unit (PDU) and the specified SMS protocol. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.SmsMms + **Parameters** | Name| Type| Mandatory| Description| @@ -42,6 +44,8 @@ createMessage\(pdu: Array, specification: string\): Promise\): void Obtains the default slot of the SIM card used to send SMS messages. This function uses an asynchronous callback to return the result. +**System capability**: SystemCapability.Telephony.SmsMms + **Parameters** | Name| Type| Mandatory| Description| | -------- | --------------------------- | ---- | ---------------------------------------- | -| callback | AsyncCallback<number> | Yes| Callback used to return the result,
- **0**: slot 1
- **1**: slot 2| +| callback | AsyncCallback<number> | Yes| Callback used to return the result.
- **0**: slot 1
- **1**: slot 2| **Example** @@ -129,6 +137,8 @@ getDefaultSmsSlotId\(\): Promise Obtains the default slot of the SIM card used to send SMS messages. This function uses a promise to return the result. +**System capability**: SystemCapability.Telephony.SmsMms + **Return value** | Type| Description| @@ -153,7 +163,9 @@ setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback\): Sets the short message service center (SMSC) address. This function uses an asynchronous callback to return the result. -Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission. +**Required permission**: ohos.permission.SET_TELEPHONY_STATE (a system permission) + +**System capability**: SystemCapability.Telephony.SmsMms **Parameters** @@ -180,7 +192,9 @@ setSmscAddr\(slotId: number, smscAddr: string\): Promise Sets the SMSC address. This function uses a promise to return the result. -Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission. +**Required permission**: ohos.permission.SET_TELEPHONY_STATE (a system permission) + +**System capability**: SystemCapability.Telephony.SmsMms **Parameters** @@ -215,7 +229,9 @@ getSmscAddr\(slotId: number, callback: AsyncCallback\): void Obtains the SMSC address. This function uses an asynchronous callback to return the result. -Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. +**Required permission**: ohos.permission.GET_TELEPHONY_STATE (a system permission) + +**System capability**: SystemCapability.Telephony.SmsMms **Parameters** @@ -240,7 +256,9 @@ getSmscAddr\(slotId: number\): Promise Obtains the SMSC address. This function uses a promise to return the result. -Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. +**Required permission**: ohos.permission.GET_TELEPHONY_STATE (a system permission) + +**System capability**: SystemCapability.Telephony.SmsMms **Parameters** @@ -271,6 +289,8 @@ promise.then(data => { Defines an SMS message instance. +**System capability**: SystemCapability.Telephony.SmsMms + | Variable| Type| Description| | ------------------------ | --------------------------------------- | ------------------------------------------------------------ | | emailAddress | string | Email address.| @@ -295,12 +315,12 @@ Defines an SMS message instance. Enumerates SMS message types. | Variable| Value| Description| -| ---------------- | ---- | ---------------------------------------- | -| UNKNOWN | 0 | Unknown type.| -| INSTANT_MESSAGE | 1 | Instant message, which is displayed immediately after being received.| -| OPTIONAL_MESSAGE | 2 | Message stored in the device or SIM card.| -| SIM_MESSAGE | 3 | Message containing SIM card information, which is to be stored in the SIM card.| -| FORWARD_MESSAGE | 4 | Message to be forwarded to another device.| +| ---------------- | ---- | ------------------------------------------------------------ | +| UNKNOWN | 0 | Unknown type.
**System capability**: SystemCapability.Telephony.SmsMms| +| INSTANT_MESSAGE | 1 | Instant message, which is displayed immediately after being received.
**System capability**: SystemCapability.Telephony.SmsMms| +| OPTIONAL_MESSAGE | 2 | Message stored in the device or SIM card.
**System capability**: SystemCapability.Telephony.SmsMms| +| SIM_MESSAGE | 3 | Message containing SIM card information, which is to be stored in the SIM card.
**System capability**: SystemCapability.Telephony.SmsMms| +| FORWARD_MESSAGE | 4 | Message to be forwarded to another device.
**System capability**: SystemCapability.Telephony.SmsMms| ## SendMessageOptions @@ -309,11 +329,13 @@ Provides the options (including callbacks) for sending an SMS message. For example, you can specify the SMS message type by the optional parameter **content**. +**System capability**: SystemCapability.Telephony.SmsMms + | Name| Type| Mandatory| Description| | ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | slotId | number | Yes| Slot ID of the SIM card used for sending SMS messages:
- **0**: slot 1
- **1**: slot 2| | destinationHost | string | Yes| Destination address of the SMS message.| -| content | string \| Array<number> | Yes| SMS message type. If the content is comprised of character strings, the SMS message is a text message. If the content is comprised of byte arrays, the SMS message is a data message.| +| content | string \| Array<number> | Yes| SMS message type. If the content is composed of character strings, the SMS message is a text message. If the content is composed of byte arrays, the SMS message is a data message.| | serviceCenter | string | No| SMSC address. By default, the SMSC address in the SIM card is used.| | destinationPort | number | No| Destination port of the SMS message. This parameter is mandatory only for a data message. Otherwise, it is optional.| | sendCallback | AsyncCallback<[ISendShortMessageCallback](#ISendShortMessageCallback)> | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).| @@ -322,7 +344,9 @@ For example, you can specify the SMS message type by the optional parameter **co ## ISendShortMessageCallback -Provides the callback for the SMS message delivery report. It consists of three parts: SMS message sending result, URI for storing the sent SMS message, and whether the SMS message is the last part of a long SMS message. +Provides the callback for the SMS message sending result. It consists of three parts: SMS message sending result, URI for storing the sent SMS message, and whether the SMS message is the last part of a long SMS message. + +**System capability**: SystemCapability.Telephony.SmsMms | Name| Type| Mandatory| Description| | ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | @@ -333,7 +357,9 @@ Provides the callback for the SMS message delivery report. It consists of three ## IDeliveryShortMessageCallback -Provides the callback for the SMS message delivery report. Return the SMS delivery report. +Provides the callback for the SMS message sending result. Return the SMS delivery report. + +**System capability**: SystemCapability.Telephony.SmsMms | Name| Type| Mandatory| Description| | ------ | ------------------- | ---- | -------------- | @@ -344,6 +370,8 @@ Provides the callback for the SMS message delivery report. Return the SMS delive Enumerates SMS message sending results. +**System capability**: SystemCapability.Telephony.SmsMms + | Name| Value| Description| | ------------------------------------ | ---- | ------------------------------------------------------ | | SEND_SMS_SUCCESS | 0 | SMS message sent successfully.| diff --git a/en/application-dev/reference/apis/js-apis-telephony-data.md b/en/application-dev/reference/apis/js-apis-telephony-data.md new file mode 100644 index 0000000000000000000000000000000000000000..8cb2951bda1838891021ab653db926958859786c --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-telephony-data.md @@ -0,0 +1,289 @@ +# Cellular Data + +>**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 + +``` +import data from '@ohos.telephony.data'; +``` + +## data.getDefaultCellularDataSlotId + +getDefaultCellularDataSlotId(callback: AsyncCallback\): void + +Obtains the default SIM card used for mobile data. This function uses an asynchronous callback to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ----------------------- | ---- | ------------------------------------------ | +| callback | AsyncCallback\ | Yes| Callback used to return the result.
**0**: slot 1
**1**: slot 2| + +**Example** + +``` +data.getDefaultCellularDataSlotId((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## data.getDefaultCellularDataSlotId + +getDefaultCellularDataSlotId(): Promise\ + +Obtains the default SIM card used for mobile data. This function uses a promise to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Return value** + +| Type| Description| +| ----------------- | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result, wherein:
**0**: slot 1
**1**: slot 2| + +**Example** + +``` +let promise = data.getDefaultCellularDataSlotId(); +promise.then((data) => { + console.log(`test success, promise: data->${JSON.stringify(data)}`); +}).catch((err) => { + console.error(`test fail, promise: err->${JSON.stringify(err)}`); +}); +``` + +## data.getCellularDataFlowType + +getCellularDataFlowType(callback: AsyncCallback\): void + +Obtains the cellular data flow type, which can be uplink or downlink. This function uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ---------------------------------------------- | ---- | ---------- | +| callback | AsyncCallback\<[DataFlowType](#DataFlowType)\> | Yes| Callback used to return the result.| + +**Example** + +``` +data.getCellularDataFlowType((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## data.getCellularDataFlowType + +getCellularDataFlowType(): Promise\ + +Obtains the cellular data flow type, which can be uplink or downlink. This function uses a promise to return the result. + +**System capability**: SystemCapability.Telephony.CellularData + +**Return value** + +| Type| Description| +| ---------------------------------------- | ----------------------------------------------- | +| Promise\<[DataFlowType](#DataFlowType)\> | Promise used to return the result. | + +**Example** + +``` +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)}`); +}); +``` + +## data.getCellularDataState + +getCellularDataState(callback: AsyncCallback\): void + +Obtains the connection status of the packet switched (PS) domain. This function uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------------------------------------ | ---- | ---------- | +| callback | AsyncCallback\<[DataConnectState](#DataConnectState)\> | Yes| Callback used to return the result.| + +**Example** + +``` +data.getCellularDataState((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## data.getCellularDataState + +getCellularDataState(): Promise\ + +Obtains the connection status of the PS domain. This function uses a promise to return the result. + +**System capability**: SystemCapability.Telephony.CellularData + +**Return value** + +| Type| Description| +| ------------------------------------------------ | ------------------------------------- | +| Promise\<[DataConnectState](#DataConnectState)\> | Promise used to return the result.| + +**Example** + +``` +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)}`); +}); +``` + +## data.isCellularDataEnabled + +isCellularDataEnabled(callback: AsyncCallback\): void + +Checks whether the cellular data service is enabled. This function uses an asynchronous callback to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------ | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback\ | Yes| Callback used to return the result.
**true**: The cellular data service is enabled.
**false**: The cellular data service is disabled.| + +**Example** + +``` +data.isCellularDataEnabled((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## data.isCellularDataEnabled + +isCellularDataEnabled(): Promise\ + +Checks whether the cellular data service is enabled. This function uses a promise to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Return value** + +| Type| Description| +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result, wherein:
**true**: The cellular data service is enabled.
**false**: The cellular data service is disabled.| + +**Example** + +``` +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)}`); +}); +``` + +## data.isCellularDataRoamingEnabled + +isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback\): void + +Checks whether roaming is enabled for the cellular data service. This function uses an asynchronous callback to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| -------- | ------------------------ | ---- | ------------------------------------------------------------ | +| slotId | number | Yes| Card slot ID. The options are as follows:
**0**: slot 1
**1**: slot 2| +| callback | AsyncCallback\ | Yes| Callback used to return the result.
**true**: Roaming is enabled for the cellular data service.
**false**: Roaming is disabled for the cellular data service.| + +**Example** + +``` +data.isCellularDataRoamingEnabled(0,(err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + +## data.isCellularDataRoamingEnabled + +isCellularDataRoamingEnabled(slotId: number): Promise\ + +Checks whether roaming is enabled for the cellular data service. This method uses a promise to return the result. + +**Required permission**: ohos.permission.GET_NETWORK_INFO + +**System capability**: SystemCapability.Telephony.CellularData + +**Parameters** + +| Name| Type| Mandatory| Description| +| ------ | ------ | ---- | ---------------------------------------- | +| slotId | number | Yes| Card slot ID. The options are as follows:
**0**: slot 1
**1**: slot 2| + +**Return value** + +| Type| Description| +| ------------------ | ------------------------------------------------------------ | +| Promise\ | Promise used to return the result, wherein:
**true**: Roaming is enabled for the cellular data service.
**false**: Roaming is disabled for the cellular data service.| + +**Example** + +``` +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)}`); +}); +``` + +## DataFlowType + + Defines the cellular data flow type. + +| Name| Value| Description| +| ------ | ---------------------- | ------------------------------------------------------------ | +| 0 | DATA_FLOW_TYPE_NONE | No uplink or downlink data is available.
**System capability**: SystemCapability.Telephony.CellularData| +| 1 | DATA_FLOW_TYPE_DOWN | Only the downlink data is available.
**System capability**: SystemCapability.Telephony.CellularData| +| 2 | DATA_FLOW_TYPE_UP | Only the uplink data is available.
**System capability**: SystemCapability.Telephony.CellularData| +| 3 | DATA_FLOW_TYPE_UP_DOWN | Both uplink data and downlink data are available.
**System capability**: SystemCapability.Telephony.CellularData| +| 4 | DATA_FLOW_TYPE_DORMANT | No uplink or downlink data is available because the lower-layer link is in the dormant state.
**System capability**: SystemCapability.Telephony.CellularData| + +## DataConnectState + + Describes the connection status of a cellular data link. + +| Name| Value| Description| +| ------ | ----------------------- | ------------------------------------------------------------ | +| -1 | DATA_STATE_UNKNOWN| The status of the cellular data link is unknown.
**System capability**: SystemCapability.Telephony.CellularData| +| 0 | DATA_STATE_DISCONNECTED | The cellular data link is disconnected.
**System capability**: SystemCapability.Telephony.CellularData| +| 1 | DATA_STATE_CONNECTING | The cellular data link is being connected.
**System capability**: SystemCapability.Telephony.CellularData| +| 2 | DATA_STATE_CONNECTED | The cellular data link is connected.
**System capability**: SystemCapability.Telephony.CellularData| +| 3 | DATA_STATE_SUSPENDED | The cellular data link is suspended.
**System capability**: SystemCapability.Telephony.CellularData|