From b47f8c0add61ff256cae34b171a1f828e1682ab9 Mon Sep 17 00:00:00 2001 From: shawn_he Date: Fri, 3 Dec 2021 14:29:27 +0800 Subject: [PATCH] update docs Signed-off-by: shawn_he --- .../js-reference/apis/js-apis-call.md | 439 +++++++++++++++++ .../js-reference/apis/js-apis-radio.md | 460 ++++++++++++++++++ .../js-reference/apis/js-apis-sim.md | 388 +++++++++++++++ .../js-reference/apis/js-apis-sms.md | 352 ++++++++++++++ 4 files changed, 1639 insertions(+) create mode 100644 en/application-dev/js-reference/apis/js-apis-call.md create mode 100644 en/application-dev/js-reference/apis/js-apis-radio.md create mode 100644 en/application-dev/js-reference/apis/js-apis-sim.md create mode 100644 en/application-dev/js-reference/apis/js-apis-sms.md diff --git a/en/application-dev/js-reference/apis/js-apis-call.md b/en/application-dev/js-reference/apis/js-apis-call.md new file mode 100644 index 0000000000..16d5ceb279 --- /dev/null +++ b/en/application-dev/js-reference/apis/js-apis-call.md @@ -0,0 +1,439 @@ +# Call + +>**Note:** +> +>- The APIs of this module are supported since API version 6. +> +>- APIs marked with 7+ are supported since API version 7. + + +## Modules to Import + +``` +import call from '@ohos.telephony.call'; +``` + +## call.dial + +dial\(phoneNumber: string, callback: AsyncCallback\): void + +Initiates a call. This function uses an asynchronous callback to return the execution result. + +Before using this API, you must declare the **ohos.permission.PLACE\_CALL** permission (a system permission). + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | phoneNumber | string | Yes|Phone number.| + | callback |AsyncCallback<boolean>|Yes|Callback used to return the result.
- **true**: success
-**false**: failure| + +- Example + + ``` + call.dial("138xxxxxxxx", (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## call.dial + +dial\(phoneNumber: string, options: DialOptions, callback: AsyncCallback\): 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<boolean> | Yes| Callback used to return the result.
- **true**: success
-**false**: failure| + + +- Example + + ``` + call.dial("138xxxxxxxx", { + extras: false + }, (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## call.dial + +dial\(phoneNumber: string, options?: DialOptions\): Promise + +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<boolean> | 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 + +hasCall\(callback: AsyncCallback\): 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<boolean> | Yes| Callback used to return the result:
- **true**: A call is in progress.
- **false**: No call is in progress. | + +- Example + + ``` + call.hasCall((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## call.hasCall + +hasCall\(\): Promise + +Checks whether a call is in progress. This function uses a promise to return the result. + +- Return values + + | Type| Description| + | ---------------------- | --------------------------------------- | + | Promise<boolean> | 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 + +getCallState\(callback: AsyncCallback\): void + +Obtains the call status. This function uses an asynchronous callback to return the result. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | -------------------------------------------- | ---- | ------------------------------------ | + | callback | AsyncCallback<[CallState](#CallState)> | 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 + +getCallState\(\): Promise + +Obtains the call status. This function uses a promise to return the result. + +- Return values + + | Type| Description| + | -------------------------------------- | ----------------------------------------- | + | Promise<[CallState](#CallState)> | 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.isEmergencyPhoneNumber7+ + +isEmergencyPhoneNumber\(phoneNumber: string, callback: AsyncCallback\): 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<boolean> | Yes| Callback used to return the result.
- **true**: The called number is an emergency number.
- **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.isEmergencyPhoneNumber7+ + +isEmergencyPhoneNumber\(phoneNumber: string, options: EmergencyNumberOptions, callback: AsyncCallback\): 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<boolean> | Yes| Callback used to return the result.
- **true**: The called number is an emergency number.
- **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.isEmergencyPhoneNumber7+ + +isEmergencyPhoneNumber\(phoneNumber: string, options?: EmergencyNumberOptions\): Promise + +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<boolean> | 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.formatPhoneNumber7+ + +formatPhoneNumber\(phoneNumber: string, callback: AsyncCallback\): 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<string> | 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.formatPhoneNumber7+ + +formatPhoneNumber\(phoneNumber: string, options: NumberFormatOptions, callback: AsyncCallback\): 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<string> | 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.formatPhoneNumber7+ + +formatPhoneNumber\(phoneNumber: string, options?: NumberFormatOptions\): Promise + +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<string> | 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.formatPhoneNumberToE1647+ + +formatPhoneNumberToE164\(phoneNumber: string, countryCode: string, callback: AsyncCallback\): 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<string> | 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.formatPhoneNumberToE1647+ + +formatPhoneNumberToE164\(phoneNumber: string, countryCode: string\): Promise + +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<string> | 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 + +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:
- **true**: video call
- **false**: voice call| + +## CallState + +Enumerates call states. +| Variable| Value| Description| +| -------- | -------- | -------- | +| CALL_STATE_UNKNOWN | -1 | The call status fails to be obtained and is unknown.| +| CALL_STATE_IDLE | 0 | No call is in progress.| +| CALL_STATE_RINGING | 1 | The call is in the ringing or waiting state.| +| CALL_STATE_OFFHOOK | 2 | At least one call is in dialing, active, or on hold, and no new incoming call is ringing or waiting.| + +## EmergencyNumberOptions7+ + +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.
- **0**: slot 1
- **1**: slot 2| + +## NumberFormatOptions7+ + +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**.| diff --git a/en/application-dev/js-reference/apis/js-apis-radio.md b/en/application-dev/js-reference/apis/js-apis-radio.md new file mode 100644 index 0000000000..69cac33509 --- /dev/null +++ b/en/application-dev/js-reference/apis/js-apis-radio.md @@ -0,0 +1,460 @@ +# Radio + +>**Note:** +> +>- The APIs of this module are supported since API version 6. +>- APIs marked with 7+ are supported since API version 7. + + +## Modules to Import + +``` +import radio from '@ohos.telephony.radio' +``` + +## radio.getRadioTech + +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:
- **0**: slot 1
- **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 + +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:
- **0**: slot 1
- **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 + +getNetworkState\(callback: AsyncCallback\): 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 + +getNetworkState\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **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 + +getNetworkState\(slotId?: number\): Promise + +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:
- **0**: slot 1
- **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 + +getNetworkSelectionMode\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **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 + +getNetworkSelectionMode\(slotId: number\): Promise + +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:
- **0**: slot 1
- **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.getISOCountryCodeForNetwork7+ + +getISOCountryCodeForNetwork\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\ | 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.getISOCountryCodeForNetwork7+ + +getISOCountryCodeForNetwork\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------- | ------------------------------------------------------------ | + | Promise\ | 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 + +getSignalInformation\(slotId: number, callback: AsyncCallback\>\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\\> | 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 + +getSignalInformation\(slotId: number\): Promise\> + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------------------------------------------------- | ------------------------------------------------------------ | + | Promise\\> | 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.isRadioOn7+ + +isRadioOn\(callback: AsyncCallback\): 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\ | Yes| Callback used to return the result.
- **true**: Radio is turned on.
- **false**: Radio is turned off.| + +- Example + + ``` + radio.isRadioOn((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## radio.isRadioOn7+ + +isRadioOn\(\): Promise + +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\ | Promise used to return the result.
- **true**: Radio is turned on.
- **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 + +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 + +Defines the signal strength. + +| Attribute| Type| Description| +| ----------- | --------------------------- | ------------------ | +| signalType | [NetworkType](#NetworkType) | Signal strength type.| +| signalLevel | number | Signal strength level.| + + +## NetworkType + +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 + +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 + +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 + +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 + +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.| diff --git a/en/application-dev/js-reference/apis/js-apis-sim.md b/en/application-dev/js-reference/apis/js-apis-sim.md new file mode 100644 index 0000000000..9d27fea1ef --- /dev/null +++ b/en/application-dev/js-reference/apis/js-apis-sim.md @@ -0,0 +1,388 @@ +# SIM Management + +>**Note:** +> +>- The APIs of this module are supported since API version 6. +>- APIs marked with 7+ are supported since API version 7. + +## Modules to Import + +``` +import sim from '@ohos.telephony.sim'; +``` + +## sim.getSimIccId + +getSimIccId\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback<string> | 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 + +getSimIccId\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | --------------------- | ---------------------------------- | + | Promise<string> | 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.getDefaultVoiceSlotId7+ + +getDefaultVoiceSlotId\(callback: AsyncCallback\): 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<number> | Yes| Callback used to return the result.| + +- Example + + ``` + sim.getDefaultVoiceSlotId((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## sim.getDefaultVoiceSlotId7+ + +getDefaultVoiceSlotId\(\): Promise + +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\ | 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 + +getISOCountryCodeForSim\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\ | 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 + +getISOCountryCodeForSim\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------- | ------------------------------------------------------------ | + | Promise\ | 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 + +getSimOperatorNumeric\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\ | 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 + +getSimOperatorNumeric\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------- | ------------------------------------------------ | + | Promise\ | 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 + +getSimSpn\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\ | 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 + +getSimSpn\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------- | ----------------------------------------- | + | Promise\ | 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 + +getSimState\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **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 + +getSimState\(slotId: number\): Promise + +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:
- **0**: slot 1
- **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 + +getSimGid1\(slotId: number, callback: AsyncCallback\): 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:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback\ | 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 + +getSimGid1\(slotId: number\): Promise + +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:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | ----------------- | ------------------------------------------------------------ | + | Promise\ | 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 + +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.| diff --git a/en/application-dev/js-reference/apis/js-apis-sms.md b/en/application-dev/js-reference/apis/js-apis-sms.md new file mode 100644 index 0000000000..a45f89399e --- /dev/null +++ b/en/application-dev/js-reference/apis/js-apis-sms.md @@ -0,0 +1,352 @@ +# SMS + +>**Note:** +> +>- The APIs of this module are supported since API version 6. +> +>- APIs marked with 7+ are supported since API version 7. + +## Modules to Import + +``` +import sms from '@ohos.telephony.sms'; +``` + +## sms.createMessage + +createMessage\(pdu: Array, specification: string, callback: AsyncCallback\): 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<number> | Yes| Protocol data unit, which is obtained from the received SMS message.| + | specification | string | Yes| SMS protocol type. The options are as follows:
- **3gpp**: GSM/UMTS/LTE SMS
- **3gpp2**: CDMA SMS| + | callback | AsyncCallback<[ShortMessage](#ShortMessage)> | 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 + +createMessage\(pdu: Array, specification: string\): Promise + +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<number> | Yes| Protocol data unit, which is obtained from the received SMS message.| + | specification | string | Yes| SMS protocol type. The options are as follows:
- **3gpp**: GSM/UMTS/LTE SMS
- **3gpp2**: CDMA SMS| + +- Return values + + | Type| Description| + | -------------------------------------------- | --------------------------------- | + | Promise<[ShortMessage](#ShortMessage)> | 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.getDefaultSmsSlotId7+ + +getDefaultSmsSlotId\(callback: AsyncCallback\): 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<number> | Yes| Callback used to return the result.
- **0**: slot 1
- **1**: slot 2| + +- Example + + ``` + sms.getDefaultSmsSlotId((err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); + }); + ``` + + +## sms.getDefaultSmsSlotId7+ + +getDefaultSmsSlotId\(\): Promise + +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 | Promise used to return the result.
- **0**: slot 1
- **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.setSmscAddr7+ + +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. + +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:
- **0**: slot 1
- **1**: slot 2| + | smscAddr | string | Yes| SMSC address. | + | callback | AsyncCallback<void> | 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.setSmscAddr7+ + +setSmscAddr\(slotId: number, smscAddr: string\): Promise + +Sets the SMSC address. This function uses a promise to return the result. + +Before using this API, you must declare the **ohos.permission.SET\_TELEPHONY\_STATE** permission. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | ------ | ---- | ----------------------------------------- | + | slotId | number | Yes| SIM card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| + | smscAddr | string | Yes| SMSC address.| + +- Return values + + | Type| Description| + | ------------------- | ------------------------------- | + | Promise<void> | 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.getSmscAddr7+ + +getSmscAddr\(slotId: number, callback: AsyncCallback\): void + +Obtains the SMSC address. This function uses an asynchronous callback to return the result. + +Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | --------------------------- | ---- | ----------------------------------------- | + | slotId | number | Yes| SIM card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| + | callback | AsyncCallback<string> | 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.getSmscAddr7+ + +getSmscAddr\(slotId: number\): Promise + +Obtains the SMSC address. This function uses a promise to return the result. + +Before using this API, you must declare the **ohos.permission.GET\_TELEPHONY\_STATE** permission. + +- Parameters + + | Name| Type| Mandatory| Description| + | ------ | ------ | ---- | ----------------------------------------- | + | slotId | number | Yes| SIM card slot ID. The options are as follows:
- **0**: slot 1
- **1**: slot 2| + +- Return values + + | Type| Description| + | --------------------- | --------------------------------------------- | + | Promise<string> | 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 + +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**.
**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**.
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**.
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<number> | 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<number>|User data excluding the data header.| +|visibleMessageBody|string|SMS message body.| +|visibleRawAddress|string|Sender address to be displayed on the UI.| + + +## ShortMessageClass + +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 + +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:
- **0**: slot 1
- **1**: slot 2| +| destinationHost | string | Yes| Destination address of the SMS message.| +| content | string \| Array<number> | Yes| SMS message type. If the content is comprised of character strings, the SMS message is a text message. If the content is comprised of byte arrays, the SMS message is a data message.| +| 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<[ISendShortMessageCallback](#ISendShortMessageCallback)> | No| Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#ISendShortMessageCallback).| +| deliveryCallback | AsyncCallback<[IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback)> | No| Callback used to return the SMS message delivery report. For details, see [IDeliveryShortMessageCallback](#IDeliveryShortMessageCallback).| + + +## ISendShortMessageCallback + +Provides the callback for the SMS message delivery report. It consists of three parts: SMS message sending result, URI for storing the sent SMS message, and whether the SMS message is the last part of a long SMS message. + +| 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 + +Provides the callback for the SMS message delivery report. + +| Name| Type| Mandatory| Description| +| ------ | ------------------- | ---- | -------------- | +| pdu | Array<number> | Yes| SMS message delivery report.| + + +## SendSmsResult + +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.| -- GitLab