提交 26129356 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 c7ec364f
...@@ -17,7 +17,9 @@ dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void ...@@ -17,7 +17,9 @@ dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Initiates a call. This function uses an asynchronous callback to return the execution result. 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** **Parameters**
...@@ -41,7 +43,9 @@ dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean ...@@ -41,7 +43,9 @@ dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean
Initiates a call. You can set call options as needed. This function uses an asynchronous callback to return the execution result. Initiates a call. You can set call options as needed. 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** **Parameters**
...@@ -68,7 +72,9 @@ dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\> ...@@ -68,7 +72,9 @@ dial\(phoneNumber: string, options?: DialOptions\): Promise<boolean\>
Initiates a call. You can set call options as needed. This function uses a promise to return the execution result. 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** **Parameters**
...@@ -102,6 +108,8 @@ hasCall\(callback: AsyncCallback<boolean\>\): void ...@@ -102,6 +108,8 @@ hasCall\(callback: AsyncCallback<boolean\>\): void
Checks whether a call is in progress. This function uses an asynchronous callback to return the result. Checks whether a call is in progress. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -123,6 +131,8 @@ hasCall\(\): Promise<boolean\> ...@@ -123,6 +131,8 @@ hasCall\(\): Promise<boolean\>
Checks whether a call is in progress. This function uses a promise to return the result. Checks whether a call is in progress. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -147,6 +157,8 @@ getCallState\(callback: AsyncCallback<CallState\>\): void ...@@ -147,6 +157,8 @@ getCallState\(callback: AsyncCallback<CallState\>\): void
Obtains the call status. This function uses an asynchronous callback to return the result. Obtains the call status. This function uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -168,6 +180,8 @@ getCallState\(\): Promise<CallState\> ...@@ -168,6 +180,8 @@ getCallState\(\): Promise<CallState\>
Obtains the call status. This function uses a promise to return the result. Obtains the call status. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -191,6 +205,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\) ...@@ -191,6 +205,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\)
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. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -213,6 +229,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, ca ...@@ -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. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -236,6 +254,8 @@ isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): ...@@ -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. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -266,6 +286,8 @@ formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void ...@@ -266,6 +286,8 @@ formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void
Formats a phone number based on the specified ISO country code. This function uses an asynchronous callback to return the result. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -288,6 +310,8 @@ formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: ...@@ -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. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -313,6 +337,8 @@ formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise ...@@ -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. Formats a phone number based on specified formatting options. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -349,6 +375,8 @@ The phone number must match the specified country code. For example, for a China ...@@ -349,6 +375,8 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported. All country codes are supported.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -378,6 +406,8 @@ The phone number must match the specified country code. For example, for a China ...@@ -378,6 +406,8 @@ The phone number must match the specified country code. For example, for a China
All country codes are supported. All country codes are supported.
**System capability**: SystemCapability.Telephony.CallManager
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -407,30 +437,40 @@ promise.then(data => { ...@@ -407,30 +437,40 @@ promise.then(data => {
## DialOptions<a name=DialOptions></a> ## DialOptions<a name=DialOptions></a>
Provides an option for determining whether a call is a video call. 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: <br/> - **true**: video call <br/> - **false**: voice call| | extras | boolean | No| Indication of a video call. The options are as follows: <br/> - **true**: video call <br/> - **false**: voice call|
## CallState<a name=CallState></a> ## CallState<a name=CallState></a>
Enumerates call states. Enumerates call states.
| Variable| Value| Description| | Variable| Value| Description|
| ------------------ | ---- | ------------------------------------------------------------ | | ------------------ | ---- | ------------------------------------------------------------ |
| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.| | CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown. <br />**System capability**: SystemCapability.Telephony.CallManager|
| CALL_STATE_IDLE | 0 | No call is in progress.| | CALL_STATE_IDLE | 0 | No call is in progress. <br />**System capability**: SystemCapability.Telephony.CallManager|
| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.| | CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state. <br />**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.| | CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting. <br />**System capability**: SystemCapability.Telephony.CallManager|
## EmergencyNumberOptions<sup>7+</sup><a name=EmergencyNumberOptions></a> ## EmergencyNumberOptions<sup>7+</sup><a name=EmergencyNumberOptions></a>
Provides an option for determining whether a number is an emergency number for the SIM card in the specified slot. 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.<br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | No| SIM card slot ID.<br/> - **0**: slot 1 <br/> - **1**: slot 2|
## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a> ## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a>
Provides an option for number formatting. 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**.| | countryCode | string | No| Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|
# 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')<a name=observer.on.networkStateChange-callback></a>
on\(type: \'networkStateChange\', callback: Callback<NetworkState\>\): 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')<a name=observer.on.networkStateChange.options-callback></a>
on\(type: \'networkStateChange\', options: { slotId: number }, callback: Callback<NetworkState\>\): 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: <br/> - **0**: slot 1 <br/> - **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')<a name=observer.off.networkStateChange-callback></a>
off\(type: \'networkStateChange\', callback?: Callback<NetworkState\>\): 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')<a name=observer.on.signalInfoChange-callback></a>
on\(type: \'signalInfoChange\', callback: Callback<Array<SignalInformation\>\>): 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<Array<[SignalInformation](js-apis-radio.md#SignalInformation)\>\> | 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')<a name=observer.on.signalInfoChange.options-callback></a>
on\(type: \'signalInfoChange\', options: { slotId: number }, callback: Callback<Array<SignalInformation\>\>): 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: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| callback | Callback<Array<[SignalInformation](js-apis-radio.md#SignalInformation)\>\> | 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')<a name=observer.off.signalInfoChange-callback></a>
off\(type: \'signalInfoChange\', callback?: Callback<Array<SignalInformation\>\>): 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<Array<[SignalInformation](js-apis-radio.md#SignalInformation)\>\> | 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')<a name=observer.on.callStateChange-callback></a>
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)<br />**number**: phone number.|
**Example**
```
observer.on('callStateChange', value =>{
console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
});
```
## observer.on('callStateChange')<a name=observer.on.callStateChange.options-callback></a>
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: <br/> - **0**: slot 1<br/> - **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)<br />**number**: phone number.|
**Example**
```
observer.on('callStateChange', {slotId: 0}, value =>{
console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
});
```
## observer.off('callStateChange')<a name=observer.off.callStateChange-callback></a>
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)<br />**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');
```
...@@ -16,6 +16,8 @@ createMessage\(pdu: Array<number\>, specification: string, callback: AsyncCallba ...@@ -16,6 +16,8 @@ createMessage\(pdu: Array<number\>, 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. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -42,6 +44,8 @@ createMessage\(pdu: Array<number\>, specification: string\): Promise<ShortMessag ...@@ -42,6 +44,8 @@ createMessage\(pdu: Array<number\>, specification: string\): Promise<ShortMessag
Creates an SMS message instance based on the PDU and the specified SMS protocol. This function uses a promise to return the result. Creates an SMS message instance based on the PDU and the specified SMS protocol. This function uses a promise to return the result.
**System capability**: SystemCapability.Telephony.SmsMms
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
...@@ -75,7 +79,9 @@ sendMessage(options: SendMessageOptions): void ...@@ -75,7 +79,9 @@ sendMessage(options: SendMessageOptions): void
Sends an SMS message. Sends an SMS message.
Before using this API, you must declare the **ohos.permission.SEND_MESSAGES** permission. **Required permission**: ohos.permission.SEND_MESSAGES
**System capability**: SystemCapability.Telephony.SmsMms
**Parameters** **Parameters**
...@@ -108,11 +114,13 @@ getDefaultSmsSlotId\(callback: AsyncCallback<number\>\): void ...@@ -108,11 +114,13 @@ getDefaultSmsSlotId\(callback: AsyncCallback<number\>\): void
Obtains the default slot of the SIM card used to send SMS messages. This function uses an asynchronous callback to return the result. 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** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result, <br/> - **0**: slot 1 <br/> - **1**: slot 2| | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. <br/> - **0**: slot 1 <br/> - **1**: slot 2|
**Example** **Example**
...@@ -129,6 +137,8 @@ getDefaultSmsSlotId\(\): Promise<number\> ...@@ -129,6 +137,8 @@ getDefaultSmsSlotId\(\): Promise<number\>
Obtains the default slot of the SIM card used to send SMS messages. This function uses a promise to return the result. 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** **Return value**
| Type| Description| | Type| Description|
...@@ -153,7 +163,9 @@ setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback<void\>\): ...@@ -153,7 +163,9 @@ setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback<void\>\):
Sets the short message service center (SMSC) address. This function uses an asynchronous callback to return the result. 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** **Parameters**
...@@ -180,7 +192,9 @@ setSmscAddr\(slotId: number, smscAddr: string\): Promise<void\> ...@@ -180,7 +192,9 @@ setSmscAddr\(slotId: number, smscAddr: string\): Promise<void\>
Sets the SMSC address. This function uses a promise to return the result. 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** **Parameters**
...@@ -215,7 +229,9 @@ getSmscAddr\(slotId: number, callback: AsyncCallback<string\>\): void ...@@ -215,7 +229,9 @@ getSmscAddr\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the SMSC address. This function uses an asynchronous callback to return the result. 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** **Parameters**
...@@ -240,7 +256,9 @@ getSmscAddr\(slotId: number\): Promise<string\> ...@@ -240,7 +256,9 @@ getSmscAddr\(slotId: number\): Promise<string\>
Obtains the SMSC address. This function uses a promise to return the result. 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** **Parameters**
...@@ -271,6 +289,8 @@ promise.then(data => { ...@@ -271,6 +289,8 @@ promise.then(data => {
Defines an SMS message instance. Defines an SMS message instance.
**System capability**: SystemCapability.Telephony.SmsMms
| Variable| Type| Description| | Variable| Type| Description|
| ------------------------ | --------------------------------------- | ------------------------------------------------------------ | | ------------------------ | --------------------------------------- | ------------------------------------------------------------ |
| emailAddress | string | Email address.| | emailAddress | string | Email address.|
...@@ -295,12 +315,12 @@ Defines an SMS message instance. ...@@ -295,12 +315,12 @@ Defines an SMS message instance.
Enumerates SMS message types. Enumerates SMS message types.
| Variable| Value| Description| | Variable| Value| Description|
| ---------------- | ---- | ---------------------------------------- | | ---------------- | ---- | ------------------------------------------------------------ |
| UNKNOWN | 0 | Unknown type.| | UNKNOWN | 0 | Unknown type. <br />**System capability**: SystemCapability.Telephony.SmsMms|
| INSTANT_MESSAGE | 1 | Instant message, which is displayed immediately after being received.| | INSTANT_MESSAGE | 1 | Instant message, which is displayed immediately after being received. <br />**System capability**: SystemCapability.Telephony.SmsMms|
| OPTIONAL_MESSAGE | 2 | Message stored in the device or SIM card.| | OPTIONAL_MESSAGE | 2 | Message stored in the device or SIM card. <br />**System capability**: SystemCapability.Telephony.SmsMms|
| SIM_MESSAGE | 3 | Message containing SIM card information, which is to be stored in the SIM card.| | SIM_MESSAGE | 3 | Message containing SIM card information, which is to be stored in the SIM card. <br />**System capability**: SystemCapability.Telephony.SmsMms|
| FORWARD_MESSAGE | 4 | Message to be forwarded to another device.| | FORWARD_MESSAGE | 4 | Message to be forwarded to another device. <br />**System capability**: SystemCapability.Telephony.SmsMms|
## SendMessageOptions<a name=SendMessageOptions></a> ## SendMessageOptions<a name=SendMessageOptions></a>
...@@ -309,11 +329,13 @@ Provides the options (including callbacks) for sending an SMS message. ...@@ -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**. For example, you can specify the SMS message type by the optional parameter **content**.
**System capability**: SystemCapability.Telephony.SmsMms
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| slotId | number | Yes| Slot ID of the SIM card used for sending SMS messages: <br/> - **0**: slot 1 <br/> - **1**: slot 2| | slotId | number | Yes| Slot ID of the SIM card used for sending SMS messages: <br/> - **0**: slot 1 <br/> - **1**: slot 2|
| destinationHost | string | Yes| Destination address of the SMS message.| | destinationHost | string | Yes| Destination address of the SMS message.|
| content | string \| Array&lt;number&gt; | 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&lt;number&gt; | 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.| | 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.| | destinationPort | number | No| Destination port of the SMS message. This parameter is mandatory only for a data message. Otherwise, it is optional.|
| sendCallback | AsyncCallback&lt;[ISendShortMessageCallback](#ISendShortMessageCallback)&gt; | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).| | sendCallback | AsyncCallback&lt;[ISendShortMessageCallback](#ISendShortMessageCallback)&gt; | 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 ...@@ -322,7 +344,9 @@ For example, you can specify the SMS message type by the optional parameter **co
## ISendShortMessageCallback<a name=ISendShortMessageCallback></a> ## ISendShortMessageCallback<a name=ISendShortMessageCallback></a>
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| | Name| Type| Mandatory| Description|
| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ | | ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
...@@ -333,7 +357,9 @@ Provides the callback for the SMS message delivery report. It consists of three ...@@ -333,7 +357,9 @@ Provides the callback for the SMS message delivery report. It consists of three
## IDeliveryShortMessageCallback<a name=IDeliveryShortMessageCallback></a> ## IDeliveryShortMessageCallback<a name=IDeliveryShortMessageCallback></a>
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| | Name| Type| Mandatory| Description|
| ------ | ------------------- | ---- | -------------- | | ------ | ------------------- | ---- | -------------- |
...@@ -344,6 +370,8 @@ Provides the callback for the SMS message delivery report. Return the SMS delive ...@@ -344,6 +370,8 @@ Provides the callback for the SMS message delivery report. Return the SMS delive
Enumerates SMS message sending results. Enumerates SMS message sending results.
**System capability**: SystemCapability.Telephony.SmsMms
| Name| Value| Description| | Name| Value| Description|
| ------------------------------------ | ---- | ------------------------------------------------------ | | ------------------------------------ | ---- | ------------------------------------------------------ |
| SEND_SMS_SUCCESS | 0 | SMS message sent successfully.| | SEND_SMS_SUCCESS | 0 | SMS message sent successfully.|
......
# 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<a name=data.getDefaultCellularDataSlotId-callback></a>
getDefaultCellularDataSlotId(callback: AsyncCallback\<number\>): 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\<number\> | Yes| Callback used to return the result. <br /> **0**: slot 1 <br/>**1**: slot 2|
**Example**
```
data.getDefaultCellularDataSlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## data.getDefaultCellularDataSlotId<a name=data.getDefaultCellularDataSlotId-promise></a>
getDefaultCellularDataSlotId(): Promise\<number\>
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\<number\> | Promise used to return the result, wherein: <br />**0**: slot 1 <br/>**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<a name=data.getCellularDataFlowType-callback></a>
getCellularDataFlowType(callback: AsyncCallback\<DataFlowType\>): 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<a name=data.getCellularDataFlowType-promise></a>
getCellularDataFlowType(): Promise\<DataFlowType\>
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<a name=data.getCellularDataState-callback></a>
getCellularDataState(callback: AsyncCallback\<DataConnectState\>): 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<a name=data.getCellularDataState-promise></a>
getCellularDataState(): Promise\<DataConnectState\>
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<a name=data.isCellularDataEnabled-callback></a>
isCellularDataEnabled(callback: AsyncCallback\<boolean\>): 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\<boolean\> | Yes| Callback used to return the result. <br />**true**: The cellular data service is enabled. <br />**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<a name=data.isCellularDataEnabled-promise></a>
isCellularDataEnabled(): Promise\<boolean\>
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\<boolean\> | Promise used to return the result, wherein: <br />**true**: The cellular data service is enabled. <br />**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<a name=data.isCellularDataRoamingEnabled-callback></a>
isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback\<boolean\>): 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: <br />**0**: slot 1 <br />**1**: slot 2|
| 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.|
**Example**
```
data.isCellularDataRoamingEnabled(0,(err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## data.isCellularDataRoamingEnabled<a name=data.isCellularDataRoamingEnabled-promise></a>
isCellularDataRoamingEnabled(slotId: number): Promise\<boolean\>
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: <br />**0**: slot 1 <br/>**1**: slot 2|
**Return value**
| Type| Description|
| ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result, wherein: <br />**true**: Roaming is enabled for the cellular data service. <br />**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<a name=DataFlowType></a>
Defines the cellular data flow type.
| Name| Value| Description|
| ------ | ---------------------- | ------------------------------------------------------------ |
| 0 | DATA_FLOW_TYPE_NONE | No uplink or downlink data is available. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 1 | DATA_FLOW_TYPE_DOWN | Only the downlink data is available. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 2 | DATA_FLOW_TYPE_UP | Only the uplink data is available. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 3 | DATA_FLOW_TYPE_UP_DOWN | Both uplink data and downlink data are available. <br />**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. <br />**System capability**: SystemCapability.Telephony.CellularData|
## DataConnectState<a name=DataConnectState></a>
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. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 0 | DATA_STATE_DISCONNECTED | The cellular data link is disconnected. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 1 | DATA_STATE_CONNECTING | The cellular data link is being connected. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 2 | DATA_STATE_CONNECTED | The cellular data link is connected. <br />**System capability**: SystemCapability.Telephony.CellularData|
| 3 | DATA_STATE_SUSPENDED | The cellular data link is suspended. <br />**System capability**: SystemCapability.Telephony.CellularData|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册