提交 b47f8c0a 编写于 作者: S shawn_he

update docs

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 3ebd1198
# Call
>**Note:**
>
>- The APIs of this module are supported since API version 6.
>
>- APIs marked with <sup>7+</sup> are supported since API version 7.
## Modules to Import
```
import call from '@ohos.telephony.call';
```
## call.dial<a name=call.dial-callback1></a>
dial\(phoneNumber: string, callback: AsyncCallback<boolean\>\): 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).
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| phoneNumber | string | Yes|Phone number.|
| callback |AsyncCallback&lt;boolean&gt;|Yes|Callback used to return the result.<br/> - **true**: success <br/> -**false**: failure|
- Example
```
call.dial("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<a name=call.dial-callback2></a>
dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback<boolean\>\): void
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).
- Parameters
| Parameter| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: success <br/> -**false**: failure|
- Example
```
call.dial("138xxxxxxxx", {
extras: false
}, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.dial<a name=call.dial-promise></a>
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.
Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission).
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ----------- | ---- | ------------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| options | DialOptions | Yes| Call options. For details, see [DialOptions](#DialOptions).|
- Return values
| Type| Description|
| ---------------------- | --------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
- Example
```
let promise = call.dial("138xxxxxxxx", {
extras: false
});
promise.then(data => {
console.log(`dial success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`dial fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.hasCall<a name=call.hasCall-callback></a>
hasCall\(callback: AsyncCallback<boolean\>\): void
Checks whether a call is in progress. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result: <br/> - **true**: A call is in progress. <br/> - **false**: No call is in progress. |
- Example
```
call.hasCall((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.hasCall<a name=call.hasCall-promise></a>
hasCall\(\): Promise<boolean\>
Checks whether a call is in progress. This function uses a promise to return the result.
- Return values
| Type| Description|
| ---------------------- | --------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
- Example
```
let promise = call.hasCall();
promise.then(data => {
console.log(`hasCall success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`hasCall fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.getCallState<a name=call.getCallState-callback></a>
getCallState\(callback: AsyncCallback<CallState\>\): void
Obtains the call status. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback&lt;[CallState](#CallState)&gt; | Yes| Callback used to return the result.|
- Example
```
call.getCallState((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.getCallState<a name="call.getCallState-promise"></a>
getCallState\(\): Promise<CallState\>
Obtains the call status. This function uses a promise to return the result.
- Return values
| Type| Description|
| -------------------------------------- | ----------------------------------------- |
| Promise&lt;[CallState](#CallState)&gt; | Promise used to return the result.|
- Example
```
let promise = call.getCallState();
promise.then(data => {
console.log(`getCallState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`getCallState fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback1></a>
isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback<boolean\>\): void
Checks whether the call number is an emergency number. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.|
- Example
```
call.isEmergencyPhoneNumber("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-callback2></a>
isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback<boolean\>\): void
Checks whether the call number is an emergency number. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result.<br/> - **true**: The called number is an emergency number. <br/> - **false**: The called number is not an emergency number.|
- Example
```
call.isEmergencyPhoneNumber("112", {slotId: 1}, (err, value) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.isEmergencyPhoneNumber<sup>7+</sup><a name=call.isEmergencyPhoneNumber-promise></a>
isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise<boolean\>
Checks whether the call number is an emergency number. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ---------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| options | EmergencyNumberOptions | Yes| Emergency number options defined in [EmergencyNumberOptions](#EmergencyNumberOptions).|
- Return values
| Type| Description|
| ---------------------- | --------------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
- Example
```
let promise = call.isEmergencyPhoneNumber("138xxxxxxxx", {slotId: 1});
promise.then(data => {
console.log(`isEmergencyPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`isEmergencyPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback1></a>
formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback<string\>\): void
Formats a phone number. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example
```
call.formatPhoneNumber("138xxxxxxxx", (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-callback2></a>
formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback<string\>\): void
Formats a phone number based on specified formatting options. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example
```
call.formatPhoneNumber("138xxxxxxxx",{
countryCode: "CN"
}, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.formatPhoneNumber<sup>7+</sup><a name=call.formatPhoneNumber-promise></a>
formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise<string\>
Formats a phone number based on specified formatting options. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ------------------- | ---- | ------------------------------------------------------------ |
| phoneNumber | string | Yes| Phone number.|
| options | NumberFormatOptions | Yes| Number formatting options defined in [NumberFormatOptions](#NumberFormatOptions).|
- Return values
| Type| Description|
| --------------------- | ------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
- Example
```
let promise = call.formatPhoneNumber("138xxxxxxxx", {
countryCode: "CN"
});
promise.then(data => {
console.log(`formatPhoneNumber success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`formatPhoneNumber fail, promise: err->${JSON.stringify(err)}`);
});
```
## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-callback></a>
formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback<string\>\): void
Converts a phone number into the E.164 format. This function uses an asynchronous callback to return the result.
The phone number must match the specified country code. For example, for a China phone number, the country code must be **CN**. Otherwise, **null** will be returned.
All country codes are supported.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | --------------------------- | ---- | ----------------------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example
```
call.formatPhoneNumberToE164("138xxxxxxxx",{
countryCode: "CN"
}, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## call.formatPhoneNumberToE164<sup>7+</sup><a name=call.formatPhoneNumberToE164-promise></a>
formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise<string\>
Converts a phone number into the E.164 format. This function uses a promise to return the result.
The phone number must match the specified country code. For example, for a China phone number, the country code must be **CN**. Otherwise, **null** will be returned.
All country codes are supported.
- Parameters
| Name| Type| Mandatory| Description|
| ----------- | ------ | ---- | ---------------------------------------- |
| phoneNumber | string | Yes| Phone number.|
| countryCode | string | Yes| Country code, for example, **CN** (China). All country codes are supported.|
- Return values
| Type| Description|
| --------------------- | ------------------------------------------------------------ |
| Promise&lt;string&gt; | Promise used to return the result.|
- Example
```
let promise = call.formatPhoneNumberToE164("138xxxxxxxx", {
countryCode: "CN"
});
promise.then(data => {
console.log(`formatPhoneNumberToE164 success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`formatPhoneNumberToE164 fail, promise: err->${JSON.stringify(err)}`);
});
```
## DialOptions<a name=DialOptions></a>
Provides an option for determining whether a call is a video call.
| 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|
## CallState<a name=CallState></a>
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.|
## 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.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| slotId | number | No|SIM card slot ID.<br/> - **0**: slot 1 <br/> - **1**: slot 2|
## NumberFormatOptions<sup>7+</sup><a name=NumberFormatOptions></a>
Provides an option for number formatting.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| countryCode | string | No|Country code, for example, **CN** (China). All country codes are supported. The default value is **CN**.|
# Radio
>**Note:**
>
>- The APIs of this module are supported since API version 6.
>- APIs marked with <sup>7+</sup> are supported since API version 7.
## Modules to Import
```
import radio from '@ohos.telephony.radio'
```
## radio.getRadioTech<a name=radio.getRadioTech-callback></a>
getRadioTech\(slotId: number, callback: AsyncCallback<\{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology\}\>\): void
Obtains the radio access technologies (RATs) used by the CS and PS domains. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech:[RadioTechnology](#RadioTechnology)}\> | Yes| Callback used to return the result.|
- Example
```
let slotId = 0;
radio.getRadioTech(slotId, (err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getRadioTech<a name=radio.getRadioTech-promise></a>
getRadioTech\(slotId: number\): Promise<\{psRadioTech: RadioTechnology, csRadioTech: RadioTechnology\}\>
Obtains the RAT used by the CS and PS domains. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| ------------------------------------------------------------ | ----------------------------------------------- |
| Promise<{psRadioTech: [RadioTechnology](#RadioTechnology), csRadioTech: [RadioTechnology](#RadioTechnology)}> | Promise used to return the result.|
- Example
```
let slotId = 0;
let promise = radio.getRadioTech(slotId);
promise.then(data => {
console.log(`getRadioTech success, data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getRadioTech fail, err->${JSON.stringify(err)}`);
});
```
## radio.getNetworkState<a name=radio.getNetworkState-callback1></a>
getNetworkState\(callback: AsyncCallback<NetworkState\>\): void
Obtains the network status. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ---------------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback used to return the result.|
- Example
```
radio.getNetworkState((err, data) =>{
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getNetworkState<a name=radio.getNetworkState-callback2></a>
getNetworkState\(slotId: number, callback: AsyncCallback<NetworkState\>\): void
Obtains the network status of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ---------------------------------------------- | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<[NetworkState](#NetworkState)\> | Yes| Callback used to return the result.|
- Example
```
let slotId = 0;
radio.getNetworkState(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getNetworkState<a name=radio.getNetworkState-promise></a>
getNetworkState\(slotId?: number\): Promise<NetworkState\>
Obtains the network status of the SIM card in the specified slot. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- |
| slotId | number | No| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| ---------------------------------------- | --------------------------- |
| Promise\<[NetworkState](#NetworkState)\> | Promise used to return the result.|
- Example
```
let slotId = 0;
let promise = radio.getNetworkState(slotId);
promise.then(data => {
console.log(`getNetworkState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getNetworkState fail, promise: err->${JSON.stringify(err)}`);
});
```
## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-callback></a>
getNetworkSelectionMode\(slotId: number, callback: AsyncCallback<NetworkSelectionMode\>\): void
Obtains the network selection mode of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Yes| Callback used to return the result.|
- Example
```
let slotId = 0;
radio.getNetworkSelectionMode(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getNetworkSelectionMode<a name=radio.getNetworkSelectionMode-promise></a>
getNetworkSelectionMode\(slotId: number\): Promise<NetworkSelectionMode\>
Obtains the network selection mode of the SIM card in the specified slot. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| -------------------------------------------------------- | ------------------------------- |
| Promise\<[NetworkSelectionMode](#NetworkSelectionMode)\> | Promise used to return the result.|
- Example
```
let slotId = 0;
let promise = radio.getNetworkSelectionMode(slotId);
promise.then(data => {
console.log(`getNetworkSelectionMode success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getNetworkSelectionMode fail, promise: err->${JSON.stringify(err)}`);
});
```
## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-callback></a>
getISOCountryCodeForNetwork\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ----------------------- | ---- | ---------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).|
- Example
```
let slotId = 0;
radio.getISOCountryCodeForNetwork(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getISOCountryCodeForNetwork<sup>7+</sup><a name=radio.getISOCountryCodeForNetwork-promise></a>
getISOCountryCodeForNetwork\(slotId: number\): Promise<string\>
Obtains the ISO country code of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result, which is an ISO country code, for example, **CN** (China).|
- Example
```
let slotId = 0;
let promise = radio.getISOCountryCodeForNetwork(slotId);
promise.then(data => {
console.log(`getISOCountryCodeForNetwork success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getISOCountryCodeForNetwork fail, promise: err->${JSON.stringify(err)}`);
});
```
## radio.getSignalInformation<a name=radio.getSignalInformation-callback></a>
getSignalInformation\(slotId: number, callback: AsyncCallback<Array<SignalInformation\>\>\): void
Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback\<Array\<[SignalInformation](#SignalInformation)\>\> | Yes| Callback used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.|
- Example
```
let slotId = 0;
radio.getSignalInformation(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.getSignalInformation<a name=radio.getSignalInformation-promise></a>
getSignalInformation\(slotId: number\): Promise<Array<SignalInformation\>\>
Obtains a list of signal strengths of the network with which the SIM card in the specified slot is registered. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | -------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Array\<[SignalInformation](#SignalInformation)\>\> | Promise used to return the result, which is a list of [SignalInformation](#SignalInformation) objects.|
- Example
```
let slotId = 0;
let promise = radio.getSignalInformation(slotId);
promise.then(data => {
console.log(`getSignalInformation success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`getSignalInformation fail, promise: err->${JSON.stringify(err)}`);
});
```
## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-callback></a>
isRadioOn\(callback: AsyncCallback<boolean\>\): void
Checks whether radio is turned on. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------------------------ | ---- | ------------------------------------------------------- |
| callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result. <br/> - **true**: Radio is turned on.<br/> - **false**: Radio is turned off.|
- Example
```
radio.isRadioOn((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## radio.isRadioOn<sup>7+</sup><a name=radio.isRadioOn-promise></a>
isRadioOn\(\): Promise<boolean\>
Checks whether radio is turned on. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_NETWORK\_INFO** permission.
- Return values
| Type| Description|
| ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result. <br/> - **true**: Radio is turned on.<br/> - **false**: Radio is turned off.|
- Example
```
let promise = radio.isRadioOn();
promise.then(data => {
console.log(`isRadioOn success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`isRadioOn fail, promise: err->${JSON.stringify(err)}`);
});
```
## RadioTechnology<a name=RadioTechnology></a>
Enumerates the RATs.
| Variable| Value| Description|
| ------------------------- | ---- | ------------------------------------------------------------ |
| RADIO_TECHNOLOGY_UNKNOWN | 0 | Unknown|
| RADIO_TECHNOLOGY_GSM | 1 | Global System for Mobile Communication (GSM)|
| RADIO_TECHNOLOGY_1XRTT | 2 | Single-Carrier Radio Transmission Technology (1XRTT)|
| RADIO_TECHNOLOGY_WCDMA | 3 | Wideband Code Division Multiple Access (WCDMA)|
| RADIO_TECHNOLOGY_HSPA | 4 | High Speed Packet Access (HSPA)|
| RADIO_TECHNOLOGY_HSPAP | 5 | Evolved High Speed Packet Access (HSPA+)|
| RADIO_TECHNOLOGY_TD_SCDMA | 6 | Time Division Synchronous Code Division Multiple Access (TD-SCDMA)|
| RADIO_TECHNOLOGY_EVDO | 7 | Evolution-Data Optimized (EVDO)|
| RADIO_TECHNOLOGY_EHRPD | 8 | Evolved High Rate Package Data (EHRPD)|
| RADIO_TECHNOLOGY_LTE | 9 | Long Term Evolution (LTE)|
| RADIO_TECHNOLOGY_LTE_CA | 10 | Long Term Evolution_Carrier Aggregation (LTE_CA)|
| RADIO_TECHNOLOGY_IWLAN | 11 | Industrial Wireless LAN (IWLAN)|
| RADIO_TECHNOLOGY_NR | 12 | New Radio (NR)|
## SignalInformation<a name=SignalInformation></a>
Defines the signal strength.
| Attribute| Type| Description|
| ----------- | --------------------------- | ------------------ |
| signalType | [NetworkType](#NetworkType) | Signal strength type.|
| signalLevel | number | Signal strength level.|
## NetworkType<a name=NetworkType></a>
Enumerates network types.
| Variable| Value| Description|
| -------------------- | ---- | ------------------------------------------------------------ |
| NETWORK_TYPE_UNKNOWN | 0 | Unknown|
| NETWORK_TYPE_GSM | 1 | GSM network|
| NETWORK_TYPE_CDMA | 2 | CDMA network|
| NETWORK_TYPE_WCDMA | 3 | WCDMA network|
| NETWORK_TYPE_TDSCDMA | 4 | TD-SCDMA network|
| NETWORK_TYPE_LTE | 5 | LTE network|
| NETWORK_TYPE_NR | 6 | 5G NR network|
## NetworkState<a name=NetworkState></a>
Defines the network registration status.
| Variable| Type| Description|
| ----------------- | --------------------- | ------------------------------ |
| longOperatorName | string | Long carrier name of the registered network.|
| shortOperatorName | string | Short carrier name of the registered network.|
| plmnNumeric | string | PLMN code of the registered network.|
| isRoaming | boolean | Whether the user is roaming.|
| regState | [RegState](#RegState) | Network registration status of the device.|
| nsaState | [NsaState](#NsaState) | NSA network registration status of the device.|
| isCaActive | boolean | Whether carrier aggregation (CA) is supported.|
| isEmergency | boolean | Whether only emergency calls are allowed.|
## RegState<a name=RegState></a>
Enumerates network registration states.
| Variable| Value| Description|
| ----------------------------- | ---- | -------------------------- |
| REG_STATE_NO_SERVICE | 0 | The device cannot use any service.|
| REG_STATE_IN_SERVICE | 1 | The device can use services normally. |
| REG_STATE_EMERGENCY_CALL_ONLY | 2 | The device can use only the emergency call service.|
| REG_STATE_POWER_OFF | 3 | The cellular radio service is disabled.|
## NsaState<a name=NsaState></a>
Enumerates NSA network states.
| Variable| Value| Description|
| -------------------------- | ---- | ---------------------------------------------------------- |
| NSA_STATE_NOT_SUPPORT | 1 | The device is in idle or connected state in an LTE cell that does not support NSA.|
| NSA_STATE_NO_DETECT | 2 | The device is in the idle state in an LTE cell that supports NSA but does not support NR coverage detection.|
| NSA_STATE_CONNECTED_DETECT | 3 | The device is connected to the LTE network in an LTE cell that supports NSA and NR coverage detection.|
| NSA_STATE_IDLE_DETECT | 4 | The device is in the idle state in an LTE cell that supports NSA and NR coverage detection.|
| NSA_STATE_DUAL_CONNECTED | 5 | The device is connected to the LTE/NR network in an LTE cell that supports NSA.|
| NSA_STATE_SA_ATTACHED | 6 | The device is idle or connected to the NG-RAN cell when being attached to the 5G Core.|
## NetworkSelectionMode<a name=NetworkSelectionMode></a>
Enumerates network selection modes.
| Variable| Value| Description|
| --------------------------- | ---- | -------------- |
| NETWORK_SELECTION_UNKNOWN | 0 | Unknown network selection mode.|
| NETWORK_SELECTION_AUTOMATIC | 1 | Automatic network selection mode.|
| NETWORK_SELECTION_MANUAL | 2 | Manual network selection mode.|
# SIM Management
>**Note:**
>
>- The APIs of this module are supported since API version 6.
>- APIs marked with <sup>7+</sup> are supported since API version 7.
## Modules to Import
```
import sim from '@ohos.telephony.sim';
```
## sim.getSimIccId<a name=sim.getSimIccId-callback></a>
getSimIccId\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the integrated circuit card identity (ICCID) of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- 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&lt;string&gt; | Yes| Callback used to return the result.|
- Example
```
sim.getSimIccId(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getSimIccId<a name=sim.getSimIccId-promise></a>
getSimIccId\(slotId: number\): Promise<string\>
Obtains the ICCID of the SIM card in the specified slot. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- 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 values
| Type| Description|
| --------------------- | ---------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
- Example
```
let promise = sim.getSimIccId(0);
promise.then(data => {
console.log(`getSimIccId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getSimIccId fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getDefaultVoiceSlotId<sup>7+</sup><a name= sim.getDefaultVoiceSlotId-callback></a>
getDefaultVoiceSlotId\(callback: AsyncCallback<number\>\): void
Obtains the default slot ID of the SIM card that provides voice services. This function uses an asynchronous callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result.|
- Example
```
sim.getDefaultVoiceSlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getDefaultVoiceSlotId<sup>7+</sup><a name=sim.getDefaultVoiceSlotId-promise></a>
getDefaultVoiceSlotId\(\): Promise<number\>
Obtains the default slot ID of the SIM card that provides voice services. This function uses a promise to return the result.
- Return values
| Type| Description|
| ----------------- | --------------------------------------- |
| Promise\<number\> | Promise used to return the result.|
- Example
```
let promise = sim.getDefaultVoiceSlotId();
promise.then(data => {
console.log(`getDefaultVoiceSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getDefaultVoiceSlotId fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-callback></a>
getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the ISO country code of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- 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\<string\> | Yes| Callback used to return the result, which is a country code, for example, **CN** (China).|
- Example
```
sim.getISOCountryCodeForSim(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getISOCountryCodeForSim<a name=sim.getISOCountryCodeForSim-promise></a>
getISOCountryCodeForSim\(slotId: number\): Promise<string\>
Obtains the ISO country code of the SIM card in the specified slot. This function uses a promise to return the result.
- 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 values
| Type| Description|
| ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result, which is a country code, for example, **CN** (China).|
- Example
```
let promise = sim.getISOCountryCodeForSim(0);
promise.then(data => {
console.log(`getISOCountryCodeForSim success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getISOCountryCodeForSim fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-callback></a>
getSimOperatorNumeric\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the public land mobile network (PLMN) ID of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- 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\<string\> | Yes| Callback used to return the result.|
- Example
```
sim.getSimOperatorNumeric(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getSimOperatorNumeric<a name=sim.getSimOperatorNumeric-promise></a>
getSimOperatorNumeric\(slotId: number\): Promise<string\>
Obtains the PLMN ID of the SIM card in the specified slot. This function uses a promise to return the result.
- 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 values
| Type| Description|
| ----------------- | ------------------------------------------------ |
| Promise\<string\> | Promise used to return the result.|
- Example
```
let promise = sim.getSimOperatorNumeric(0);
promise.then(data => {
console.log(`getSimOperatorNumeric success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getSimOperatorNumeric fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getSimSpn<a name=sim.getSimSpn-callback></a>
getSimSpn\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the service provider name (SPN) of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- 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\<string\> | Yes| Callback used to return the result.|
- Example
```
sim.getSimSpn(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getSimSpn<a name=sim.getSimSpn-promise></a>
getSimSpn\(slotId: number\): Promise<string\>
Obtains the SPN of the SIM card in the specified slot. This function uses a promise to return the result.
- 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 values
| Type| Description|
| ----------------- | ----------------------------------------- |
| Promise\<string\> | Promise used to return the result.|
- Example
```
let promise = sim.getSimSpn(0);
promise.then(data => {
console.log(`getSimSpn success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getSimSpn fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getSimState<a name=sim.getSimState-callback></a>
getSimState\(slotId: number, callback: AsyncCallback<SimState\>\): void
Obtains the status of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
- 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\<[SimState](#SimState)\> | Yes| Callback used to return the result. For details, see [SimState](#SimState).|
- Example
```
sim.getSimState(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getSimState<a name=sim.getSimState-promise></a>
getSimState\(slotId: number\): Promise<SimState\>
Obtains the status of the SIM card in the specified slot. This function uses a promise to return the result.
- 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 values
| Type| Description|
| -------------------------------- | ------------------------------------------ |
| Promise\<[SimState](#SimState)\> | Promise used to return the result.|
- Example
```
let promise = sim.getSimState(0);
promise.then(data => {
console.log(`getSimState success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getSimState fail, promise: err->${JSON.stringify(err)}`);
});
```
## sim.getSimGid1<a name=sim.getSimGid1-callback></a>
getSimGid1\(slotId: number, callback: AsyncCallback<string\>\): void
Obtains the group identifier level 1 (GID1) of the SIM card in the specified slot. This function uses an asynchronous callback to return the result.
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- 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\<string\> | Yes| Callback used to return the result.|
- Example
```
sim.getSimGid1(0, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sim.getSimGid1<a name=sim.getSimGid1-promise></a>
getSimGid1\(slotId: number\): Promise<string\>
Obtains the GID1 of the SIM card in the specified slot. This function uses a promise to return the result.
Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission.
- 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 values
| Type| Description|
| ----------------- | ------------------------------------------------------------ |
| Promise\<string\> | Promise used to return the result.|
- Example
```
let promise = sim.getSimGid1(0);
promise.then(data => {
console.log(`getSimGid1 success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.log(`getSimGid1 fail, promise: err->${JSON.stringify(err)}`);
});
```
## SimState<a name=SimState></a>
Enumerates SIM card states.
| Variable| Description|
| --------------------- | ---------------------------------------------------------- |
| SIM_STATE_UNKNOWN | The SIM card is in **unknown** state; that is, the SIM card status cannot be obtained.|
| SIM_STATE_NOT_PRESENT | The SIM card is in **not present** state; that is, no SIM card is inserted into the slot.|
| SIM_STATE_LOCKED | The SIM card is in **locked** state; that is, the SIM card is locked by the personal identification number (PIN), PIN unblocking key (PUK), or network.|
| SIM_STATE_NOT_READY | The SIM card is in **not ready** state; that is, the SIM card is present but cannot work properly.|
| SIM_STATE_READY | The SIM card is in **ready** state; that is, the SIM card is present and is working properly.|
| SIM_STATE_LOADED | The SIM card is in **loaded** state; that is, the SIM card is present and all its files have been loaded.|
# SMS
>**Note:**
>
>- The APIs of this module are supported since API version 6.
>
>- APIs marked with <sup>7+</sup> are supported since API version 7.
## Modules to Import
```
import sms from '@ohos.telephony.sms';
```
## sms.createMessage<a name=sms.createMessage-callback></a>
createMessage\(pdu: Array<number\>, specification: string, callback: AsyncCallback<ShortMessage\>\): void
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.
- Parameters
| Name| Type| Mandatory| Description|
| ------------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| pdu | Array&lt;number&gt; | Yes| Protocol data unit, which is obtained from the received SMS message.|
| specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS|
| callback | AsyncCallback&lt;[ShortMessage](#ShortMessage)&gt; | Yes| Callback used to return the result.|
- Example
```
let specification = '3gpp';
let pdu = [0x08, 0x91, ...];
sms.createMessage(pdu, specification, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sms.createMessage<a name=sms.createMessage-promise></a>
createMessage\(pdu: Array<number\>, specification: string\): Promise<ShortMessage\>
Creates an SMS message instance based on the PDU and the specified SMS protocol. This function uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| ------------- | ------------------- | ---- | ------------------------------------------------------------ |
| pdu | Array&lt;number&gt; | Yes| Protocol data unit, which is obtained from the received SMS message.|
| specification | string | Yes| SMS protocol type. The options are as follows: <br/> - **3gpp**: GSM/UMTS/LTE SMS<br/> - **3gpp2**: CDMA SMS|
- Return values
| Type| Description|
| -------------------------------------------- | --------------------------------- |
| Promise&lt;[ShortMessage](#ShortMessage)&gt; | Promise used to return the result.|
- Example
```
let specification = '3gpp';
let pdu = [0x08, 0x91, ...];
let promise = sms.createMessage(pdu, specification);
promise.then(data => {
console.log(`createMessage success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`createMessage fail, promise: err->${JSON.stringify(err)}`);
});
```
## sms.sendMessage
sendMessage(options: SendMessageOptions): void
Sends an SMS message.
Before using this API, you must declare the **ohos.permission.SEND_MESSAGES** permission.
- Parameters
| Name| Type| Mandatory| Description|
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [SendMessageOptions](#SendMessageOptions) | Yes| Options (including the callback) for sending an SMS message. For details, see [SendMessageOptions](#SendMessageOptions).|
- Example
```
let sendCallback = function (err, data) {
console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let deliveryCallback = function (err, data) {
console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
}
let slotId = 0;
let content ='SMS message content';
let destinationHost = '+861xxxxxxxxxx';
let serviceCenter = '+861xxxxxxxxxx';
let destinationPort = 1000;
let options = {slotId, content, destinationHost, serviceCenter, destinationPort, sendCallback, deliveryCallback};
sms.sendMessage(options);
```
## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-callback></a>
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.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Example
```
sms.getDefaultSmsSlotId((err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sms.getDefaultSmsSlotId<sup>7+</sup><a name=sms.getDefaultSmsSlotId-promise></a>
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.
- Return values
| Type| Description|
| --------------- | ------------------------------------------------------------ |
| Promise<number> | Promise used to return the result.<br/> - **0**: slot 1<br/> - **1**: slot 2|
- Example
```
let promise = call.getDefaultSmsSlotId();
promise.then(data => {
console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`getDefaultSmsSlotId fail, promise: err->${JSON.stringify(err)}`);
});
```
## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-callback></a>
setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback<void\>\): void
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.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| smscAddr | string | Yes| SMSC address. |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
- Example
```
let slotId = 0;
let smscAddr = '+861xxxxxxxxxx';
sms.setSmscAddr(slotId, smscAddr, (err,data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sms.setSmscAddr<sup>7+</sup><a name=sms.setSmscAddr-promise></a>
setSmscAddr\(slotId: number, smscAddr: string\): Promise<void\>
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.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | ------ | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| smscAddr | string | Yes| SMSC address.|
- Return values
| Type| Description|
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
- Example
```
let slotId = 0;
let smscAddr = '+861xxxxxxxxxx';
let promise = sms.setSmscAddr(slotId, smscAddr);
promise.then(data => {
console.log(`setSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`setSmscAddr fail, promise: err->${JSON.stringify(err)}`);
});
```
## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-callback></a>
getSmscAddr\(slotId: number, callback: AsyncCallback<string\>\): 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.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | --------------------------- | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result.|
- Example
```
let slotId = 0;
sms.getSmscAddr(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
## sms.getSmscAddr<sup>7+</sup><a name=sms.getSmscAddr-promise></a>
getSmscAddr\(slotId: number\): Promise<string\>
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.
- Parameters
| Name| Type| Mandatory| Description|
| ------ | ------ | ---- | ----------------------------------------- |
| slotId | number | Yes| SIM card slot ID. The options are as follows: <br/> - **0**: slot 1<br/> - **1**: slot 2|
- Return values
| Type| Description|
| --------------------- | --------------------------------------------- |
| Promise&lt;string&gt; | Promise used to return the result.|
- Example
```
let slotId = 0;
let promise = sms.getSmscAddr(slotId);
promise.then(data => {
console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`getSmscAddr fail, promise: err->${JSON.stringify(err)}`);
});
```
## ShortMessage<a name=ShortMessage></a>
Defines an SMS message instance.
| Variable| Type| Description|
| ------------------------ | --------------------------------------- | ------------------------------------------------------------ |
| emailAddress | string | Email address.|
| emailMessageBody | string | Email body.|
| hasReplyPath | boolean | Whether the received SMS contains **TP-Reply-Path**. The default value is **false**. <br/>**TP-Reply-Path**: the path in which the mobile phone can reply to the SMS message through the originating SMSC.|
| isEmailMessage | boolean | Whether the received SMS message is an email.|
| isReplaceMessage | boolean | Whether the received SMS message is a **replace short message**. The default value is **false**. <br/>For details, see section 9.2.3.9 in **3GPP TS 23.040**.|
| isSmsStatusReportMessage | boolean | Whether the received SMS message is an SMS delivery status report. The default value is **false**. <br/>SMS delivery status report: a message sent from the SMSC to show the current status of the SMS message you delivered.|
| messageClass | [ShortMessageClass](#ShortMessageClass) | SMS message type.|
| pdu | Array&lt;number&gt; | PDU in the SMS message.|
|protocolId|number|Protocol identifier used for delivering the SMS message.|
|scAddress|string|SMSC address.|
|scTimestamp|number|SMSC timestamp.|
|status|number|SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.|
|userRawData|Array&lt;number&gt;|User data excluding the data header.|
|visibleMessageBody|string|SMS message body.|
|visibleRawAddress|string|Sender address to be displayed on the UI.|
## ShortMessageClass<a name=ShortMessageClass></a>
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.|
## SendMessageOptions<a name=SendMessageOptions></a>
Provides the options (including callbacks) for sending an SMS message.
For example, you can specify the SMS message type by the optional parameter **content**.
| 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|
| 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.|
| 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. |
| sendCallback | AsyncCallback&lt;[ISendShortMessageCallback](#ISendShortMessageCallback)&gt; | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).|
| deliveryCallback | AsyncCallback&lt;[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)&gt; | No| Callback used to return the SMS message delivery report. For details, see [IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback).|
## 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.
| Name| Type| Mandatory| Description|
| ---------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| isLastPart | boolean | No| Whether this SMS message is the last part of a long SMS message. The value **true** indicates that this SMS message is the last part of a long SMS message, and value **false** indicates the opposite. The default value is **false**.|
| result | [SendSmsResult](#SendSmsResult) | Yes| SMS message sending result.|
| url | string | Yes| URI for storing sent SMS messages.|
## IDeliveryShortMessageCallback<a name=IDeliveryShortMessageCallback></a>
Provides the callback for the SMS message delivery report.
| Name| Type| Mandatory| Description|
| ------ | ------------------- | ---- | -------------- |
| pdu | Array&lt;number&gt; | Yes| SMS message delivery report.|
## SendSmsResult<a name=SendSmsResult></a>
Enumerates SMS message sending results.
| Name| Value| Description|
| ------------------------------------ | ---- | ------------------------------------------------------ |
| SEND_SMS_SUCCESS | 0 | The SMS message is sent successfully.|
| SEND_SMS_FAILURE_UNKNOWN | 1 | Failed to send the SMS message due to unknown reasons.|
| SEND_SMS_FAILURE_RADIO_OFF | 2 | Failed to send the SMS message because the modem is shut down.|
| SEND_SMS_FAILURE_SERVICE_UNAVAILABLE | 3 | Failed to send the SMS message because the network is unavailable or SMS message sending or receiving is not supported.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册