1# @ohos.telephony.sms (SMS) (System API)
2
3The **sms** module provides basic SMS management functions. With the APIs provided by this module, you can create and send SMS messages, obtain the ID of the default SIM card used to send and receive SMS messages, and obtain and set the SMSC address.
4
5>**NOTE**
6>
7>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.
8>
9>This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.telephony.sms (SMS)](js-apis-sms.md).
10
11
12## Modules to Import
13
14```ts
15import { sms } from '@kit.TelephonyKit';
16```
17
18
19## sms.sendMms<sup>11+</sup>
20
21sendMms\(context: Context, mmsParams: MmsParams, callback: AsyncCallback&lt;void&gt;\): void
22
23Sends an MMS message. This API uses an asynchronous callback to return the result.
24
25**System API**: This is a system API.
26
27**Required permissions**: ohos.permission.SEND_MESSAGES
28
29**System capability**: SystemCapability.Telephony.SmsMms
30
31**Parameters**
32
33| Name  | Type                       | Mandatory| Description                                    |
34| -------- | --------------------------- | ---- | ---------------------------------------- |
35| context | Context          | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).|
36| mmsParams | [MmsParams](#mmsparams11) | Yes  | Parameters (including the callback) for sending MMS messages. For details, see [MmsParams](#mmsparams11).|
37| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
38
39**Error codes**
40
41For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
42
43| ID|                 Error Message                    |
44| -------- | -------------------------------------------- |
45| 201      | Permission denied.                           |
46| 202      | Non-system applications use system APIs.                           |
47| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
48| 8300001  | Invalid parameter value.                     |
49| 8300002  | Operation failed. Cannot connect to service. |
50| 8300003  | System internal error.                       |
51| 8300999  | Unknown error code.                          |
52
53**Example**
54
55FA model:
56<!--code_no_check_fa-->
57```ts
58import { sms } from '@kit.TelephonyKit';
59import { BusinessError } from '@kit.BasicServicesKit';
60import { common, featureAbility } from '@kit.AbilityKit';
61
62// Obtain the context.
63let context: common.BaseContext = featureAbility.getContext();
64
65// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
66const sandBoxPath: string = '/data/storage/el2/base/files/';
67let filePath: string  = sandBoxPath + 'SendReq.mms';
68
69// Options for sending MMS messages (The MMSC is for reference only.)
70let mmsPars: sms.MmsParams = {
71  slotId : 0,
72  mmsc: 'http://mmsc.myuni.com.cn',
73  data: filePath,
74  mmsConfig: {
75   userAgent:'ua',
76   userAgentProfile: 'uaprof'
77  }
78};
79
80// Call the sendMms API.
81sms.sendMms(context, mmsPars, async(err: BusinessError) =>{
82  if (err) {
83      console.error(`sendMms fail, err : ${JSON.stringify(err)}`);
84      return;
85  }
86  console.log(`sendMms Success`);
87})
88```
89
90Stage model:
91
92```ts
93import { UIAbility } from '@kit.AbilityKit';
94import { sms } from '@kit.TelephonyKit';
95import { BusinessError } from '@kit.BasicServicesKit';
96import { window } from '@kit.ArkUI';
97
98// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
99const sandBoxPath = '/data/storage/el2/base/files/';
100let filePath  = sandBoxPath + 'SendReq.mms';
101
102// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements.
103let mmsConf: sms.MmsConfig = {
104  userAgent:'ua',
105  userAgentProfile: 'uaprof'
106};
107
108// Options for sending MMS messages (The MMSC is for reference only.)
109let mmsPars: sms.MmsParams = {
110  slotId : 0,
111  mmsc: 'http://mmsc.myuni.com.cn',
112  data: filePath,
113  mmsConfig: mmsConf
114};
115
116class EntryAbility extends UIAbility {
117    onWindowStageCreate(windowStage: window.WindowStage) {
118    sms.sendMms(this.context, mmsPars, async(err: BusinessError) =>{
119        if (err) {
120            console.error(`sendMms fail, err : ${JSON.stringify(err)}`);
121            return;
122        }
123        console.log(`sendMms Success`);
124        })
125    }
126}
127```
128
129## sms.sendMms<sup>11+</sup>
130
131sendMms\(context: Context, mmsParams: MmsParams\): Promise&lt;void&gt;
132
133Sends an MMS message. This API uses a promise to return the result.
134
135**System API**: This is a system API.
136
137**Required permissions**: ohos.permission.SEND_MESSAGES
138
139**System capability**: SystemCapability.Telephony.SmsMms
140
141**Parameters**
142
143| Name  | Type                       | Mandatory| Description                                    |
144| -------- | --------------------------- | ---- | ---------------------------------------- |
145| context | Context          | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).|
146| mmsParams | [MmsParams](#mmsparams11) | Yes  | Parameters (including the callback) for sending MMS messages. For details, see [MmsParams](#mmsparams11).|
147
148**Return value**
149
150| Type           | Description                                                        |
151| --------------- | ------------------------------------------------------------ |
152| Promise&lt;void&gt; | Promise used to return the result.|
153
154**Error codes**
155
156For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
157
158| ID|                 Error Message                    |
159| -------- | -------------------------------------------- |
160| 201      | Permission denied.                           |
161| 202      | Non-system applications use system APIs.                           |
162| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                             |
163| 8300001  | Invalid parameter value.                     |
164| 8300002  | Operation failed. Cannot connect to service. |
165| 8300003  | System internal error.                       |
166| 8300999  | Unknown error code.                          |
167
168**Example**
169
170FA model:
171<!--code_no_check_fa-->
172```ts
173import { sms } from '@kit.TelephonyKit';
174import { BusinessError } from '@kit.BasicServicesKit';
175import { common, featureAbility } from '@kit.AbilityKit';
176
177// Obtain the context.
178let context: common.BaseContext = featureAbility.getContext();
179
180// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
181const sandBoxPath: string = '/data/storage/el2/base/files/';
182let filePath: string = sandBoxPath + 'SendReq.mms';
183
184// Options for sending MMS messages (The MMSC is for reference only.)
185let mmsPars: sms.MmsParams = {
186  slotId: 0,
187  mmsc: 'http://mmsc.myuni.com.cn',
188  data: filePath,
189  mmsConfig: {
190   userAgent:'ua',
191   userAgentProfile: 'uaprof'
192  }
193};
194
195// Call the sendMms API.
196let promise = sms.sendMms(context, mmsPars);
197promise.then(() => {
198    console.log(`sendMms success`);
199}).catch((err: BusinessError) => {
200    console.error(`sendMms failed, promise: err->${JSON.stringify(err)}`);
201});
202```
203
204Stage model:
205
206```ts
207import { UIAbility } from '@kit.AbilityKit';
208import { sms } from '@kit.TelephonyKit';
209import { BusinessError } from '@kit.BasicServicesKit';
210import { window } from '@kit.ArkUI';
211
212// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
213const sandBoxPath = '/data/storage/el2/base/files/';
214let filePath  = sandBoxPath + 'SendReq.mms';
215
216// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements.
217let mmsConf: sms.MmsConfig = {
218  userAgent:'ua',
219  userAgentProfile: 'uaprof'
220};
221
222// Options for sending MMS messages (The MMSC is for reference only.)
223let mmsPars: sms.MmsParams = {
224  slotId : 0,
225  mmsc: 'http://mmsc.myuni.com.cn',
226  data: filePath,
227  mmsConfig: mmsConf
228};
229
230class EntryAbility extends UIAbility {
231    onWindowStageCreate(windowStage: window.WindowStage) {
232    let promise = sms.sendMms(this.context, mmsPars);
233    promise.then(() => {
234        console.log(`sendMms success`);
235    }).catch((err: BusinessError) => {
236        console.error(`sendMms failed, promise: err->${JSON.stringify(err)}`);
237    });
238    }
239}
240```
241
242## sms.downloadMms<sup>11+</sup>
243
244downloadMms\(context: Context, mmsParams: MmsParams, callback: AsyncCallback&lt;void&gt;\): void
245
246Downloads an MMS message. This API uses an asynchronous callback to return the result.
247
248**System API**: This is a system API.
249
250**Required permissions**: ohos.permission.RECEIVE_MMS
251
252**System capability**: SystemCapability.Telephony.SmsMms
253
254**Parameters**
255
256| Name  | Type                       | Mandatory| Description                                    |
257| -------- | --------------------------- | ---- | ---------------------------------------- |
258| context | Context          | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).|
259| mmsParams | [MmsParams](#mmsparams11) | Yes  | Parameters (including the callback) for downloading MMS messages. For details, see [MmsParams](#mmsparams11).|
260| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.|
261
262**Error codes**
263
264For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
265
266| ID|                 Error Message                    |
267| -------- | -------------------------------------------- |
268| 201      | Permission denied.                           |
269| 202      | Non-system applications use system APIs.                           |
270| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
271| 8300001  | Invalid parameter value.                     |
272| 8300002  | Operation failed. Cannot connect to service. |
273| 8300003  | System internal error.                       |
274| 8300999  | Unknown error code.                          |
275
276**Example**
277
278FA model:
279<!--code_no_check_fa-->
280```ts
281import { sms } from '@kit.TelephonyKit';
282import { BusinessError } from '@kit.BasicServicesKit';
283import { common, featureAbility } from '@kit.AbilityKit';
284
285// Obtain the context.
286let context: common.BaseContext = featureAbility.getContext();
287
288// Configure the path for storing the PDU of the MMS message.
289const sandBoxPath: string = '/data/storage/el2/base/files/';
290let filePath: string = sandBoxPath + 'RetrieveConf.mms';
291
292// Parse the MMS URL from the WAP Push message.
293let wapPushUrl: string = 'URL';
294
295// Configure the parameters (including the callback) for downloading MMS messages.
296let mmsPars: sms.MmsParams = {
297  slotId: 0,
298  mmsc: wapPushUrl,
299  data: filePath,
300  mmsConfig: {
301   userAgent:'ua',
302   userAgentProfile: 'uaprof'
303  }
304};
305
306// Call the downloadMms API.
307sms.downloadMms(context, mmsPars, async(err: BusinessError) =>{
308  if (err) {
309      console.error(`downloadMms fail, err : ${JSON.stringify(err)}`);
310      return;
311  }
312  console.log(`downloadMms Success`);
313})
314```
315
316Stage model:
317
318```ts
319import { UIAbility } from '@kit.AbilityKit';
320import { sms } from '@kit.TelephonyKit';
321import { BusinessError } from '@kit.BasicServicesKit';
322import { window } from '@kit.ArkUI';
323
324// Configure the path for storing the PDU of the MMS message.
325const sandBoxPath = '/data/storage/el2/base/files/';
326let filePath  = sandBoxPath + 'RetrieveConf.mms';
327
328// Parse the MMS URL from the WAP Push message.
329let wapPushUrl  = 'URL';
330
331// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements.
332let mmsConf: sms.MmsConfig = {
333  userAgent:'ua',
334  userAgentProfile: 'uaprof'
335};
336
337// Configure the parameters (including the callback) for downloading MMS messages.
338let mmsPars: sms.MmsParams = {
339  slotId : 0,
340  mmsc: wapPushUrl,
341  data: filePath,
342  mmsConfig: mmsConf
343};
344
345class EntryAbility extends UIAbility {
346    onWindowStageCreate(windowStage: window.WindowStage) {
347    sms.downloadMms(this.context, mmsPars, async(err: BusinessError) =>{
348        if (err) {
349            console.error(`downloadMms fail, err : ${JSON.stringify(err)}`);
350            return;
351        }
352        console.log(`downloadMms Success`);
353        });
354    }
355}
356```
357
358## sms.downloadMms<sup>11+</sup>
359
360downloadMms\(context: Context, mmsParams: MmsParams\): Promise&lt;void&gt;
361
362Sends an MMS message. This API uses a promise to return the result.
363
364**System API**: This is a system API.
365
366**Required permissions**: ohos.permission.RECEIVE_MMS
367
368**System capability**: SystemCapability.Telephony.SmsMms
369
370**Parameters**
371
372| Name  | Type                       | Mandatory| Description                                    |
373| -------- | --------------------------- | ---- | ---------------------------------------- |
374| context | Context          | Yes  | Application context.<br>For details about the application context of the FA model, see [Context](../apis-ability-kit/js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).|
375| mmsParams | [MmsParams](#mmsparams11) | Yes  | Parameters (including the callback) for sending MMS messages. For details, see [MmsParams](#mmsparams11).|
376
377**Return value**
378
379| Type           | Description                                                        |
380| --------------- | ------------------------------------------------------------ |
381| Promise&lt;void&gt; | Promise used to return the result.|
382
383**Error codes**
384
385For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
386
387| ID|                 Error Message                    |
388| -------- | -------------------------------------------- |
389| 201      | Permission denied.                           |
390| 202      | Non-system applications use system APIs.                           |
391| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
392| 8300001  | Invalid parameter value.                     |
393| 8300002  | Operation failed. Cannot connect to service. |
394| 8300003  | System internal error.                       |
395| 8300999  | Unknown error code.                          |
396
397**Example**
398
399FA model:
400<!--code_no_check_fa-->
401```ts
402import { sms } from '@kit.TelephonyKit';
403import { BusinessError } from '@kit.BasicServicesKit';
404import { common, featureAbility } from '@kit.AbilityKit';
405
406// Obtain the context.
407let context: common.BaseContext = featureAbility.getContext();
408
409// Configure the path for storing the PDU of the MMS message.
410const sandBoxPath: string = '/data/storage/el2/base/files/';
411let filePath: string = sandBoxPath + 'RetrieveConf.mms';
412
413// Parse the MMS URL from the WAP Push message.
414let wapPushUrl: string = 'URL';
415
416// Configure the parameters (including the callback) for downloading MMS messages.
417let mmsPars: sms.MmsParams = {
418  slotId: 0,
419  mmsc: wapPushUrl,
420  data: filePath,
421  mmsConfig: {
422   userAgent:'ua',
423   userAgentProfile: 'uaprof'
424  }
425};
426
427// Call the sendMms API.
428let promise = sms.downloadMms(context, mmsPars);
429promise.then(() => {
430    console.log(`downloadMms success`);
431}).catch((err: BusinessError) => {
432    console.error(`downloadMms failed, promise: err->${JSON.stringify(err)}`);
433});
434```
435
436Stage model:
437
438```ts
439import { UIAbility } from '@kit.AbilityKit';
440import { sms } from '@kit.TelephonyKit';
441import { BusinessError } from '@kit.BasicServicesKit';
442import { window } from '@kit.ArkUI';
443
444// Configure the path for storing the PDU of the MMS message.
445const sandBoxPath = '/data/storage/el2/base/files/';
446let filePath  = sandBoxPath + 'RetrieveConf.mms';
447
448// Parse the MMS URL from the WAP Push message.
449let wapPushUrl  = 'URL';
450
451// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements.
452let mmsConf: sms.MmsConfig = {
453  userAgent:'ua',
454  userAgentProfile: 'uaprof'
455};
456
457// Configure the parameters (including the callback) for downloading MMS messages.
458let mmsPars: sms.MmsParams = {
459  slotId : 0,
460  mmsc: wapPushUrl,
461  data: filePath,
462  mmsConfig: mmsConf
463};
464
465class EntryAbility extends UIAbility {
466    onWindowStageCreate(windowStage: window.WindowStage) {
467    let promise = sms.downloadMms(this.context, mmsPars);
468    promise.then(() => {
469        console.log(`downloadMms success`);
470    }).catch((err: BusinessError) => {
471        console.error(`downloadMms failed, promise: err->${JSON.stringify(err)}`);
472    });
473    }
474}
475```
476
477
478## sms.setDefaultSmsSlotId<sup>7+</sup>
479
480setDefaultSmsSlotId\(slotId: number, callback: AsyncCallback&lt;void&gt;\): void
481
482Sets the default slot ID of the SIM card used to send SMS messages. This API uses an asynchronous callback to return the result.
483
484**System API**: This is a system API.
485
486**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
487
488**System capability**: SystemCapability.Telephony.SmsMms
489
490**Parameters**
491
492| Name  | Type                     | Mandatory| Description                                                        |
493| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
494| slotId   | number                    | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: Clears the default configuration.|
495| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                                                  |
496
497**Error codes**
498
499For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
500
501| ID|                 Error Message                    |
502| -------- | -------------------------------------------- |
503| 201      | Permission denied.                           |
504| 202      | Non-system applications use system APIs.     |
505| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
506| 8300001  | Invalid parameter value.                     |
507| 8300002  | Operation failed. Cannot connect to service. |
508| 8300003  | System internal error.                       |
509| 8300004  | Do not have sim card.                        |
510| 8300999  | Unknown error code.                          |
511
512**Example**
513
514```ts
515import { sms } from '@kit.TelephonyKit';
516import { BusinessError } from '@kit.BasicServicesKit';
517
518sms.setDefaultSmsSlotId(0, (err: BusinessError) => {
519    console.log(`callback: err->${JSON.stringify(err)}.`);
520});
521```
522
523
524## sms.setDefaultSmsSlotId<sup>7+</sup>
525
526setDefaultSmsSlotId\(slotId: number\): Promise&lt;void&gt;
527
528Sets the default slot ID of the SIM card used to send SMS messages. This API uses a promise to return the result.
529
530**System API**: This is a system API.
531
532**Required permissions**: ohos.permission.SET_TELEPHONY_STATE
533
534**System capability**: SystemCapability.Telephony.SmsMms
535
536**Parameters**
537
538| Name| Type  | Mandatory| Description                                                        |
539| ------ | ------ | ---- | ------------------------------------------------------------ |
540| slotId | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2<br>- **-1**: Clears the default configuration.|
541
542**Return value**
543
544| Type           | Description                           |
545| --------------- | ------------------------------- |
546| Promise\<void\> | Promise used to return the result.|
547
548**Error codes**
549
550For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
551
552| ID|                 Error Message                    |
553| -------- | -------------------------------------------- |
554| 201      | Permission denied.                           |
555| 202      | Non-system applications use system APIs.     |
556| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
557| 8300001  | Invalid parameter value.                     |
558| 8300002  | Operation failed. Cannot connect to service. |
559| 8300003  | System internal error.                       |
560| 8300004  | Do not have sim card.                        |
561| 8300999  | Unknown error code.                          |
562
563**Example**
564
565```ts
566import { sms } from '@kit.TelephonyKit';
567import { BusinessError } from '@kit.BasicServicesKit';
568
569sms.setDefaultSmsSlotId(0).then(() => {
570    console.log(`setDefaultSmsSlotId success.`);
571}).catch((err: BusinessError) => {
572    console.error(`setDefaultSmsSlotId failed, promise: err->${JSON.stringify(err)}`);
573});
574```
575
576## sms.setSmscAddr<sup>7+</sup>
577
578setSmscAddr\(slotId: number, smscAddr: string, callback: AsyncCallback\<void\>\): void
579
580Sets the short message service center (SMSC) address. This API uses an asynchronous callback to return the result.
581
582**System API**: This is a system API.
583
584**Required permissions**: ohos.permission.SET_TELEPHONY_STATE (a system permission)
585
586**System capability**: SystemCapability.Telephony.SmsMms
587
588**Parameters**
589
590| Name  | Type                     | Mandatory| Description                                     |
591| -------- | ------------------------- | ---- | ----------------------------------------- |
592| slotId   | number                    | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
593| smscAddr | string                    | Yes  | SMSC address.                       |
594| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result.                               |
595
596**Error codes**
597
598For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
599
600| ID|                  Error Message                   |
601| -------- | -------------------------------------------- |
602| 201      | Permission denied.                           |
603| 202      | Non-system applications use system APIs.     |
604| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
605| 8300001  | Invalid parameter value.                     |
606| 8300002  | Operation failed. Cannot connect to service. |
607| 8300003  | System internal error.                       |
608| 8300999  | Unknown error code.                          |
609
610**Example**
611
612```ts
613import { sms } from '@kit.TelephonyKit';
614import { BusinessError } from '@kit.BasicServicesKit';
615
616let slotId: number = 0;
617let smscAddr: string = '+861xxxxxxxxxx';
618sms.setSmscAddr(slotId, smscAddr, (err: BusinessError) => {
619      console.log(`callback: err->${JSON.stringify(err)}`);
620});
621```
622
623
624## sms.setSmscAddr<sup>7+</sup>
625
626setSmscAddr\(slotId: number, smscAddr: string\): Promise\<void\>
627
628Sets the SMSC address. This API uses a promise to return the result.
629
630**System API**: This is a system API.
631
632**Required permissions**: ohos.permission.SET_TELEPHONY_STATE (a system permission)
633
634**System capability**: SystemCapability.Telephony.SmsMms
635
636**Parameters**
637
638| Name  | Type  | Mandatory| Description                                     |
639| -------- | ------ | ---- | ----------------------------------------- |
640| slotId   | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
641| smscAddr | string | Yes  | SMSC address.                       |
642
643**Return value**
644
645| Type               | Description                           |
646| ------------------- | ------------------------------- |
647| Promise&lt;void&gt; | Promise used to return the result.|
648
649**Error codes**
650
651For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
652
653| ID|                  Error Message                   |
654| -------- | -------------------------------------------- |
655| 201      | Permission denied.                           |
656| 202      | Non-system applications use system APIs.     |
657| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
658| 8300001  | Invalid parameter value.                     |
659| 8300002  | Operation failed. Cannot connect to service. |
660| 8300003  | System internal error.                       |
661| 8300999  | Unknown error code.                          |
662
663**Example**
664
665```ts
666import { sms } from '@kit.TelephonyKit';
667import { BusinessError } from '@kit.BasicServicesKit';
668
669let slotId: number = 0;
670let smscAddr: string = '+861xxxxxxxxxx';
671sms.setSmscAddr(slotId, smscAddr).then(() => {
672    console.log(`setSmscAddr success.`);
673}).catch((err: BusinessError) => {
674    console.error(`setSmscAddr failed, promise: err->${JSON.stringify(err)}`);
675});
676```
677
678
679## sms.getSmscAddr<sup>7+</sup>
680
681getSmscAddr\(slotId: number, callback: AsyncCallback\<string\>\): void
682
683Obtains the SMSC address. This API uses an asynchronous callback to return the result.
684
685**System API**: This is a system API.
686
687**Required permissions**: ohos.permission.GET_TELEPHONY_STATE (a system permission)
688
689**System capability**: SystemCapability.Telephony.SmsMms
690
691**Parameters**
692
693| Name  | Type                       | Mandatory| Description                                     |
694| -------- | --------------------------- | ---- | ----------------------------------------- |
695| slotId   | number                      | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
696| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.                               |
697
698**Error codes**
699
700For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
701
702| ID|                  Error Message                   |
703| -------- | -------------------------------------------- |
704| 201      | Permission denied.                           |
705| 202      | Non-system applications use system APIs.     |
706| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
707| 8300001  | Invalid parameter value.                     |
708| 8300002  | Operation failed. Cannot connect to service. |
709| 8300003  | System internal error.                       |
710| 8300999  | Unknown error code.                          |
711
712**Example**
713
714```ts
715import { sms } from '@kit.TelephonyKit';
716import { BusinessError } from '@kit.BasicServicesKit';
717
718let slotId: number = 0;
719sms.getSmscAddr(slotId, (err: BusinessError, data: string) => {
720      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
721});
722```
723
724
725## sms.getSmscAddr<sup>7+</sup>
726
727getSmscAddr\(slotId: number\): Promise\<string\>
728
729Obtains the SMSC address. This API uses a promise to return the result.
730
731**System API**: This is a system API.
732
733**Required permissions**: ohos.permission.GET_TELEPHONY_STATE (a system permission)
734
735**System capability**: SystemCapability.Telephony.SmsMms
736
737**Parameters**
738
739| Name| Type  | Mandatory| Description                                     |
740| ------ | ------ | ---- | ----------------------------------------- |
741| slotId | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
742
743**Return value**
744
745| Type                 | Description                                         |
746| --------------------- | --------------------------------------------- |
747| Promise&lt;string&gt; | Promise used to return the result.|
748
749**Error codes**
750
751For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
752
753| ID|                  Error Message                   |
754| -------- | -------------------------------------------- |
755| 201      | Permission denied.                           |
756| 202      | Non-system applications use system APIs.     |
757| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
758| 8300001  | Invalid parameter value.                     |
759| 8300002  | Operation failed. Cannot connect to service. |
760| 8300003  | System internal error.                       |
761| 8300999  | Unknown error code.                          |
762
763**Example**
764
765```ts
766import { sms } from '@kit.TelephonyKit';
767import { BusinessError } from '@kit.BasicServicesKit';
768
769let slotId: number = 0;
770sms.getSmscAddr(slotId).then((data: string) => {
771    console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`);
772}).catch((err: BusinessError) => {
773    console.error(`getSmscAddr failed, promise: err->${JSON.stringify(err)}`);
774});
775```
776
777
778## sms.splitMessage<sup>8+</sup>
779
780splitMessage\(content: string, callback: AsyncCallback\<Array\<string\>\>\): void
781
782Splits an SMS message into multiple segments. This API uses an asynchronous callback to return the result.
783
784**System API**: This is a system API.
785
786**Required permissions**: ohos.permission.SEND_MESSAGES
787
788**System capability**: SystemCapability.Telephony.SmsMms
789
790**Parameters**
791
792| Name  | Type                         | Mandatory| Description                         |
793| -------- | ----------------------------- | ---- | ----------------------------- |
794| content  | string                        | Yes  | SMS message content. The value cannot be null.|
795| callback | AsyncCallback<Array<string\>> | Yes  | Callback used to return the result.|
796
797**Error codes**
798
799For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
800
801| ID|                  Error Message                   |
802| -------- | -------------------------------------------- |
803| 201      | Permission denied.                           |
804| 202      | Non-system applications use system APIs.     |
805| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
806| 8300001  | Invalid parameter value.                     |
807| 8300002  | Operation failed. Cannot connect to service. |
808| 8300003  | System internal error.                       |
809| 8300999  | Unknown error code.                          |
810
811**Example**
812
813```ts
814import { sms } from '@kit.TelephonyKit';
815import { BusinessError } from '@kit.BasicServicesKit';
816
817let content: string = "long message";
818sms.splitMessage(content, (err: BusinessError, data: string[]) => {
819      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
820});
821```
822
823
824## sms.splitMessage<sup>8+</sup>
825
826splitMessage\(content: string\): Promise\<Array\<string\>\>
827
828Splits an SMS message into multiple segments. This API uses a promise to return the result.
829
830**System API**: This is a system API.
831
832**Required permissions**: ohos.permission.SEND_MESSAGES
833
834**System capability**: SystemCapability.Telephony.SmsMms
835
836**Parameters**
837
838| Name | Type  | Mandatory| Description                        |
839| ------- | ------ | ---- | ---------------------------- |
840| content | string | Yes  | SMS message content. The value cannot be null.|
841
842**Return value**
843
844| Type                   | Description                               |
845| ----------------------- | ----------------------------------- |
846| Promise<Array<string\>> | Promise used to return the result.|
847
848**Error codes**
849
850For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
851
852| ID|                  Error Message                   |
853| -------- | -------------------------------------------- |
854| 201      | Permission denied.                           |
855| 202      | Non-system applications use system APIs.     |
856| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
857| 8300001  | Invalid parameter value.                     |
858| 8300002  | Operation failed. Cannot connect to service. |
859| 8300003  | System internal error.                       |
860| 8300999  | Unknown error code.                          |
861
862**Example**
863
864```ts
865import { sms } from '@kit.TelephonyKit';
866import { BusinessError } from '@kit.BasicServicesKit';
867
868let content: string = "long message";
869let promise = sms.splitMessage(content);
870promise.then((data: string[]) => {
871    console.log(`splitMessage success, promise: data->${JSON.stringify(data)}`);
872}).catch((err: BusinessError) => {
873    console.error(`splitMessage failed, promise: err->${JSON.stringify(err)}`);
874});
875```
876
877## sms.addSimMessage<sup>7+</sup>
878
879addSimMessage\(options: SimMessageOptions, callback: AsyncCallback\<void\>\): void
880
881Adds a message to the SIM card. If the SIM card is full, an error is reported. This API uses an asynchronous callback to return the result.
882
883**System API**: This is a system API.
884
885**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
886
887**System capability**: SystemCapability.Telephony.SmsMms
888
889**Parameters**
890
891| Name  | Type                                    | Mandatory| Description           |
892| -------- | ---------------------------------------- | ---- | --------------- |
893| options  | [SimMessageOptions](#simmessageoptions7) | Yes  | SIM message options.|
894| callback | AsyncCallback&lt;void&gt;                | Yes  | Callback used to return the result.|
895
896**Error codes**
897
898For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
899
900| ID|                  Error Message                   |
901| -------- | -------------------------------------------- |
902| 201      | Permission denied.                           |
903| 202      | Non-system applications use system APIs.     |
904| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                           |
905| 8300001  | Invalid parameter value.                     |
906| 8300002  | Operation failed. Cannot connect to service. |
907| 8300003  | System internal error.                       |
908| 8300999  | Unknown error code.                          |
909
910**Example**
911
912```ts
913import { sms } from '@kit.TelephonyKit';
914import { BusinessError } from '@kit.BasicServicesKit';
915
916let simMessageOptions: sms.SimMessageOptions = {
917    slotId: 0,
918    smsc: "test",
919    pdu: "xxxxxx",
920    status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
921};
922sms.addSimMessage(simMessageOptions, (err: BusinessError) => {
923      console.log(`callback: err->${JSON.stringify(err)}`);
924});
925```
926
927
928## sms.addSimMessage<sup>7+</sup>
929
930addSimMessage\(options: SimMessageOptions\): Promise\<void\>
931
932Adds a message to the SIM card. If the SIM card is full, an error is reported. This API uses a promise to return the result.
933
934**System API**: This is a system API.
935
936**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
937
938**System capability**: SystemCapability.Telephony.SmsMms
939
940**Parameters**
941
942| Name | Type                                    | Mandatory| Description           |
943| ------- | ---------------------------------------- | ---- | --------------- |
944| options | [SimMessageOptions](#simmessageoptions7) | Yes  | SIM message options.|
945
946**Return value**
947
948| Type               | Description                         |
949| ------------------- | ----------------------------- |
950| Promise&lt;void&gt; | Promise used to return the result.|
951
952**Error codes**
953
954For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
955
956| ID|                  Error Message                   |
957| -------- | -------------------------------------------- |
958| 201      | Permission denied.                           |
959| 202      | Non-system applications use system APIs.     |
960| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
961| 8300001  | Invalid parameter value.                     |
962| 8300002  | Operation failed. Cannot connect to service. |
963| 8300003  | System internal error.                       |
964| 8300999  | Unknown error code.                          |
965
966**Example**
967
968```ts
969import { sms } from '@kit.TelephonyKit';
970import { BusinessError } from '@kit.BasicServicesKit';
971
972let simMessageOptions: sms.SimMessageOptions = {
973    slotId: 0,
974    smsc: "test",
975    pdu: "xxxxxx",
976    status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
977};
978sms.addSimMessage(simMessageOptions).then(() => {
979    console.log(`addSimMessage success.`);
980}).catch((err: BusinessError) => {
981    console.error(`addSimMessage failed, promise: err->${JSON.stringify(err)}`);
982});
983```
984
985## sms.delSimMessage<sup>7+</sup>
986
987delSimMessage\(slotId: number, msgIndex: number, callback: AsyncCallback\<void\>\): void
988
989Deletes a message from the SIM card. If the specified **msgIndex** is invalid, an error is reported. This API uses an asynchronous callback to return the result.
990
991**System API**: This is a system API.
992
993**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
994
995**System capability**: SystemCapability.Telephony.SmsMms
996
997**Parameters**
998
999| Name  | Type                     | Mandatory| Description                                     |
1000| -------- | ------------------------- | ---- | ----------------------------------------- |
1001| slotId   | number                    | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1002| msgIndex | number                    | Yes  | Message index.                                 |
1003| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. |
1004
1005**Error codes**
1006
1007For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1008
1009| ID|                  Error Message                   |
1010| -------- | -------------------------------------------- |
1011| 201      | Permission denied.                           |
1012| 202      | Non-system applications use system APIs.     |
1013| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
1014| 8300001  | Invalid parameter value.                     |
1015| 8300002  | Operation failed. Cannot connect to service. |
1016| 8300003  | System internal error.                       |
1017| 8300999  | Unknown error code.                          |
1018
1019**Example**
1020
1021```ts
1022import { sms } from '@kit.TelephonyKit';
1023import { BusinessError } from '@kit.BasicServicesKit';
1024
1025let slotId: number = 0;
1026let msgIndex: number = 1;
1027sms.delSimMessage(slotId, msgIndex, (err: BusinessError) => {
1028      console.log(`callback: err->${JSON.stringify(err)}`);
1029});
1030```
1031
1032
1033## sms.delSimMessage<sup>7+</sup>
1034
1035delSimMessage\(slotId: number, msgIndex: number\): Promise\<void\>
1036
1037Deletes a message from the SIM card. If the specified **msgIndex** is invalid, an error is reported. This API uses a promise to return the result.
1038
1039**System API**: This is a system API.
1040
1041**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
1042
1043**System capability**: SystemCapability.Telephony.SmsMms
1044
1045**Parameters**
1046
1047| Name  | Type  | Mandatory| Description                                     |
1048| -------- | ------ | ---- | ----------------------------------------- |
1049| slotId   | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1050| msgIndex | number | Yes  | Message index.                                 |
1051
1052**Return value**
1053
1054| Type               | Description                         |
1055| ------------------- | ----------------------------- |
1056| Promise&lt;void&gt; | Promise used to return the result.|
1057
1058**Error codes**
1059
1060For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1061
1062| ID|                  Error Message                   |
1063| -------- | -------------------------------------------- |
1064| 201      | Permission denied.                           |
1065| 202      | Non-system applications use system APIs.     |
1066| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                            |
1067| 8300001  | Invalid parameter value.                     |
1068| 8300002  | Operation failed. Cannot connect to service. |
1069| 8300003  | System internal error.                       |
1070| 8300999  | Unknown error code.                          |
1071
1072**Example**
1073
1074```ts
1075import { sms } from '@kit.TelephonyKit';
1076import { BusinessError } from '@kit.BasicServicesKit';
1077
1078let slotId: number = 0;
1079let msgIndex: number = 1;
1080let promise = sms.delSimMessage(slotId, msgIndex);
1081promise.then(() => {
1082    console.log(`delSimMessage success.`);
1083}).catch((err: BusinessError) => {
1084    console.error(`delSimMessage failed, promise: err->${JSON.stringify(err)}`);
1085});
1086```
1087
1088## sms.updateSimMessage<sup>7+</sup>
1089
1090updateSimMessage\(options: UpdateSimMessageOptions, callback: AsyncCallback\<void\>\): void
1091
1092Updates a SIM message. This API uses an asynchronous callback to return the result.
1093
1094**System API**: This is a system API.
1095
1096**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
1097
1098**System capability**: SystemCapability.Telephony.SmsMms
1099
1100**Parameters**
1101
1102| Name  | Type                                                | Mandatory| Description               |
1103| -------- | ---------------------------------------------------- | ---- | ------------------- |
1104| options  | [UpdateSimMessageOptions](#updatesimmessageoptions7) | Yes  | SIM message updating options.|
1105| callback | AsyncCallback&lt;void&gt;                            | Yes  | Callback used to return the result.|
1106
1107**Error codes**
1108
1109For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1110
1111| ID|                  Error Message                   |
1112| -------- | -------------------------------------------- |
1113| 201      | Permission denied.                           |
1114| 202      | Non-system applications use system APIs.     |
1115| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1116| 8300001  | Invalid parameter value.                     |
1117| 8300002  | Operation failed. Cannot connect to service. |
1118| 8300003  | System internal error.                       |
1119| 8300999  | Unknown error code.                          |
1120
1121**Example**
1122
1123```ts
1124import { sms } from '@kit.TelephonyKit';
1125import { BusinessError } from '@kit.BasicServicesKit';
1126
1127let updateSimMessageOptions: sms.UpdateSimMessageOptions = {
1128    slotId: 0,
1129    msgIndex: 1,
1130    newStatus: sms.SimMessageStatus.SIM_MESSAGE_STATUS_FREE,
1131    pdu: "xxxxxxx",
1132    smsc: "test"
1133};
1134sms.updateSimMessage(updateSimMessageOptions, (err: BusinessError) => {
1135      console.log(`callback: err->${JSON.stringify(err)}`);
1136});
1137```
1138
1139
1140## sms.updateSimMessage<sup>7+</sup>
1141
1142updateSimMessage\(options: UpdateSimMessageOptions\): Promise\<void\>
1143
1144Updates a SIM message. This API uses a promise to return the result.
1145
1146**System API**: This is a system API.
1147
1148**Required permissions**: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES
1149
1150**System capability**: SystemCapability.Telephony.SmsMms
1151
1152**Parameters**
1153
1154| Name | Type                                                | Mandatory| Description               |
1155| ------- | ---------------------------------------------------- | ---- | ------------------- |
1156| options | [UpdateSimMessageOptions](#updatesimmessageoptions7) | Yes  | SIM message updating options.|
1157
1158**Return value**
1159
1160| Type               | Description                         |
1161| ------------------- | ----------------------------- |
1162| Promise&lt;void&gt; | Promise used to return the result.|
1163
1164**Error codes**
1165
1166For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1167
1168| ID|                  Error Message                   |
1169| -------- | -------------------------------------------- |
1170| 201      | Permission denied.                           |
1171| 202      | Non-system applications use system APIs.     |
1172| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1173| 8300001  | Invalid parameter value.                     |
1174| 8300002  | Operation failed. Cannot connect to service. |
1175| 8300003  | System internal error.                       |
1176| 8300999  | Unknown error code.                          |
1177
1178**Example**
1179
1180```ts
1181import { sms } from '@kit.TelephonyKit';
1182import { BusinessError } from '@kit.BasicServicesKit';
1183
1184let updateSimMessageOptions: sms.UpdateSimMessageOptions = {
1185    slotId: 0,
1186    msgIndex: 1,
1187    newStatus: sms.SimMessageStatus.SIM_MESSAGE_STATUS_FREE,
1188    pdu: "xxxxxxx",
1189    smsc: "test"
1190};
1191let promise = sms.updateSimMessage(updateSimMessageOptions);
1192promise.then(() => {
1193    console.log(`updateSimMessage success.`);
1194}).catch((err: BusinessError) => {
1195    console.error(`updateSimMessage failed, promise: err->${JSON.stringify(err)}`);
1196});
1197```
1198
1199## sms.getAllSimMessages<sup>7+</sup>
1200
1201getAllSimMessages\(slotId: number, callback: AsyncCallback\<Array\<SimShortMessage\>\>\): void
1202
1203Obtains all SIM card messages. This API uses an asynchronous callback to return the result.
1204
1205**System API**: This is a system API.
1206
1207**Required permissions**: ohos.permission.RECEIVE_SMS
1208
1209**System capability**: SystemCapability.Telephony.SmsMms
1210
1211**Parameters**
1212
1213| Name  | Type                                                       | Mandatory| Description                                     |
1214| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------- |
1215| slotId   | number                                                      | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1216| callback | AsyncCallback<Array<[SimShortMessage](#simshortmessage7)\>> | Yes  | Callback used to return the result. |
1217
1218**Error codes**
1219
1220For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1221
1222| ID|                  Error Message                   |
1223| -------- | -------------------------------------------- |
1224| 201      | Permission denied.                           |
1225| 202      | Non-system applications use system APIs.     |
1226| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                         |
1227| 8300001  | Invalid parameter value.                     |
1228| 8300002  | Operation failed. Cannot connect to service. |
1229| 8300003  | System internal error.                       |
1230| 8300999  | Unknown error code.                          |
1231
1232**Example**
1233
1234```ts
1235import { sms } from '@kit.TelephonyKit';
1236import { BusinessError } from '@kit.BasicServicesKit';
1237
1238let slotId: number = 0;
1239sms.getAllSimMessages(slotId, (err: BusinessError, data: sms.SimShortMessage[]) => {
1240      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1241});
1242```
1243
1244
1245## sms.getAllSimMessages<sup>7+</sup>
1246
1247getAllSimMessages\(slotId: number\): Promise\<Array\<SimShortMessage\>\>
1248
1249Obtains all SIM card messages. This API uses a promise to return the result.
1250
1251**System API**: This is a system API.
1252
1253**Required permissions**: ohos.permission.RECEIVE_SMS
1254
1255**System capability**: SystemCapability.Telephony.SmsMms
1256
1257**Parameters**
1258
1259| Name| Type  | Mandatory| Description                                     |
1260| ------ | ------ | ---- | ----------------------------------------- |
1261| slotId | number | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1262
1263**Return value**
1264
1265| Type                                                   | Description                              |
1266| ------------------------------------------------------- | ---------------------------------- |
1267| Promise<Array<[SimShortMessage](#simshortmessage7)\>&gt; | Promise used to return the result.|
1268
1269**Error codes**
1270
1271For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1272
1273| ID|                  Error Message                   |
1274| -------- | -------------------------------------------- |
1275| 201      | Permission denied.                           |
1276| 202      | Non-system applications use system APIs.     |
1277| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                           |
1278| 8300001  | Invalid parameter value.                     |
1279| 8300002  | Operation failed. Cannot connect to service. |
1280| 8300003  | System internal error.                       |
1281| 8300999  | Unknown error code.                          |
1282
1283**Example**
1284
1285```ts
1286import { sms } from '@kit.TelephonyKit';
1287import { BusinessError } from '@kit.BasicServicesKit';
1288
1289let slotId: number = 0;
1290let promise = sms.getAllSimMessages(slotId);
1291promise.then((data: sms.SimShortMessage[]) => {
1292    console.log(`getAllSimMessages success, promise: data->${JSON.stringify(data)}`);
1293}).catch((err: BusinessError) => {
1294    console.error(`getAllSimMessages failed, promise: err->${JSON.stringify(err)}`);
1295});
1296```
1297
1298## sms.setCBConfig<sup>7+</sup>
1299
1300setCBConfig\(options: CBConfigOptions, callback: AsyncCallback\<void\>\): void
1301
1302Sets the cell broadcast configuration. This API uses an asynchronous callback to return the result.
1303
1304**System API**: This is a system API.
1305
1306**Required permissions**: ohos.permission.RECEIVE_SMS
1307
1308**System capability**: SystemCapability.Telephony.SmsMms
1309
1310**Parameters**
1311
1312| Name  | Type                                | Mandatory| Description        |
1313| -------- | ------------------------------------ | ---- | ------------ |
1314| options  | [CBConfigOptions](#cbconfigoptions7) | Yes  | Cell broadcast configuration options.|
1315| callback | AsyncCallback&lt;void&gt;            | Yes  | Callback used to return the result. |
1316
1317**Error codes**
1318
1319For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1320
1321| ID|                  Error Message                   |
1322| -------- | -------------------------------------------- |
1323| 201      | Permission denied.                           |
1324| 202      | Non-system applications use system APIs.     |
1325| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                         |
1326| 8300001  | Invalid parameter value.                     |
1327| 8300002  | Operation failed. Cannot connect to service. |
1328| 8300003  | System internal error.                       |
1329| 8300999  | Unknown error code.                          |
1330
1331**Example**
1332
1333```ts
1334import { sms } from '@kit.TelephonyKit';
1335import { BusinessError } from '@kit.BasicServicesKit';
1336
1337let cbConfigOptions: sms.CBConfigOptions = {
1338    slotId: 0,
1339    enable: true,
1340    startMessageId: 100,
1341    endMessageId: 200,
1342    ranType: sms.RanType.TYPE_GSM
1343};
1344sms.setCBConfig(cbConfigOptions, (err: BusinessError) => {
1345      console.log(`callback: err->${JSON.stringify(err)}`);
1346});
1347```
1348
1349
1350## sms.setCBConfig<sup>7+</sup>
1351
1352setCBConfig\(options: CBConfigOptions\): Promise\<void\>
1353
1354Sets the cell broadcast configuration. This API uses a promise to return the result.
1355
1356**System API**: This is a system API.
1357
1358**Required permissions**: ohos.permission.RECEIVE_SMS
1359
1360**System capability**: SystemCapability.Telephony.SmsMms
1361
1362**Parameters**
1363
1364| Name | Type                                | Mandatory| Description        |
1365| ------- | ------------------------------------ | ---- | ------------ |
1366| options | [CBConfigOptions](#cbconfigoptions7) | Yes  | Cell broadcast configuration options.|
1367
1368**Return value**
1369
1370| Type               | Description                         |
1371| ------------------- | ----------------------------- |
1372| Promise&lt;void&gt; | Promise used to return the result.|
1373
1374**Error codes**
1375
1376For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1377
1378| ID|                  Error Message                   |
1379| -------- | -------------------------------------------- |
1380| 201      | Permission denied.                           |
1381| 202      | Non-system applications use system APIs.     |
1382| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                         |
1383| 8300001  | Invalid parameter value.                     |
1384| 8300002  | Operation failed. Cannot connect to service. |
1385| 8300003  | System internal error.                       |
1386| 8300999  | Unknown error code.                          |
1387
1388**Example**
1389
1390```ts
1391import { sms } from '@kit.TelephonyKit';
1392import { BusinessError } from '@kit.BasicServicesKit';
1393
1394let cbConfigOptions: sms.CBConfigOptions = {
1395    slotId: 0,
1396    enable: true,
1397    startMessageId: 100,
1398    endMessageId: 200,
1399    ranType: sms.RanType.TYPE_GSM
1400};
1401let promise = sms.setCBConfig(cbConfigOptions);
1402promise.then(() => {
1403    console.log(`setCBConfig success.`);
1404}).catch((err: BusinessError) => {
1405    console.error(`setCBConfig failed, promise: err->${JSON.stringify(err)}`);
1406});
1407```
1408
1409## sms.getSmsSegmentsInfo<sup>8+</sup>
1410
1411getSmsSegmentsInfo\(slotId: number, message: string, force7bit: boolean, callback: AsyncCallback\<SmsSegmentsInfo\>\): void
1412
1413Obtains SMS message segment information. This API uses an asynchronous callback to return the result.
1414
1415**System API**: This is a system API.
1416
1417**System capability**: SystemCapability.Telephony.SmsMms
1418
1419**Parameters**
1420
1421| Name   | Type                                                        | Mandatory| Description                                     |
1422| --------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
1423| slotId    | number                                                       | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1424| message   | string                                                       | Yes  | SMS message.                                     |
1425| force7bit | boolean                                                      | Yes  | Whether to use 7-bit coding.                         |
1426| callback  | AsyncCallback&lt;[SmsSegmentsInfo](#smssegmentsinfo8)&gt; | Yes  | Callback used to return the result. |
1427
1428**Error codes**
1429
1430For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1431
1432| ID|                 Error Message                    |
1433| -------- | -------------------------------------------- |
1434| 202      | Non-system applications use system APIs.     |
1435| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1436| 8300001  | Invalid parameter value.                     |
1437| 8300002  | Operation failed. Cannot connect to service. |
1438| 8300003  | System internal error.                       |
1439| 8300999  | Unknown error code.                          |
1440
1441**Example**
1442
1443```ts
1444import { sms } from '@kit.TelephonyKit';
1445import { BusinessError } from '@kit.BasicServicesKit';
1446
1447let slotId: number = 0;
1448sms.getSmsSegmentsInfo(slotId, "message", false, (err: BusinessError, data: sms.SmsSegmentsInfo) => {
1449      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1450});
1451```
1452
1453
1454## sms.getSmsSegmentsInfo<sup>8+</sup>
1455
1456getSmsSegmentsInfo\(slotId: number, message: string, force7bit: boolean\): Promise\<SmsSegmentsInfo\>
1457
1458Obtains SMS message segment information. This API uses a promise to return the result.
1459
1460**System API**: This is a system API.
1461
1462**System capability**: SystemCapability.Telephony.SmsMms
1463
1464**Parameters**
1465
1466| Name   | Type   | Mandatory| Description                                     |
1467| --------- | ------- | ---- | ----------------------------------------- |
1468| slotId    | number  | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1469| message   | string  | Yes  | SMS message.                                     |
1470| force7bit | boolean | Yes  | Whether to use 7-bit coding.                         |
1471
1472**Return value**
1473
1474| Type                                                   | Description                         |
1475| ------------------------------------------------------- | ----------------------------- |
1476| Promise&lt;[SmsSegmentsInfo](#smssegmentsinfo8)&gt; | Promise used to return the result.|
1477
1478**Error codes**
1479
1480For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1481
1482| ID|                 Error Message                    |
1483| -------- | -------------------------------------------- |
1484| 202      | Non-system applications use system APIs.     |
1485| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1486| 8300001  | Invalid parameter value.                     |
1487| 8300002  | Operation failed. Cannot connect to service. |
1488| 8300003  | System internal error.                       |
1489| 8300999  | Unknown error code.                          |
1490
1491**Example**
1492
1493```ts
1494import { sms } from '@kit.TelephonyKit';
1495import { BusinessError } from '@kit.BasicServicesKit';
1496
1497let slotId: number = 0;
1498let promise = sms.getSmsSegmentsInfo(slotId, "message", false);
1499promise.then((data: sms.SmsSegmentsInfo) => {
1500    console.log(`getSmsSegmentsInfo success, promise: data->${JSON.stringify(data)}`);
1501}).catch((err: BusinessError) => {
1502    console.error(`getSmsSegmentsInfo failed, promise: err->${JSON.stringify(err)}`);
1503});
1504```
1505
1506## sms.isImsSmsSupported<sup>8+</sup>
1507
1508isImsSmsSupported\(slotId: number, callback: AsyncCallback\<boolean\>\): void
1509
1510Checks whether SMS is supported on IMS. This API uses an asynchronous callback to return the result.
1511
1512**System API**: This is a system API.
1513
1514**System capability**: SystemCapability.Telephony.SmsMms
1515
1516**Parameters**
1517
1518| Name  | Type                        | Mandatory| Description      |
1519| -------- | ---------------------------- | ---- | ---------- |
1520| slotId   | number                       | Yes  | SIM card slot ID. <br>- **0**: card slot 1<br>- **1**: card slot 2|
1521| callback | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result.|
1522
1523**Error codes**
1524
1525For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1526
1527| ID|                 Error Message                    |
1528| -------- | -------------------------------------------- |
1529| 202      | Non-system applications use system APIs.     |
1530| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                          |
1531| 8300001  | Invalid parameter value.                     |
1532| 8300002  | Operation failed. Cannot connect to service. |
1533| 8300003  | System internal error.                       |
1534| 8300999  | Unknown error code.                          |
1535
1536**Example**
1537
1538```ts
1539import { sms } from '@kit.TelephonyKit';
1540import { BusinessError } from '@kit.BasicServicesKit';
1541
1542let slotId: number = 0;
1543sms.isImsSmsSupported(slotId, (err: BusinessError, data: boolean) => {
1544      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1545});
1546```
1547
1548
1549## sms.isImsSmsSupported<sup>8+</sup>
1550
1551isImsSmsSupported\(slotId: number\): Promise\<boolean\>
1552
1553Checks whether SMS is supported on IMS. This API uses a promise to return the result.
1554
1555**System API**: This is a system API.
1556
1557**System capability**: SystemCapability.Telephony.SmsMms
1558
1559**Parameters**
1560
1561| Name| Type  | Mandatory | Description                                 |
1562| ------ | ------ | ---- | -------------------------------------- |
1563| slotId | number | Yes  | Card slot ID.<br>- **0**: card slot 1<br>- **1**: card slot 2|
1564
1565**Return value**
1566
1567| Type                  | Description                   |
1568| ---------------------- | ----------------------- |
1569| Promise&lt;boolean&gt; | Promise used to return the result.|
1570
1571**Error codes**
1572
1573For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1574
1575| ID|                 Error Message                    |
1576| -------- | -------------------------------------------- |
1577| 202      | Non-system applications use system APIs.     |
1578| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                         |
1579| 8300001  | Invalid parameter value.                     |
1580| 8300002  | Operation failed. Cannot connect to service. |
1581| 8300003  | System internal error.                       |
1582| 8300999  | Unknown error code.                          |
1583
1584**Example**
1585
1586```ts
1587import { sms } from '@kit.TelephonyKit';
1588import { BusinessError } from '@kit.BasicServicesKit';
1589
1590let slotId: number = 0;
1591let promise = sms.isImsSmsSupported(slotId);
1592promise.then((data: boolean) => {
1593    console.log(`isImsSmsSupported success, promise: data->${JSON.stringify(data)}`);
1594}).catch((err: BusinessError) => {
1595    console.error(`isImsSmsSupported failed, promise: err->${JSON.stringify(err)}`);
1596});
1597```
1598
1599## sms.getImsShortMessageFormat<sup>8+</sup>
1600
1601getImsShortMessageFormat\(callback: AsyncCallback\<string\>\): void
1602
1603Obtains the SMS format supported by the IMS, for example, **3gpp**, **3gpp2**, or **unknown**. This API uses an asynchronous callback to return the result.
1604
1605**System API**: This is a system API.
1606
1607**System capability**: SystemCapability.Telephony.SmsMms
1608
1609**Parameters**
1610
1611| Name  | Type                       | Mandatory| Description      |
1612| -------- | --------------------------- | ---- | ---------- |
1613| callback | AsyncCallback&lt;string&gt; | Yes  | Callback used to return the result.|
1614
1615**Error codes**
1616
1617For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1618
1619| ID|                  Error Message                   |
1620| -------- | -------------------------------------------- |
1621| 202      | Non-system applications use system APIs.     |
1622| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.                           |
1623| 8300001  | Invalid parameter value.                     |
1624| 8300002  | Operation failed. Cannot connect to service. |
1625| 8300003  | System internal error.                       |
1626| 8300999  | Unknown error code.                          |
1627
1628**Example**
1629
1630```ts
1631import { sms } from '@kit.TelephonyKit';
1632import { BusinessError } from '@kit.BasicServicesKit';
1633
1634sms.getImsShortMessageFormat((err: BusinessError, data: string) => {
1635      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1636});
1637```
1638
1639
1640## sms.getImsShortMessageFormat<sup>8+</sup>
1641
1642getImsShortMessageFormat\(\): Promise\<string\>
1643
1644Obtains the SMS format supported by the IMS, for example, **3gpp**, **3gpp2**, or **unknown**. This API uses a promise to return the result.
1645
1646**System API**: This is a system API.
1647
1648**System capability**: SystemCapability.Telephony.SmsMms
1649
1650**Return value**
1651
1652| Type                 | Description                      |
1653| --------------------- | -------------------------- |
1654| Promise&lt;string&gt; | Promise used to return the result. |
1655
1656**Error codes**
1657
1658For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1659
1660| ID|                  Error Message                   |
1661| -------- | -------------------------------------------- |
1662| 202      | Non-system applications use system APIs.     |
1663| 8300002  | Operation failed. Cannot connect to service. |
1664| 8300003  | System internal error.                       |
1665| 8300999  | Unknown error code.                          |
1666
1667**Example**
1668
1669```ts
1670import { sms } from '@kit.TelephonyKit';
1671import { BusinessError } from '@kit.BasicServicesKit';
1672
1673sms.getImsShortMessageFormat().then((data: string) => {
1674    console.log(`getImsShortMessageFormat success, promise: data->${JSON.stringify(data)}`);
1675}).catch((err: BusinessError) => {
1676    console.error(`getImsShortMessageFormat failed, promise: err->${JSON.stringify(err)}`);
1677});
1678```
1679
1680## sms.decodeMms<sup>8+</sup>
1681
1682decodeMms\(mmsFilePathName: string | Array\<number\>, callback: AsyncCallback\<MmsInformation\>\): void
1683
1684Decodes MMS messages. This API uses an asynchronous callback to return the result.
1685
1686**System API**: This is a system API.
1687
1688**System capability**: SystemCapability.Telephony.SmsMms
1689
1690**Parameters**
1691
1692| Name         | Type                                                   | Mandatory| Description          |
1693| --------------- | ------------------------------------------------------- | ---- | -------------- |
1694| mmsFilePathName | string \|Array<number\>                                 | Yes  | MMS message file path.|
1695| callback        | AsyncCallback&lt;[MmsInformation](#mmsinformation8)&gt; | Yes  | Callback used to return the result, which is carried in {@code MmsInformation}.    |
1696
1697**Error codes**
1698
1699For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1700
1701| ID|                 Error Message                    |
1702| -------- | -------------------------------------------- |
1703| 202      | Non-system applications use system APIs.     |
1704| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1705| 8300001  | Invalid parameter value.                     |
1706| 8300002  | Operation failed. Cannot connect to service. |
1707| 8300003  | System internal error.                       |
1708| 8300999  | Unknown error code.                          |
1709
1710**Example**
1711
1712```ts
1713import { sms } from '@kit.TelephonyKit';
1714import { BusinessError } from '@kit.BasicServicesKit';
1715
1716let mmsFilePathName: string = "filename";
1717sms.decodeMms(mmsFilePathName, (err: BusinessError, data: sms.MmsInformation) => {
1718      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1719});
1720
1721const mmsPdu: Array<number> = [0x8c, 0x80, 0x98, 0x31, 0x00, 0x8d, 0x92, 0x89, 0x09, 0x80, 0x07, 0xea, 0x31, 0x30, 0x30, 0x38, 0x36, 0x00, 0x97, 0x07, 0xea, 0x31, 0x30, 0x30,0x31, 0x30, 0x00, 0x84, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00];
1722sms.decodeMms(mmsPdu, (err: BusinessError, data: sms.MmsInformation) => {
1723    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1724});
1725```
1726
1727
1728## sms.decodeMms<sup>8+</sup>
1729
1730decodeMms\(mmsFilePathName: string | Array\<number\>\): Promise\<MmsInformation\>
1731
1732Decodes MMS messages. This API uses a promise to return the result.
1733
1734**System API**: This is a system API.
1735
1736**System capability**: SystemCapability.Telephony.SmsMms
1737
1738**Parameters**
1739
1740| Name         | Type                   | Mandatory| Description          |
1741| --------------- | ----------------------- | ---- | -------------- |
1742| mmsFilePathName | string \|Array<number\> | Yes  | MMS message file path.|
1743
1744**Return value**
1745
1746| Type                                                     | Description                       |
1747| --------------------------------------------------------- | --------------------------- |
1748| Promise&lt;&lt;[MmsInformation](#mmsinformation8)&gt;&gt; | Promise used to return the result.|
1749
1750**Error codes**
1751
1752For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1753
1754| ID|                 Error Message                    |
1755| -------- | -------------------------------------------- |
1756| 202      | Non-system applications use system APIs.     |
1757| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1758| 8300001  | Invalid parameter value.                     |
1759| 8300002  | Operation failed. Cannot connect to service. |
1760| 8300003  | System internal error.                       |
1761| 8300999  | Unknown error code.                          |
1762
1763**Example**
1764
1765```ts
1766import { sms } from '@kit.TelephonyKit';
1767import { BusinessError } from '@kit.BasicServicesKit';
1768
1769let mmsFilePathName: string = "filename";
1770let promise = sms.decodeMms(mmsFilePathName);
1771promise.then((data: sms.MmsInformation) => {
1772    console.log(`decodeMms success, promise: data->${JSON.stringify(data)}`);
1773}).catch((err: BusinessError) => {
1774    console.error(`decodeMms failed, promise: err->${JSON.stringify(err)}`);
1775});
1776
1777const mmsPdu: Array<number> = [0x8c, 0x80, 0x98, 0x31, 0x00, 0x8d, 0x92, 0x89, 0x09, 0x80, 0x07, 0xea, 0x31, 0x30, 0x30, 0x38, 0x36, 0x00, 0x97, 0x07, 0xea, 0x31, 0x30, 0x30,0x31, 0x30, 0x00, 0x84, 0x74, 0x79, 0x70, 0x65, 0x00, 0x00];
1778let promiseArr = sms.decodeMms(mmsPdu);
1779promiseArr.then((data: sms.MmsInformation) => {
1780    console.log(`decodeMms success, promise: data->${JSON.stringify(data)}`);
1781}).catch((err: BusinessError) => {
1782    console.error(`decodeMms failed, promise: err->${JSON.stringify(err)}`);
1783});
1784```
1785
1786## sms.encodeMms<sup>8+</sup>
1787
1788encodeMms\(mms: MmsInformation, callback: AsyncCallback\<Array\<number\>\>\): void
1789
1790MMS message code. This API uses an asynchronous callback to return the result.
1791
1792**System API**: This is a system API.
1793
1794**System capability**: SystemCapability.Telephony.SmsMms
1795
1796**Parameters**
1797
1798| Name  | Type                               | Mandatory| Description      |
1799| -------- | ----------------------------------- | ---- | ---------- |
1800| mms      | [MmsInformation](#mmsinformation8)  | Yes  | MMS message information.|
1801| callback | AsyncCallback&lt;Array<number\>&gt; | Yes  | Callback used to return the result.|
1802
1803**Error codes**
1804
1805For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1806
1807| ID|                 Error Message                    |
1808| -------- | -------------------------------------------- |
1809| 202      | Non-system applications use system APIs.     |
1810| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1811| 8300001  | Invalid parameter value.                     |
1812| 8300002  | Operation failed. Cannot connect to service. |
1813| 8300003  | System internal error.                       |
1814| 8300999  | Unknown error code.                          |
1815
1816**Example**
1817
1818```ts
1819import { sms } from '@kit.TelephonyKit';
1820import { BusinessError } from '@kit.BasicServicesKit';
1821
1822let mmsAcknowledgeInd: sms.MmsAcknowledgeInd = {
1823    transactionId: "100",
1824    version: sms.MmsVersionType.MMS_VERSION_1_0,
1825    reportAllowed: sms.ReportType.MMS_YES
1826};
1827let mmsInformation: sms.MmsInformation = {
1828    messageType: sms.MessageType.TYPE_MMS_ACKNOWLEDGE_IND,
1829    mmsType: mmsAcknowledgeInd
1830};
1831sms.encodeMms(mmsInformation, (err: BusinessError, data: number[]) => {
1832      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
1833});
1834```
1835
1836
1837## sms.encodeMms<sup>8+</sup>
1838
1839encodeMms\(mms: MmsInformation\): Promise\<Array\<number\>\>
1840
1841MMS message code. This API uses a promise to return the result.
1842
1843**System API**: This is a system API.
1844
1845**System capability**: SystemCapability.Telephony.SmsMms
1846
1847**Parameters**
1848
1849| Name| Type                              | Mandatory| Description      |
1850| ------ | ---------------------------------- | ---- | ---------- |
1851| mms    | [MmsInformation](#mmsinformation8) | Yes  | MMS message information.|
1852
1853**Return value**
1854
1855| Type                         | Description                               |
1856| ----------------------------- | ----------------------------------- |
1857| Promise&lt;Array<number\>&gt; | Promise used to return the result.|
1858
1859**Error codes**
1860
1861For details about the error codes, see [Telephony Error Codes](errorcode-telephony.md).
1862
1863| ID|                 Error Message                    |
1864| -------- | -------------------------------------------- |
1865| 202      | Non-system applications use system APIs.     |
1866| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.                            |
1867| 8300001  | Invalid parameter value.                     |
1868| 8300002  | Operation failed. Cannot connect to service. |
1869| 8300003  | System internal error.                       |
1870| 8300999  | Unknown error code.                          |
1871
1872**Example**
1873
1874```ts
1875import { sms } from '@kit.TelephonyKit';
1876import { BusinessError } from '@kit.BasicServicesKit';
1877
1878let mmsAcknowledgeInd: sms.MmsAcknowledgeInd = {
1879    transactionId: "100",
1880    version: sms.MmsVersionType.MMS_VERSION_1_0,
1881    reportAllowed: sms.ReportType.MMS_YES
1882};
1883let mmsInformation: sms.MmsInformation = {
1884    messageType: sms.MessageType.TYPE_MMS_ACKNOWLEDGE_IND,
1885    mmsType: mmsAcknowledgeInd
1886};
1887sms.encodeMms(mmsInformation).then((data: number[]) => {
1888    console.log(`encodeMms success, promise: data->${JSON.stringify(data)}`);
1889}).catch((err: BusinessError) => {
1890    console.error(`encodeMms failed, promise: err->${JSON.stringify(err)}`);
1891});
1892```
1893
1894
1895## MmsParams<sup>11+</sup>
1896
1897Defines the parameters for sending SMS messages.
1898
1899**System API**: This is a system API.
1900
1901**System capability**: SystemCapability.Telephony.SmsMms
1902
1903|       Name      | Type                                                        | Mandatory| Description                                                        |
1904| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1905| slotId<sup>11+</sup>           | number                                                       | Yes  | Slot ID of the SIM card used for sending SMS messages. <br>- **0**: card slot 1<br>- **1**: card slot 2     |
1906| mmsc<sup>11+</sup>  | string                                                       | Yes  | MMSC address.                                            |
1907| data<sup>11+</sup>          | string                               | Yes  | MMS PDU address.|
1908| mmsConfig<sup>11+</sup>    | MmsConfig                                                       | No  | MMS configuration file. For details, see [MmsParams](#mmsparams11).               |
1909
1910## MmsConfig<sup>11+</sup>
1911
1912MMS configuration file.
1913
1914**System API**: This is a system API.
1915
1916**System capability**: SystemCapability.Telephony.SmsMms
1917
1918|       Name      | Type                                                        | Mandatory| Description                                                        |
1919| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1920| userAgent<sup>11+</sup>  | string                                                       | Yes  | User agent.                                            |
1921| userAgentProfile<sup>11+</sup>    | string                                                       | Yes  | User agent profile.               |
1922
1923
1924
1925## MmsInformation<sup>8+</sup>
1926
1927Defines the MMS message information.
1928
1929**System API**: This is a system API.
1930
1931**System capability**: SystemCapability.Telephony.SmsMms
1932
1933|     Name   | Type                                                        | Mandatory|    Description   |
1934| ----------- | ------------------------------------------------------------ | ---- | ---------- |
1935| messageType | [MessageType](#messagetype8)                                 | Yes  | Message type.|
1936| mmsType     | [MmsSendReq](#mmssendreq8) \|[MmsSendConf](#mmssendconf8) \|[MmsNotificationInd](#mmsnotificationind8) \|[MmsRespInd](#mmsrespind8) \|[MmsRetrieveConf](#mmsretrieveconf8)\|[MmsAcknowledgeInd](#mmsacknowledgeind8)\|[MmsDeliveryInd](#mmsdeliveryind8)\|[MmsReadOrigInd](#mmsreadorigind8)\|[MmsReadRecInd](#mmsreadrecind8) | Yes  | PDU header type.|
1937| attachment  | Array<[MmsAttachment](#mmsattachment8)\>                     | No  | Attachment.     |
1938
1939## MmsSendReq<sup>8+</sup>
1940
1941Defines an MMS message sending request.
1942
1943**System API**: This is a system API.
1944
1945**System capability**: SystemCapability.Telephony.SmsMms
1946
1947|       Name      | Type                                | Mandatory| Description        |
1948| ---------------- | ------------------------------------ | ---- | ------------ |
1949| from             | [MmsAddress](#mmsaddress8)           | Yes  | MMS message source.    |
1950| transactionId    | string                               | Yes  | Transaction ID.      |
1951| contentType      | string                               | Yes  | Content type.    |
1952| version          | [MmsVersionType](#mmsversiontype8)   | Yes  | Version.        |
1953| to               | Array<[MmsAddress](#mmsaddress8)\>   | No  | Destination address.      |
1954| date             | number                               | No  | Date.        |
1955| cc               | Array<[MmsAddress](#mmsaddress8)\>   | No  | Carbon copy.        |
1956| bcc              | Array<[MmsAddress](#mmsaddress8)\>   | No  | Blind carbon copy.      |
1957| subject          | string                               | No  | Subject.        |
1958| messageClass     | number                               | No  | Message class.      |
1959| expiry           | number                               | No  | Expiration.        |
1960| priority         | [MmsPriorityType](#mmsprioritytype8) | No  | Priority.        |
1961| senderVisibility | number                               | No  | Sender visibility.|
1962| deliveryReport   | number                               | No  | Delivery report.    |
1963| readReport       | number                               | No  | Read report.    |
1964
1965## MmsSendConf<sup>8+</sup>
1966
1967Defines the MMS message sending configuration.
1968
1969**System API**: This is a system API.
1970
1971**System capability**: SystemCapability.Telephony.SmsMms
1972
1973|     Name     | Type                              | Mandatory| Description    |
1974| ------------- | ---------------------------------- | ---- | -------- |
1975| responseState | number                             | Yes  | Response status.|
1976| transactionId | string                             | Yes  | Transaction ID.  |
1977| version       | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
1978| messageId     | string                             | No  | Message ID.  |
1979
1980## MmsNotificationInd<sup>8+</sup>
1981
1982Defines an MMS notification index.
1983
1984**System API**: This is a system API.
1985
1986**System capability**: SystemCapability.Telephony.SmsMms
1987
1988|      Name      | Type                              | Mandatory| Description    |
1989| --------------- | ---------------------------------- | ---- | -------- |
1990| transactionId   | string                             | Yes  | Transaction ID.  |
1991| messageClass    | number                             | Yes  | Message class.  |
1992| messageSize     | number                             | Yes  | Message size.|
1993| expiry          | number                             | Yes  | Expiration.    |
1994| contentLocation | string                             | Yes  | Content location.|
1995| version         | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
1996| from            | [MmsAddress](#mmsaddress8)         | No  | Source address.    |
1997| subject         | string                             | No  | Subject.    |
1998| deliveryReport  | number                             | No  | Status report.|
1999| contentClass    | number                             | No  | Content class.  |
2000
2001## MmsAcknowledgeInd<sup>8+</sup>
2002
2003Defines an MMS confirmation index.
2004
2005**System API**: This is a system API.
2006
2007**System capability**: SystemCapability.Telephony.SmsMms
2008
2009|      Name    | Type                              | Mandatory| Description    |
2010| ------------- | ---------------------------------- | ---- | -------- |
2011| transactionId | string                             | Yes  | Transaction ID.  |
2012| version       | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
2013| reportAllowed | [ReportType](#reporttype8)         | No  | Report allowed.|
2014
2015## MmsRetrieveConf<sup>8+</sup>
2016
2017Defines the MMS message retrieval configuration.
2018
2019**System API**: This is a system API.
2020
2021**System capability**: SystemCapability.Telephony.SmsMms
2022
2023|      Name     | Type                                | Mandatory| Description    |
2024| -------------- | ------------------------------------ | ---- | -------- |
2025| transactionId  | string                               | Yes  | Transaction ID.  |
2026| messageId      | string                               | Yes  | Message ID.  |
2027| date           | number                               | Yes  | Date.    |
2028| contentType    | string                               | Yes  | Content type.|
2029| to             | Array<[MmsAddress](#mmsaddress8)\>   | Yes  | Destination address.  |
2030| version        | [MmsVersionType](#mmsversiontype8)   | Yes  | Version.    |
2031| from           | [MmsAddress](#mmsaddress8)           | No  | Source address.    |
2032| cc             | Array<[MmsAddress](#mmsaddress8)\>   | No  | Carbon copy.    |
2033| subject        | string                               | No  | Subject.    |
2034| priority       | [MmsPriorityType](#mmsprioritytype8) | No  | Priority.  |
2035| deliveryReport | number                               | No  | Status report.|
2036| readReport     | number                               | No  | Read report.|
2037| retrieveStatus | number                               | No  | Retrieval status.|
2038| retrieveText   | string                               | No  | Retrieval text.|
2039
2040## MmsReadOrigInd<sup>8+</sup>
2041
2042Defines the original MMS message reading index.
2043
2044**System API**: This is a system API.
2045
2046**System capability**: SystemCapability.Telephony.SmsMms
2047
2048|    Name   | Type                              | Mandatory| Description    |
2049| ---------- | ---------------------------------- | ---- | -------- |
2050| version    | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
2051| messageId  | string                             | Yes  | Message ID.  |
2052| to         | Array<[MmsAddress](#mmsaddress8)\> | Yes  | Destination address.  |
2053| from       | [MmsAddress](#mmsaddress8)         | Yes  | Source address.    |
2054| date       | number                             | Yes  | Date.    |
2055| readStatus | number                             | Yes  | Read status.|
2056
2057## MmsReadRecInd<sup>8+</sup>
2058
2059Defines the MMS message reading index.
2060
2061**System API**: This is a system API.
2062
2063**System capability**: SystemCapability.Telephony.SmsMms
2064
2065|    Name   | Type                              | Mandatory| Description    |
2066| ---------- | ---------------------------------- | ---- | -------- |
2067| version    | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
2068| messageId  | string                             | Yes  | Message ID.  |
2069| to         | Array<[MmsAddress](#mmsaddress8)\> | Yes  | Destination address.  |
2070| from       | [MmsAddress](#mmsaddress8)         | Yes  | Source address.    |
2071| readStatus | number                             | Yes  | Read status.|
2072| date       | number                             | No  | Date.    |
2073
2074## MmsAttachment<sup>8+</sup>
2075
2076Defines the attachment of an MMS message.
2077
2078**System API**: This is a system API.
2079
2080**System capability**: SystemCapability.Telephony.SmsMms
2081
2082|          Name          | Type                                | Mandatory| Description              |
2083| ----------------------- | ------------------------------------ | ---- | ------------------ |
2084| contentId               | string                               | Yes  | Content ID.            |
2085| contentLocation         | string                               | Yes  | Content location.          |
2086| contentDisposition      | [DispositionType](#dispositiontype8) | Yes  | Content disposition.          |
2087| contentTransferEncoding | string                               | Yes  | Encoding for content transfer.      |
2088| contentType             | string                               | Yes  | Content type.          |
2089| isSmil                  | boolean                              | Yes  | Whether the synchronized multimedia integration language is used.|
2090| path                    | string                               | No  | Path.              |
2091| inBuff                  | Array<number\>                       | No  | Whether the message is in the buffer.          |
2092| fileName                | string                               | No  | File name.            |
2093| charset                 | [MmsCharSets](#mmscharsets8)         | No  | Character set.            |
2094
2095## MmsAddress<sup>8+</sup>
2096
2097Defines an MMSC address.
2098
2099**System API**: This is a system API.
2100
2101**System capability**: SystemCapability.Telephony.SmsMms
2102
2103|   Name | Type                        | Mandatory| Description  |
2104| ------- | ---------------------------- | ---- | ------ |
2105| address | string                       | Yes  | Network address.  |
2106| charset | [MmsCharSets](#mmscharsets8) | Yes  | Character set.|
2107
2108## MessageType<sup>8+</sup>
2109
2110Message type.
2111
2112**System API**: This is a system API.
2113
2114**System capability**: SystemCapability.Telephony.SmsMms
2115
2116|          Name            | Value  | Description                |
2117| ------------------------- | ---- | -------------------- |
2118| TYPE_MMS_SEND_REQ         | 128  | MMS message sending request.    |
2119| TYPE_MMS_SEND_CONF        | 129  | MMS message sending configuration.    |
2120| TYPE_MMS_NOTIFICATION_IND | 130  | MMS notification index.    |
2121| TYPE_MMS_RESP_IND         | 131  | MMS message response index.    |
2122| TYPE_MMS_RETRIEVE_CONF    | 132  | MMS message retrieval configuration.    |
2123| TYPE_MMS_ACKNOWLEDGE_IND  | 133  | MMS message acknowledgement index.    |
2124| TYPE_MMS_DELIVERY_IND     | 134  | MMS message delivery index.    |
2125| TYPE_MMS_READ_REC_IND     | 135  | MMS message reading and receiving index.|
2126| TYPE_MMS_READ_ORIG_IND    | 136  | Original MMS message reading index.|
2127
2128## MmsPriorityType<sup>8+</sup>
2129
2130Enumerates MMS message priorities.
2131
2132**System API**: This is a system API.
2133
2134**System capability**: SystemCapability.Telephony.SmsMms
2135
2136|    Name   | Value  | Description          |
2137| ---------- | ---- | -------------- |
2138| MMS_LOW    | 128  | Low priority.  |
2139| MMS_NORMAL | 129  | Normal priority.|
2140| MMS_HIGH   | 130  | High priority.  |
2141
2142## MmsVersionType<sup>8+</sup>
2143
2144Enumerates MMS versions.
2145
2146**System API**: This is a system API.
2147
2148**System capability**: SystemCapability.Telephony.SmsMms
2149
2150|      Name      | Value  | Description       |
2151| --------------- | ---- | ----------- |
2152| MMS_VERSION_1_0 | 0x10 | MMS version 1_0.|
2153| MMS_VERSION_1_1 | 0x11 | MMS version 1_1.|
2154| MMS_VERSION_1_2 | 0x12 | MMS version 1_2.|
2155| MMS_VERSION_1_3 | 0x13 | MMS version 1_3.|
2156
2157## MmsCharSets<sup>8+</sup>
2158
2159Enumerates MMS character sets.
2160
2161**System API**: This is a system API.
2162
2163**System capability**: SystemCapability.Telephony.SmsMms
2164
2165|      Name      | Value    | Description               |
2166| --------------- | ------ | ------------------- |
2167| BIG5            | 0X07EA | BIG5 format.           |
2168| ISO_10646_UCS_2 | 0X03E8 | ISO_10646_UCS_2 format.|
2169| ISO_8859_1      | 0X04   | ISO_8859_1 format.     |
2170| ISO_8859_2      | 0X05   | ISO_8859_2 format.     |
2171| ISO_8859_3      | 0X06   | ISO_8859_3 format.     |
2172| ISO_8859_4      | 0X07   | ISO_8859_4 format.     |
2173| ISO_8859_5      | 0X08   | ISO_8859_5 format.     |
2174| ISO_8859_6      | 0X09   | ISO_8859_6 format.     |
2175| ISO_8859_7      | 0X0A   | ISO_8859_7 format.     |
2176| ISO_8859_8      | 0X0B   | ISO_8859_8 format.     |
2177| ISO_8859_9      | 0X0C   | ISO_8859_9 format.     |
2178| SHIFT_JIS       | 0X11   | SHIFT_JIS format.      |
2179| US_ASCII        | 0X03   | US_ASCII format.       |
2180| UTF_8           | 0X6A   | UTF_8 format.          |
2181
2182## DispositionType<sup>8+</sup>
2183
2184Enumerates disposition types.
2185
2186**System API**: This is a system API.
2187
2188**System capability**: SystemCapability.Telephony.SmsMms
2189
2190|    Name   | Value  | Description    |
2191| ---------- | ---- | -------- |
2192| FROM_DATA  | 0    | Data source.|
2193| ATTACHMENT | 1    | Attachment.    |
2194| INLINE     | 2    | Inlining.    |
2195
2196## ReportType<sup>8+</sup>
2197
2198Enumerates report types.
2199
2200**System API**: This is a system API.
2201
2202**System capability**: SystemCapability.Telephony.SmsMms
2203
2204|  Name  | Value  | Description|
2205| ------- | ---- | ---- |
2206| MMS_YES | 128  | YES  |
2207| MMS_NO  | 129  | NO   |
2208
2209## CBConfigOptions<sup>7+</sup>
2210
2211Defines the cell broadcast configuration options.
2212
2213**System API**: This is a system API.
2214
2215**System capability**: SystemCapability.Telephony.SmsMms
2216
2217|      Name     | Type                | Mandatory| Description        |
2218| -------------- | -------------------- | ---- | ------------ |
2219| slotId         | number               | Yes  | Card slot ID.      |
2220| enable         | boolean              | Yes  | Whether to enable cell broadcast.        |
2221| startMessageId | number               | Yes  | Start message ID.  |
2222| endMessageId   | number               | Yes  | End message ID.  |
2223| ranType        | [RanType](#rantype7) | Yes  | RAN type.|
2224
2225## SimMessageStatus<sup>7+</sup>
2226
2227Defines the SIM message status.
2228
2229**System API**: This is a system API.
2230
2231**System capability**: SystemCapability.Telephony.SmsMms
2232
2233|           Name           | Value  | Description                       |
2234| ------------------------- | ---- | --------------------------- |
2235| SIM_MESSAGE_STATUS_FREE   | 0    | Free space state of the SIM card.      |
2236| SIM_MESSAGE_STATUS_READ   | 1    | Read state.               |
2237| SIM_MESSAGE_STATUS_UNREAD | 3    | Unread state.               |
2238| SIM_MESSAGE_STATUS_SENT   | 5    | Storage of sent messages (applicable only to SMS).|
2239| SIM_MESSAGE_STATUS_UNSENT | 7    | Storage of unsent messages (applicable only to SMS).|
2240
2241## RanType<sup>7+</sup>
2242
2243RAN type.
2244
2245**System API**: This is a system API.
2246
2247**System capability**: SystemCapability.Telephony.SmsMms
2248
2249|   Name   | Value  | Description|
2250| --------- | ---- | ---- |
2251| TYPE_GSM  | 1    | GSM  |
2252| TYPE_CDMA | 2    | CMDA |
2253
2254## SmsEncodingScheme<sup>8+</sup>
2255
2256Enumerates SMS encoding schemes.
2257
2258**System API**: This is a system API.
2259
2260**System capability**: SystemCapability.Telephony.SmsMms
2261
2262|         Name        | Value  | Description        |
2263| -------------------- | ---- | ------------ |
2264| SMS_ENCODING_UNKNOWN | 0    | Unknown code.|
2265| SMS_ENCODING_7BIT    | 1    | 7-digit code. |
2266| SMS_ENCODING_8BIT    | 2    | 8-digit code. |
2267| SMS_ENCODING_16BIT   | 3    | 16-digit code.|
2268
2269## SimMessageOptions<sup>7+</sup>
2270
2271Defines the SIM message options.
2272
2273**System API**: This is a system API.
2274
2275**System capability**: SystemCapability.Telephony.SmsMms
2276
2277|  Name | Type                                  | Mandatory| Description          |
2278| ------ | -------------------------------------- | ---- | -------------- |
2279| slotId | number                                 | Yes  | Card slot ID.        |
2280| smsc   | string                                 | Yes  | Short message service center.|
2281| pdu    | string                                 | Yes  | Protocol data unit.  |
2282| status | [SimMessageStatus](#simmessagestatus7) | Yes  | Status.          |
2283
2284## UpdateSimMessageOptions<sup>7+</sup>
2285
2286Defines the updating SIM message options.
2287
2288**System API**: This is a system API.
2289
2290**System capability**: SystemCapability.Telephony.SmsMms
2291
2292|   Name   | Type                                  | Mandatory| Description          |
2293| --------- | -------------------------------------- | ---- | -------------- |
2294| slotId    | number                                 | Yes  | Card slot ID.        |
2295| msgIndex  | number                                 | Yes  | Message index.      |
2296| newStatus | [SimMessageStatus](#simmessagestatus7) | Yes  | New status.        |
2297| pdu       | string                                 | Yes  | Protocol data unit.  |
2298| smsc      | string                                 | Yes  | Short message service center.|
2299
2300## SimShortMessage<sup>7+</sup>
2301
2302Defines a SIM message.
2303
2304**System API**: This is a system API.
2305
2306**System capability**: SystemCapability.Telephony.SmsMms
2307
2308|       Name      | Type                                  | Mandatory| Description         |
2309| ---------------- | -------------------------------------- | ---- | ------------- |
2310| shortMessage     | [ShortMessage](js-apis-sms.md#shortmessage)          | Yes  | SMS message.       |
2311| simMessageStatus | [SimMessageStatus](#simmessagestatus7) | Yes  | SIM message status.|
2312| indexOnSim       | number                                 | Yes  | SIM card index.    |
2313
2314## MmsDeliveryInd<sup>8+</sup>
2315
2316Defines an MMS message delivery index.
2317
2318**System API**: This is a system API.
2319
2320**System capability**: SystemCapability.Telephony.SmsMms
2321
2322|    Name  | Type                              | Mandatory| Description  |
2323| --------- | ---------------------------------- | ---- | ------ |
2324| messageId | string                             | Yes  | Message ID.|
2325| date      | number                             | Yes  | Date.  |
2326| to        | Array<[MmsAddress](#mmsaddress8)\> | Yes  | Destination address.|
2327| status    | number                             | Yes  | Status.  |
2328| version   | [MmsVersionType](#mmsversiontype8) | Yes  | Version.  |
2329
2330## MmsRespInd<sup>8+</sup>
2331
2332Defines an MMS response index.
2333
2334**System API**: This is a system API.
2335
2336**System capability**: SystemCapability.Telephony.SmsMms
2337
2338|     Name     | Type                              | Mandatory| Description    |
2339| ------------- | ---------------------------------- | ---- | -------- |
2340| transactionId | string                             | Yes  | Event ID.  |
2341| status        | number                             | Yes  | Status.    |
2342| version       | [MmsVersionType](#mmsversiontype8) | Yes  | Version.    |
2343| reportAllowed | [ReportType](#reporttype8)         | No  | Report allowed.|
2344
2345## SmsSegmentsInfo<sup>8+</sup>
2346
2347Defines the SMS message segment information.
2348
2349**System API**: This is a system API.
2350
2351**System capability**: SystemCapability.Telephony.SmsMms
2352
2353|        Name         | Type                                    | Mandatory| Description        |
2354| -------------------- | ---------------------------------------- | ---- | ------------ |
2355| splitCount           | number                                   | Yes  | Split count.    |
2356| encodeCount          | number                                   | Yes  | Encoding count.    |
2357| encodeCountRemaining | number                                   | Yes  | Remaining encoding count.|
2358| scheme               | [SmsEncodingScheme](#smsencodingscheme8) | Yes  | Encoding scheme.|
2359