1e41f4b71Sopenharmony_ci# @ohos.telephony.sms (SMS)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **sms** module provides basic SMS management functions. With the APIs provided by this module, you can create and send SMS messages, and obtain the ID of the default SIM card used to send and receive SMS messages, and check whether the current device can send and receive SMS messages.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>**NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## sms.createMessage
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_cicreateMessage\(pdu: Array&lt;number&gt;, specification: string, callback: AsyncCallback\<ShortMessage\>\): void
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciCreates an SMS instance based on the protocol data unit (PDU) and specified SMS protocol. This API uses an asynchronous callback to return the result.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Parameters**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| Name       | Type                                              | Mandatory| Description                                                        |
26e41f4b71Sopenharmony_ci| ------------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
27e41f4b71Sopenharmony_ci| pdu           | Array&lt;number&gt;                                | Yes  | Protocol data unit, which is obtained from the received SMS message.                          |
28e41f4b71Sopenharmony_ci| specification | string                                             | Yes  | SMS protocol type. <br>- **3gpp**: GSM/UMTS/LTE SMS<br>- **3gpp2**: CDMA SMS|
29e41f4b71Sopenharmony_ci| callback      | AsyncCallback&lt;[ShortMessage](#shortmessage)&gt; | Yes  | Callback used to return the result.                                                  |
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Error codes**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| ID|                  Error Message                    |
36e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
37e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
38e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
39e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
40e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
41e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Example**
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci```ts
46e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
47e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ciconst specification: string = '3gpp';
50e41f4b71Sopenharmony_ci// Display PDUs in array format. The type is number.
51e41f4b71Sopenharmony_ciconst pdu: Array<number> = [0x01, 0x00, 0x05, 0x81, 0x01, 0x80, 0xF6, 0x00, 0x00, 0x05, 0xE8, 0x32, 0x9B, 0xFD, 0x06];
52e41f4b71Sopenharmony_cisms.createMessage(pdu, specification, (err: BusinessError, data: sms.ShortMessage) => {
53e41f4b71Sopenharmony_ci    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
54e41f4b71Sopenharmony_ci});
55e41f4b71Sopenharmony_ci```
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## sms.createMessage
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_cicreateMessage\(pdu: Array&lt;number&gt;, specification: string\): Promise\<ShortMessage\>
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciCreates an SMS instance based on the PDU and specified SMS protocol. This API uses a promise to return the result.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**Parameters**
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci| Name       | Type               | Mandatory| Description                                                        |
69e41f4b71Sopenharmony_ci| ------------- | ------------------- | ---- | ------------------------------------------------------------ |
70e41f4b71Sopenharmony_ci| pdu           | Array&lt;number&gt; | Yes  | Protocol data unit, which is obtained from the received SMS message.                          |
71e41f4b71Sopenharmony_ci| specification | string              | Yes  | SMS protocol type. <br>- **3gpp**: GSM/UMTS/LTE SMS<br>- **3gpp2**: CDMA SMS|
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**Return value**
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci| Type                                        | Description                             |
76e41f4b71Sopenharmony_ci| -------------------------------------------- | --------------------------------- |
77e41f4b71Sopenharmony_ci| Promise&lt;[ShortMessage](#shortmessage)&gt; | Promise used to return the result.|
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**Error codes**
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci| ID|                  Error Message                    |
84e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
85e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
86e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
87e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
88e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
89e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Example**
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci```ts
94e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
95e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ciconst specification: string = '3gpp';
98e41f4b71Sopenharmony_ci// Display PDUs in array format. The type is number.
99e41f4b71Sopenharmony_ciconst pdu: Array<number> = [0x01, 0x00, 0x05, 0x81, 0x01, 0x80, 0xF6, 0x00, 0x00, 0x05, 0xE8, 0x32, 0x9B, 0xFD, 0x06];
100e41f4b71Sopenharmony_cisms.createMessage(pdu, specification).then((data: sms.ShortMessage) => {
101e41f4b71Sopenharmony_ci    console.log(`createMessage success, promise: data->${JSON.stringify(data)}`);
102e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
103e41f4b71Sopenharmony_ci    console.error(`createMessage failed, promise: err->${JSON.stringify(err)}`);
104e41f4b71Sopenharmony_ci});
105e41f4b71Sopenharmony_ci```
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci## sms.sendMessage<sup>(deprecated)</sup>
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_cisendMessage\(options: SendMessageOptions\): void
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ciSends an SMS message.
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci> **NOTE**
114e41f4b71Sopenharmony_ci>
115e41f4b71Sopenharmony_ci> This API is supported since API version 6 and deprecated since API version 10. You are advised to use [sendShortMessage](#smssendshortmessage10).
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SEND_MESSAGES (available only for system applications)
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci**Parameters**
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci| Name | Type                                     | Mandatory| Description                                                        |
124e41f4b71Sopenharmony_ci| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
125e41f4b71Sopenharmony_ci| options | [SendMessageOptions](#sendmessageoptions) | Yes  | Options (including the callback) for sending SMS messages. For details, see [SendMessageOptions](#sendmessageoptions).|
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci**Error codes**
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci| ID|                 Error Message                    |
132e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
133e41f4b71Sopenharmony_ci| 201      | Permission denied.                           |
134e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
135e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
136e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
137e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
138e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**Example**
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci```ts
143e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
144e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_cilet sendCallback: AsyncCallback<sms.ISendShortMessageCallback> = (err: BusinessError, data: sms.ISendShortMessageCallback) => {
147e41f4b71Sopenharmony_ci    console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 
148e41f4b71Sopenharmony_ci};
149e41f4b71Sopenharmony_cilet deliveryCallback: AsyncCallback<sms.IDeliveryShortMessageCallback> = (err: BusinessError, data: sms.IDeliveryShortMessageCallback) => {
150e41f4b71Sopenharmony_ci    console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); 
151e41f4b71Sopenharmony_ci};
152e41f4b71Sopenharmony_cilet options: sms.SendMessageOptions = {
153e41f4b71Sopenharmony_ci    slotId: 0,
154e41f4b71Sopenharmony_ci    content: 'SMS message content';
155e41f4b71Sopenharmony_ci    destinationHost: '+861xxxxxxxxxx',
156e41f4b71Sopenharmony_ci    serviceCenter: '+861xxxxxxxxxx',
157e41f4b71Sopenharmony_ci    destinationPort: 1000,
158e41f4b71Sopenharmony_ci    sendCallback: sendCallback,
159e41f4b71Sopenharmony_ci    deliveryCallback: deliveryCallback
160e41f4b71Sopenharmony_ci};
161e41f4b71Sopenharmony_cisms.sendMessage(options);
162e41f4b71Sopenharmony_ci```
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci## sms.sendShortMessage<sup>10+</sup>
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_cisendShortMessage\(options: SendMessageOptions, callback: AsyncCallback&lt;void&gt;\): void
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ciSends an SMS message. This API uses an asynchronous callback to return the result.
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SEND_MESSAGES (available only for system applications)
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**Parameters**
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                    |
177e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ---------------------------------------- |
178e41f4b71Sopenharmony_ci| options | [SendMessageOptions](#sendmessageoptions) | Yes  | Options (including the callback) for sending SMS messages. For details, see [SendMessageOptions](#sendmessageoptions).|
179e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci**Error codes**
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
184e41f4b71Sopenharmony_ci
185e41f4b71Sopenharmony_ci| ID|                 Error Message                    |
186e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
187e41f4b71Sopenharmony_ci| 201      | Permission denied.                           |
188e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
189e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
190e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
191e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
192e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Example**
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci```ts
197e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
198e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_cilet sendCallback: AsyncCallback<sms.ISendShortMessageCallback> = (err: BusinessError, data: sms.ISendShortMessageCallback) => {
201e41f4b71Sopenharmony_ci    console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
202e41f4b71Sopenharmony_ci};
203e41f4b71Sopenharmony_cilet deliveryCallback: AsyncCallback<sms.IDeliveryShortMessageCallback> = (err: BusinessError, data: sms.IDeliveryShortMessageCallback) => {
204e41f4b71Sopenharmony_ci    console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
205e41f4b71Sopenharmony_ci};
206e41f4b71Sopenharmony_cilet options: sms.SendMessageOptions = {
207e41f4b71Sopenharmony_ci    slotId: 0,
208e41f4b71Sopenharmony_ci    content: 'SMS message content';
209e41f4b71Sopenharmony_ci    destinationHost: '+861xxxxxxxxxx',
210e41f4b71Sopenharmony_ci    serviceCenter: '+861xxxxxxxxxx',
211e41f4b71Sopenharmony_ci    destinationPort: 1000,
212e41f4b71Sopenharmony_ci    sendCallback: sendCallback,
213e41f4b71Sopenharmony_ci    deliveryCallback: deliveryCallback
214e41f4b71Sopenharmony_ci};
215e41f4b71Sopenharmony_cisms.sendShortMessage(options, (err: BusinessError) => {
216e41f4b71Sopenharmony_ci    console.log(`callback: err->${JSON.stringify(err)}`);
217e41f4b71Sopenharmony_ci});
218e41f4b71Sopenharmony_ci```
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci## sms.sendShortMessage<sup>10+</sup>
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_cisendShortMessage\(options: SendMessageOptions\): Promise&lt;void&gt;
223e41f4b71Sopenharmony_ci
224e41f4b71Sopenharmony_ciSends an SMS message. This API uses a promise to return the result.
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.SEND_MESSAGES (available only for system applications)
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci**Parameters**
231e41f4b71Sopenharmony_ci
232e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                    |
233e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ---------------------------------------- |
234e41f4b71Sopenharmony_ci| options | [SendMessageOptions](#sendmessageoptions) | Yes  | Options (including the callback) for sending SMS messages. For details, see [SendMessageOptions](#sendmessageoptions).|
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci**Return value**
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci| Type           | Description                                                        |
239e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ |
240e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result.|
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**Error codes**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
245e41f4b71Sopenharmony_ci
246e41f4b71Sopenharmony_ci| ID|                 Error Message                    |
247e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
248e41f4b71Sopenharmony_ci| 201      | Permission denied.                           |
249e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
250e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
251e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
252e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
253e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci**Example**
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci```ts
258e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
259e41f4b71Sopenharmony_ciimport { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_cilet sendCallback: AsyncCallback<sms.ISendShortMessageCallback> = (err: BusinessError, data: sms.ISendShortMessageCallback) => {
262e41f4b71Sopenharmony_ci    console.log(`sendCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
263e41f4b71Sopenharmony_ci};
264e41f4b71Sopenharmony_cilet deliveryCallback: AsyncCallback<sms.IDeliveryShortMessageCallback> = (err: BusinessError, data: sms.IDeliveryShortMessageCallback) => {
265e41f4b71Sopenharmony_ci    console.log(`deliveryCallback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
266e41f4b71Sopenharmony_ci};
267e41f4b71Sopenharmony_cilet options: sms.SendMessageOptions = {
268e41f4b71Sopenharmony_ci    slotId: 0,
269e41f4b71Sopenharmony_ci    content: 'SMS message content';
270e41f4b71Sopenharmony_ci    destinationHost: '+861xxxxxxxxxx',
271e41f4b71Sopenharmony_ci    serviceCenter: '+861xxxxxxxxxx',
272e41f4b71Sopenharmony_ci    destinationPort: 1000,
273e41f4b71Sopenharmony_ci    sendCallback: sendCallback,
274e41f4b71Sopenharmony_ci    deliveryCallback: deliveryCallback
275e41f4b71Sopenharmony_ci};
276e41f4b71Sopenharmony_cilet promise = sms.sendShortMessage(options);
277e41f4b71Sopenharmony_cipromise.then(() => {
278e41f4b71Sopenharmony_ci    console.log(`sendShortMessage success`);
279e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
280e41f4b71Sopenharmony_ci    console.error(`sendShortMessage failed, promise: err->${JSON.stringify(err)}`);
281e41f4b71Sopenharmony_ci});
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci```
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci## sms.getDefaultSmsSlotId<sup>7+</sup>
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_cigetDefaultSmsSlotId\(callback: AsyncCallback&lt;number&gt;\): void
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ciObtains the default slot ID of the SIM card used to send SMS messages. This API uses an asynchronous callback to return the result.
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ci**Parameters**
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                    |
297e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ---------------------------------------- |
298e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the result.<br>- **0**: card slot 1<br>- **1**: card slot 2|
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci**Example**
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci```ts
303e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
304e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_cisms.getDefaultSmsSlotId((err: BusinessError, data: number) => {
307e41f4b71Sopenharmony_ci    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
308e41f4b71Sopenharmony_ci});
309e41f4b71Sopenharmony_ci```
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ci## sms.getDefaultSmsSlotId<sup>7+</sup>
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_cigetDefaultSmsSlotId\(\): Promise&lt;number&gt;
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ciObtains the default slot ID of the SIM card used to send SMS messages. This API uses a promise to return the result.
317e41f4b71Sopenharmony_ci
318e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**Return value**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci| Type           | Description                                                        |
323e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ |
324e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the result.<br>- **0**: card slot 1<br>- **1**: card slot 2|
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci**Example**
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci```ts
329e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
330e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_cisms.getDefaultSmsSlotId().then((data: number) => {
333e41f4b71Sopenharmony_ci    console.log(`getDefaultSmsSlotId success, promise: data->${JSON.stringify(data)}`);
334e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
335e41f4b71Sopenharmony_ci    console.error(`getDefaultSmsSlotId failed, promise: err->${JSON.stringify(err)}`);
336e41f4b71Sopenharmony_ci});
337e41f4b71Sopenharmony_ci```
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ci## sms.hasSmsCapability<sup>7+</sup>
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_cihasSmsCapability\(\): boolean
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ciChecks whether the current device can send and receive SMS messages. This API works in synchronous mode.
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**Return value**
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci| Type   | Description                                                        |
350e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
351e41f4b71Sopenharmony_ci| boolean | - **true**: The device can send and receive SMS messages.<br>- **false**: The device cannot send or receive SMS messages.|
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci```ts
354e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
355e41f4b71Sopenharmony_ci
356e41f4b71Sopenharmony_cilet result = sms.hasSmsCapability(); 
357e41f4b71Sopenharmony_ciconsole.log(`hasSmsCapability: ${JSON.stringify(result)}`);
358e41f4b71Sopenharmony_ci```
359e41f4b71Sopenharmony_ci
360e41f4b71Sopenharmony_ci## sms.getDefaultSmsSimId<sup>10+</sup>
361e41f4b71Sopenharmony_ci
362e41f4b71Sopenharmony_cigetDefaultSmsSimId\(callback: AsyncCallback&lt;number&gt;\): void
363e41f4b71Sopenharmony_ci
364e41f4b71Sopenharmony_ciObtains the default ID of the SIM card used to send SMS messages. This API uses an asynchronous callback to return the result.
365e41f4b71Sopenharmony_ci
366e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci**Parameters**
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci| Name  | Type                       | Mandatory| Description                                    |
371e41f4b71Sopenharmony_ci| -------- | --------------------------- | ---- | ---------------------------------------- |
372e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;number&gt; | Yes  | Callback used to return the result.<br>The return value is bound to the SIM card and increases from 1.<br>The return value is **-1** if no SIM card is detected.|
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci**Error codes**
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci| ID|                 Error Message                    |
379e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
380e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
381e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
382e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
383e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
384e41f4b71Sopenharmony_ci| 8300004  | Do not have sim card.                        |
385e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
386e41f4b71Sopenharmony_ci| 8301001  | SIM card is not activated.                   |
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci**Example**
389e41f4b71Sopenharmony_ci
390e41f4b71Sopenharmony_ci```ts
391e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
392e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_cisms.getDefaultSmsSimId((err: BusinessError, data: number) => {
395e41f4b71Sopenharmony_ci    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
396e41f4b71Sopenharmony_ci});
397e41f4b71Sopenharmony_ci```
398e41f4b71Sopenharmony_ci
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci## sms.getDefaultSmsSimId<sup>10+</sup>
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_cigetDefaultSmsSimId\(\): Promise&lt;number&gt;
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ciObtains the default ID of the SIM card used to send SMS messages. This API uses a promise to return the result.
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci**Return value**
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci| Type           | Description                                                        |
411e41f4b71Sopenharmony_ci| --------------- | ------------------------------------------------------------ |
412e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | Promise used to return the result.<br>The return value is bound to the SIM card and increases from 1.<br>The return value is **-1** if no SIM card is detected.|
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ci**Error codes**
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ciFor details about the error codes, see[ohos.telephony (Telephony) Error Codes](errorcode-telephony.md).
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci| ID|                 Error Message                    |
419e41f4b71Sopenharmony_ci| -------- | -------------------------------------------- |
420e41f4b71Sopenharmony_ci| 8300001  | Invalid parameter value.                     |
421e41f4b71Sopenharmony_ci| 8300002  | Operation failed. Cannot connect to service. |
422e41f4b71Sopenharmony_ci| 8300003  | System internal error.                       |
423e41f4b71Sopenharmony_ci| 8300004  | Do not have sim card.                        |
424e41f4b71Sopenharmony_ci| 8300999  | Unknown error code.                          |
425e41f4b71Sopenharmony_ci| 8301001  | SIM card is not activated.                   |
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci**Example**
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci```ts
430e41f4b71Sopenharmony_ciimport { sms } from '@kit.TelephonyKit';
431e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_cilet promise = sms.getDefaultSmsSimId();
434e41f4b71Sopenharmony_cipromise.then((data: number) => {
435e41f4b71Sopenharmony_ci    console.log(`getDefaultSmsSimId success, promise: data->${JSON.stringify(data)}`);
436e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => {
437e41f4b71Sopenharmony_ci    console.error(`getDefaultSmsSimId failed, promise: err->${JSON.stringify(err)}`);
438e41f4b71Sopenharmony_ci});
439e41f4b71Sopenharmony_ci```
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci
442e41f4b71Sopenharmony_ci## ShortMessage
443e41f4b71Sopenharmony_ci
444e41f4b71Sopenharmony_ciDefines an SMS message instance.
445e41f4b71Sopenharmony_ci
446e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
447e41f4b71Sopenharmony_ci
448e41f4b71Sopenharmony_ci|         Name            |                  Type                  | Mandatory| Description                                                        |
449e41f4b71Sopenharmony_ci| ------------------------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
450e41f4b71Sopenharmony_ci| hasReplyPath             | boolean                                 |  Yes | Whether the received SMS contains **TP-Reply-Path**. The default value is **false**.<br>TP-Reply-Path: The device returns a response based on the SMSC that sends the SMS message. |
451e41f4b71Sopenharmony_ci| isReplaceMessage         | boolean                                 |  Yes | Whether the received SMS message is a **replace short message**. The default value is **false**.<br>For details, see [3GPP TS 23.040 9.2.3.9](https://www.3gpp.org/ftp/specs/archive/23_series/23.040).|
452e41f4b71Sopenharmony_ci| isSmsStatusReportMessage | boolean                                 |  Yes | Whether the received SMS message is an SMS delivery report. The default value is **false**.<br>SMS delivery report: a message sent from the SMSC to show the current status of the SMS message you delivered.|
453e41f4b71Sopenharmony_ci| messageClass             | [ShortMessageClass](#shortmessageclass) |  Yes | Enumerates SMS message types.                                                  |
454e41f4b71Sopenharmony_ci| pdu                      | Array&lt;number&gt;                     |  Yes | PDU in the SMS message.                           |
455e41f4b71Sopenharmony_ci| protocolId               | number                                  |  Yes | Protocol identifier used for delivering the SMS message.                                  |
456e41f4b71Sopenharmony_ci| scAddress                | string                                  |  Yes | SMSC address.                                |
457e41f4b71Sopenharmony_ci| scTimestamp              | number                                  |  Yes | SMSC timestamp.                                                |
458e41f4b71Sopenharmony_ci| status                   | number                                  |  Yes | SMS message status sent by the SMSC in the **SMS-STATUS-REPORT** message.|
459e41f4b71Sopenharmony_ci| visibleMessageBody       | string                                  |  Yes | SMS message body.                                                  |
460e41f4b71Sopenharmony_ci| visibleRawAddress        | string                                  |  Yes | Sender address.                                                |
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci## ShortMessageClass
464e41f4b71Sopenharmony_ci
465e41f4b71Sopenharmony_ciEnumerates SMS message types.
466e41f4b71Sopenharmony_ci
467e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci| Name            | Value  | Description                                    |
470e41f4b71Sopenharmony_ci| ---------------- | ---- | ---------------------------------------- |
471e41f4b71Sopenharmony_ci| UNKNOWN          | 0    | Unknown type.                              |
472e41f4b71Sopenharmony_ci| INSTANT_MESSAGE  | 1    | Instant message, which is displayed immediately after being received.              |
473e41f4b71Sopenharmony_ci| OPTIONAL_MESSAGE | 2    | Message stored in the device or SIM card.             |
474e41f4b71Sopenharmony_ci| SIM_MESSAGE      | 3    | Message containing SIM card information, which is to be stored in the SIM card.|
475e41f4b71Sopenharmony_ci| FORWARD_MESSAGE  | 4    | Message to be forwarded to another device.              |
476e41f4b71Sopenharmony_ci
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci## SendMessageOptions
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ciProvides the options (including callbacks) for sending SMS messages. For example, you can specify the SMS message type by the optional parameter **content**.
481e41f4b71Sopenharmony_ci
482e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci|       Name      | Type                                                        | Mandatory| Description                                                        |
485e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
486e41f4b71Sopenharmony_ci| slotId           | number                                                       | Yes  | Slot ID of the SIM card used for sending SMS messages. <br>- **0**: card slot 1<br>- **1**: card slot 2     |
487e41f4b71Sopenharmony_ci| destinationHost  | string                                                       | Yes  | Destination address of the SMS message.                                            |
488e41f4b71Sopenharmony_ci| content          | string \| Array&lt;number&gt;                                | Yes  | SMS message type. If the content is composed of character strings, the SMS message is a text message. If the content is composed of byte arrays, the SMS message is a data message.|
489e41f4b71Sopenharmony_ci| serviceCenter    | string                                                       | No  | SMSC address. By default, the SMSC address in the SIM card is used.               |
490e41f4b71Sopenharmony_ci| destinationPort  | number                                                       | No  | Destination port of the SMS message. This field is mandatory only for a data message. Otherwise, it is optional.  |
491e41f4b71Sopenharmony_ci| sendCallback     | AsyncCallback&lt;[ISendShortMessageCallback](#isendshortmessagecallback)&gt; | No  | Callback used to return the SMS message sending result. For details, see [ISendShortMessageCallback](#isendshortmessagecallback). This parameter is mandatory for sending an SMS message.|
492e41f4b71Sopenharmony_ci| deliveryCallback | AsyncCallback&lt;[IDeliveryShortMessageCallback](#ideliveryshortmessagecallback)&gt; | No  | Callback used to return the SMS message delivery report. For details, see [IDeliveryShortMessageCallback](#ideliveryshortmessagecallback). This parameter is mandatory for sending an SMS message.|
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci## ISendShortMessageCallback
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ciProvides the callback for the SMS message sending result. It consists of three parts: SMS message sending result, URI for storing the sent SMS message, and whether the SMS message is the last part of a long SMS message.
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
501e41f4b71Sopenharmony_ci
502e41f4b71Sopenharmony_ci|   Name    | Type                           | Mandatory|                                               Description                                        |
503e41f4b71Sopenharmony_ci| ---------- | ------------------------------- | ---- | ----------------------------------------------------------------------------------------- |
504e41f4b71Sopenharmony_ci| isLastPart | boolean                         | Yes  | 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**.|
505e41f4b71Sopenharmony_ci| result     | [SendSmsResult](#sendsmsresult) | Yes  | SMS message sending result.                                                                            |
506e41f4b71Sopenharmony_ci| url        | string                          | Yes  | URI for storing the sent SMS message.                                                                       |
507e41f4b71Sopenharmony_ci
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci## IDeliveryShortMessageCallback
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ciProvides the callback for the SMS message delivery report.
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ci| Name| Type               | Mandatory| Description          |
516e41f4b71Sopenharmony_ci| ---- | ------------------- | ---- | -------------- |
517e41f4b71Sopenharmony_ci| pdu  | Array&lt;number&gt; | Yes  | SMS message delivery report.|
518e41f4b71Sopenharmony_ci
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci## SendSmsResult
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ciEnumerates SMS message sending results.
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Telephony.SmsMms
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci| Name                                | Value  | Description                                                  |
527e41f4b71Sopenharmony_ci| ------------------------------------ | ---- | ------------------------------------------------------ |
528e41f4b71Sopenharmony_ci| SEND_SMS_SUCCESS                     | 0    | The SMS message is sent successfully.                                        |
529e41f4b71Sopenharmony_ci| SEND_SMS_FAILURE_UNKNOWN             | 1    | Failed to send the SMS message due to an unknown reason.                              |
530e41f4b71Sopenharmony_ci| SEND_SMS_FAILURE_RADIO_OFF           | 2    | Failed to send the SMS message because the modem is shut down.                  |
531e41f4b71Sopenharmony_ci| 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.|
532