1# @ohos.telephony.sms (短信服务)(系统接口) 2 3短信服务提供了管理短信的一些基础能力,包括发送、下载彩信,设置发送短信的默认SIM卡槽ID,获取、设置短信服务中心(SMSC)地址等。 4 5>**说明:** 6> 7>本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> 9>当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.telephony.sms (短信服务)](js-apis-sms.md) 10 11 12## 导入模块 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<void>\): void 22 23发送彩信。使用callback异步回调。 24 25**系统接口:** 此接口为系统接口。 26 27**需要权限**:ohos.permission.SEND_MESSAGES 28 29**系统能力**:SystemCapability.Telephony.SmsMms 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| -------- | --------------------------- | ---- | ---------------------------------------- | 35| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 | 36| mmsParams | [MmsParams](#mmsparams11) | 是 | 发送彩信的参数和回调,参考[MmsParams](#mmsparams11)。 | 37| callback | AsyncCallback<void> | 是 | 发送彩信的回调函数。 | 38 39**错误码:** 40 41以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 42 43| 错误码ID | 错误信息 | 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**示例:** 54 55FA模型示例: 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// 获取context 63let context: common.BaseContext = featureAbility.getContext(); 64 65// 彩信pdu存储路径,pdu来源于编码接口 66const sandBoxPath: string = '/data/storage/el2/base/files/'; 67let filePath: string = sandBoxPath + 'SendReq.mms'; 68 69// 发送彩信参数(mmsc以联通卡为例) 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// 调用发送接口 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模型示例: 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// 彩信pdu存储路径,pdu来源于编码接口 99const sandBoxPath = '/data/storage/el2/base/files/'; 100let filePath = sandBoxPath + 'SendReq.mms'; 101 102// 彩信用户代理、用户代理描述配置。根据运营商要求配置,默认ua,uaprof 103let mmsConf: sms.MmsConfig = { 104 userAgent:'ua', 105 userAgentProfile: 'uaprof' 106}; 107 108// 发送彩信参数(mmsc以联通卡为例) 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<void> 132 133发送彩信。使用Promise异步回调。 134 135**系统接口:** 此接口为系统接口。 136 137**需要权限**:ohos.permission.SEND_MESSAGES 138 139**系统能力**:SystemCapability.Telephony.SmsMms 140 141**参数:** 142 143| 参数名 | 类型 | 必填 | 说明 | 144| -------- | --------------------------- | ---- | ---------------------------------------- | 145| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 | 146| mmsParams | [MmsParams](#mmsparams11) | 是 | 发送彩信的参数和回调,参考[MmsParams](#mmsparams11)。 | 147 148**返回值:** 149 150| 类型 | 说明 | 151| --------------- | ------------------------------------------------------------ | 152| Promise<void> | 以Promise形式返回发送彩信的结果。 | 153 154**错误码:** 155 156以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 157 158| 错误码ID | 错误信息 | 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**示例:** 169 170FA模型示例: 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// 获取context 178let context: common.BaseContext = featureAbility.getContext(); 179 180// 彩信pdu存储路径,pdu来源于编码接口 181const sandBoxPath: string = '/data/storage/el2/base/files/'; 182let filePath: string = sandBoxPath + 'SendReq.mms'; 183 184// 发送彩信参数(mmsc以联通卡为例) 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// 调用发送接口 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模型示例: 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// 彩信pdu存储路径,pdu来源于编码接口 213const sandBoxPath = '/data/storage/el2/base/files/'; 214let filePath = sandBoxPath + 'SendReq.mms'; 215 216// 彩信用户代理、用户代理描述配置。根据运营商要求配置,默认ua,uaprof 217let mmsConf: sms.MmsConfig = { 218 userAgent:'ua', 219 userAgentProfile: 'uaprof' 220}; 221 222// 发送彩信参数(mmsc以联通卡为例) 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<void>\): void 245 246下载彩信。使用callback异步回调。 247 248**系统接口:** 此接口为系统接口。 249 250**需要权限**:ohos.permission.RECEIVE_MMS 251 252**系统能力**:SystemCapability.Telephony.SmsMms 253 254**参数:** 255 256| 参数名 | 类型 | 必填 | 说明 | 257| -------- | --------------------------- | ---- | ---------------------------------------- | 258| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 | 259| mmsParams | [MmsParams](#mmsparams11) | 是 | 下载彩信的参数和回调,参考[MmsParams](#mmsparams11)。 | 260| callback | AsyncCallback<void> | 是 | 下载彩信的回调函数。 | 261 262**错误码:** 263 264以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 265 266| 错误码ID | 错误信息 | 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**示例:** 277 278FA模型示例: 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// 获取context 286let context: common.BaseContext = featureAbility.getContext(); 287 288// 彩信pdu存储路径 289const sandBoxPath: string = '/data/storage/el2/base/files/'; 290let filePath: string = sandBoxPath + 'RetrieveConf.mms'; 291 292// 从WapPush中解析出彩信URL 293let wapPushUrl: string = 'URL'; 294 295// 下载彩信参数 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// 调用下载接口 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模型示例: 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// 彩信pdu存储路径 325const sandBoxPath = '/data/storage/el2/base/files/'; 326let filePath = sandBoxPath + 'RetrieveConf.mms'; 327 328// 从WapPush中解析出彩信URL 329let wapPushUrl = 'URL'; 330 331// 彩信用户代理、用户代理描述配置。根据运营商要求配置,默认ua,uaprof 332let mmsConf: sms.MmsConfig = { 333 userAgent:'ua', 334 userAgentProfile: 'uaprof' 335}; 336 337// 下载彩信参数 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<void> 361 362发送彩信。使用Promise异步回调。 363 364**系统接口:** 此接口为系统接口。 365 366**需要权限**:ohos.permission.RECEIVE_MMS 367 368**系统能力**:SystemCapability.Telephony.SmsMms 369 370**参数:** 371 372| 参数名 | 类型 | 必填 | 说明 | 373| -------- | --------------------------- | ---- | ---------------------------------------- | 374| context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-app-context.md)。<br>Stage模型的应用Context定义见[Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md)。 | 375| mmsParams | [MmsParams](#mmsparams11) | 是 | 发送彩信的参数和回调,参考[MmsParams](#mmsparams11)。 | 376 377**返回值:** 378 379| 类型 | 说明 | 380| --------------- | ------------------------------------------------------------ | 381| Promise<void> | 以Promise形式返回发送彩信的结果。 | 382 383**错误码:** 384 385以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 386 387| 错误码ID | 错误信息 | 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**示例:** 398 399FA模型示例: 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// 获取context 407let context: common.BaseContext = featureAbility.getContext(); 408 409// 彩信pdu存储路径 410const sandBoxPath: string = '/data/storage/el2/base/files/'; 411let filePath: string = sandBoxPath + 'RetrieveConf.mms'; 412 413// 从WapPush中解析出彩信URL 414let wapPushUrl: string = 'URL'; 415 416// 下载彩信参数 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// 调用发送接口 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模型示例: 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// 彩信pdu存储路径 445const sandBoxPath = '/data/storage/el2/base/files/'; 446let filePath = sandBoxPath + 'RetrieveConf.mms'; 447 448// 从WapPush中解析出彩信URL 449let wapPushUrl = 'URL'; 450 451// 彩信用户代理、用户代理描述配置。根据运营商要求配置,默认ua,uaprof 452let mmsConf: sms.MmsConfig = { 453 userAgent:'ua', 454 userAgentProfile: 'uaprof' 455}; 456 457// 下载彩信参数 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<void>\): void 481 482设置发送短信的默认SIM卡槽ID。使用callback异步回调。 483 484**系统接口:** 此接口为系统接口。 485 486**需要权限**:ohos.permission.SET_TELEPHONY_STATE 487 488**系统能力**:SystemCapability.Telephony.SmsMms 489 490**参数:** 491 492| 参数名 | 类型 | 必填 | 说明 | 493| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 494| slotId | number | 是 | SIM卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2<br/>- -1:清除默认配置 | 495| callback | AsyncCallback<void> | 是 | 设置发送短信的默认SIM卡槽ID的回调函数。 | 496 497**错误码:** 498 499以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 500 501| 错误码ID | 错误信息 | 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**示例:** 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<void> 527 528设置发送短信的默认SIM卡槽ID。使用Promise异步回调。 529 530**系统接口:** 此接口为系统接口。 531 532**需要权限**:ohos.permission.SET_TELEPHONY_STATE 533 534**系统能力**:SystemCapability.Telephony.SmsMms 535 536**参数:** 537 538| 参数名 | 类型 | 必填 | 说明 | 539| ------ | ------ | ---- | ------------------------------------------------------------ | 540| slotId | number | 是 | SIM卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2<br/>- -1:清除默认配置 | 541 542**返回值:** 543 544| 类型 | 说明 | 545| --------------- | ------------------------------- | 546| Promise\<void\> | 以Promise形式异步返回设置结果。 | 547 548**错误码:** 549 550以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 551 552| 错误码ID | 错误信息 | 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**示例:** 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 580设置短信服务中心(SMSC)地址。使用callback异步回调。 581 582**系统接口:** 此接口为系统接口。 583 584**需要权限**:ohos.permission.SET_TELEPHONY_STATE,该权限为系统权限 585 586**系统能力**:SystemCapability.Telephony.SmsMms 587 588**参数:** 589 590| 参数名 | 类型 | 必填 | 说明 | 591| -------- | ------------------------- | ---- | ----------------------------------------- | 592| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 593| smscAddr | string | 是 | 短信服务中心地址。 | 594| callback | AsyncCallback<void> | 是 | 设置短信服务中心(SMSC)地址的回调函数。 | 595 596**错误码:** 597 598以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 599 600| 错误码ID | 错误信息 | 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**示例:** 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 628设置短信服务中心(SMSC)地址。使用Promise异步回调。 629 630**系统接口:** 此接口为系统接口。 631 632**需要权限**:ohos.permission.SET_TELEPHONY_STATE,该权限为系统权限 633 634**系统能力**:SystemCapability.Telephony.SmsMms 635 636**参数:** 637 638| 参数名 | 类型 | 必填 | 说明 | 639| -------- | ------ | ---- | ----------------------------------------- | 640| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 641| smscAddr | string | 是 | 短信服务中心地址。 | 642 643**返回值:** 644 645| 类型 | 说明 | 646| ------------------- | ------------------------------- | 647| Promise<void> | 以Promise形式异步返回设置结果。 | 648 649**错误码:** 650 651以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 652 653| 错误码ID | 错误信息 | 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**示例:** 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 683获取短信服务中心(SMSC)地址。使用callback异步回调。 684 685**系统接口:** 此接口为系统接口。 686 687**需要权限**:ohos.permission.GET_TELEPHONY_STATE,该权限为系统权限 688 689**系统能力**:SystemCapability.Telephony.SmsMms 690 691**参数:** 692 693| 参数名 | 类型 | 必填 | 说明 | 694| -------- | --------------------------- | ---- | ----------------------------------------- | 695| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 696| callback | AsyncCallback<string> | 是 | 指示用于获取SMSC地址的回调函数。 | 697 698**错误码:** 699 700以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 701 702| 错误码ID | 错误信息 | 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**示例:** 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 729获取短信服务中心(SMSC)地址。使用Promise异步回调。 730 731**系统接口:** 此接口为系统接口。 732 733**需要权限**:ohos.permission.GET_TELEPHONY_STATE,该权限为系统权限 734 735**系统能力**:SystemCapability.Telephony.SmsMms 736 737**参数:** 738 739| 参数名 | 类型 | 必填 | 说明 | 740| ------ | ------ | ---- | ----------------------------------------- | 741| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 742 743**返回值:** 744 745| 类型 | 说明 | 746| --------------------- | --------------------------------------------- | 747| Promise<string> | 以Promise形式返回获取短信服务中心地址的结果。 | 748 749**错误码:** 750 751以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 752 753| 错误码ID | 错误信息 | 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**示例:** 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 782将长短信拆分为多个片段。使用callback异步回调。 783 784**系统接口:** 此接口为系统接口。 785 786**需要权限**:ohos.permission.SEND_MESSAGES 787 788**系统能力**:SystemCapability.Telephony.SmsMms 789 790**参数:** 791 792| 参数名 | 类型 | 必填 | 说明 | 793| -------- | ----------------------------- | ---- | ----------------------------- | 794| content | string | 是 | 指示短消息内容,不能为null。 | 795| callback | AsyncCallback<Array<string\>> | 是 | 返回可合并为完整SMS的拆分段列表的回调函数。| 796 797**错误码:** 798 799以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 800 801| 错误码ID | 错误信息 | 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**示例:** 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 828将长短信拆分为多个片段。使用Promise异步回调。 829 830**系统接口:** 此接口为系统接口。 831 832**需要权限**:ohos.permission.SEND_MESSAGES 833 834**系统能力**:SystemCapability.Telephony.SmsMms 835 836**参数:** 837 838| 参数名 | 类型 | 必填 | 说明 | 839| ------- | ------ | ---- | ---------------------------- | 840| content | string | 是 | 指示短消息内容,不能为null。 | 841 842**返回值:** 843 844| 类型 | 说明 | 845| ----------------------- | ----------------------------------- | 846| Promise<Array<string\>> | 以Promise形式返回多个片段的的结果。 | 847 848**错误码:** 849 850以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 851 852| 错误码ID | 错误信息 | 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**示例:** 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 881添加SIM卡消息,sim卡消息满,添加报错。使用callback异步回调。 882 883**系统接口:** 此接口为系统接口。 884 885**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 886 887**系统能力**:SystemCapability.Telephony.SmsMms 888 889**参数:** 890 891| 参数名 | 类型 | 必填 | 说明 | 892| -------- | ---------------------------------------- | ---- | --------------- | 893| options | [SimMessageOptions](#simmessageoptions7) | 是 | SIM卡消息选项。 | 894| callback | AsyncCallback<void> | 是 | 添加SIM卡消息的回调函数。 | 895 896**错误码:** 897 898以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 899 900| 错误码ID | 错误信息 | 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**示例:** 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 932添加SIM卡消息,sim卡消息满,添加报错。使用Promise异步回调。 933 934**系统接口:** 此接口为系统接口。 935 936**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 937 938**系统能力**:SystemCapability.Telephony.SmsMms 939 940**参数:** 941 942| 参数名 | 类型 | 必填 | 说明 | 943| ------- | ---------------------------------------- | ---- | --------------- | 944| options | [SimMessageOptions](#simmessageoptions7) | 是 | SIM卡消息选项。 | 945 946**返回值:** 947 948| 类型 | 说明 | 949| ------------------- | ----------------------------- | 950| Promise<void> | 以Promise形式返回添加的结果。 | 951 952**错误码:** 953 954以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 955 956| 错误码ID | 错误信息 | 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**示例:** 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 989删除SIM卡消息,msgIndex无效时,删除报错。使用callback异步回调。 990 991**系统接口:** 此接口为系统接口。 992 993**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 994 995**系统能力**:SystemCapability.Telephony.SmsMms 996 997**参数:** 998 999| 参数名 | 类型 | 必填 | 说明 | 1000| -------- | ------------------------- | ---- | ----------------------------------------- | 1001| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1002| msgIndex | number | 是 | 消息索引。 | 1003| callback | AsyncCallback<void> | 是 | 删除SIM卡消息的回调函数。 | 1004 1005**错误码:** 1006 1007以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1008 1009| 错误码ID | 错误信息 | 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**示例:** 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 1037删除SIM卡消息,msgIndex无效时,删除报错。使用Promise异步回调。 1038 1039**系统接口:** 此接口为系统接口。 1040 1041**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 1042 1043**系统能力**:SystemCapability.Telephony.SmsMms 1044 1045**参数:** 1046 1047| 参数名 | 类型 | 必填 | 说明 | 1048| -------- | ------ | ---- | ----------------------------------------- | 1049| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1050| msgIndex | number | 是 | 消息索引。 | 1051 1052**返回值:** 1053 1054| 类型 | 说明 | 1055| ------------------- | ----------------------------- | 1056| Promise<void> | 以Promise形式返回删除的结果。 | 1057 1058**错误码:** 1059 1060以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1061 1062| 错误码ID | 错误信息 | 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**示例:** 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 1092更新SIM卡消息。使用callback异步回调。 1093 1094**系统接口:** 此接口为系统接口。 1095 1096**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 1097 1098**系统能力**:SystemCapability.Telephony.SmsMms 1099 1100**参数:** 1101 1102| 参数名 | 类型 | 必填 | 说明 | 1103| -------- | ---------------------------------------------------- | ---- | ------------------- | 1104| options | [UpdateSimMessageOptions](#updatesimmessageoptions7) | 是 | 更新SIM卡消息选项。 | 1105| callback | AsyncCallback<void> | 是 | 更新SIM卡消息的回调函数。 | 1106 1107**错误码:** 1108 1109以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1110 1111| 错误码ID | 错误信息 | 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**示例:** 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 1144更新SIM卡消息。使用Promise异步回调。 1145 1146**系统接口:** 此接口为系统接口。 1147 1148**需要权限**:ohos.permission.RECEIVE_SMS,ohos.permission.SEND_MESSAGES 1149 1150**系统能力**:SystemCapability.Telephony.SmsMms 1151 1152**参数:** 1153 1154| 参数名 | 类型 | 必填 | 说明 | 1155| ------- | ---------------------------------------------------- | ---- | ------------------- | 1156| options | [UpdateSimMessageOptions](#updatesimmessageoptions7) | 是 | 更新SIM卡消息选项。 | 1157 1158**返回值:** 1159 1160| 类型 | 说明 | 1161| ------------------- | ----------------------------- | 1162| Promise<void> | 以Promise形式返回更新的结果。 | 1163 1164**错误码:** 1165 1166以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1167 1168| 错误码ID | 错误信息 | 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**示例:** 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 1203获取所有SIM卡消息。使用callback异步回调。 1204 1205**系统接口:** 此接口为系统接口。 1206 1207**需要权限**:ohos.permission.RECEIVE_SMS 1208 1209**系统能力**:SystemCapability.Telephony.SmsMms 1210 1211**参数:** 1212 1213| 参数名 | 类型 | 必填 | 说明 | 1214| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------- | 1215| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1216| callback | AsyncCallback<Array<[SimShortMessage](#simshortmessage7)\>> | 是 | 获取所有SIM卡消息的回调函数。 | 1217 1218**错误码:** 1219 1220以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1221 1222| 错误码ID | 错误信息 | 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**示例:** 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 1249获取所有SIM卡消息。使用Promise异步回调。 1250 1251**系统接口:** 此接口为系统接口。 1252 1253**需要权限**:ohos.permission.RECEIVE_SMS 1254 1255**系统能力**:SystemCapability.Telephony.SmsMms 1256 1257**参数:** 1258 1259| 参数名 | 类型 | 必填 | 说明 | 1260| ------ | ------ | ---- | ----------------------------------------- | 1261| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1262 1263**返回值:** 1264 1265| 类型 | 说明 | 1266| ------------------------------------------------------- | ---------------------------------- | 1267| Promise<Array<[SimShortMessage](#simshortmessage7)\>> | 以Promise形式返回获取的SIM短消息。 | 1268 1269**错误码:** 1270 1271以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1272 1273| 错误码ID | 错误信息 | 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**示例:** 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 1302设置小区广播配置。使用callback异步回调。 1303 1304**系统接口:** 此接口为系统接口。 1305 1306**需要权限**:ohos.permission.RECEIVE_SMS 1307 1308**系统能力**:SystemCapability.Telephony.SmsMms 1309 1310**参数:** 1311 1312| 参数名 | 类型 | 必填 | 说明 | 1313| -------- | ------------------------------------ | ---- | ------------ | 1314| options | [CBConfigOptions](#cbconfigoptions7) | 是 | 小区广播配置选项。 | 1315| callback | AsyncCallback<void> | 是 | 设置小区广播配置的回调函数。 | 1316 1317**错误码:** 1318 1319以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1320 1321| 错误码ID | 错误信息 | 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**示例:** 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 1354设置小区广播配置。使用Promise异步回调。 1355 1356**系统接口:** 此接口为系统接口。 1357 1358**需要权限**:ohos.permission.RECEIVE_SMS 1359 1360**系统能力**:SystemCapability.Telephony.SmsMms 1361 1362**参数:** 1363 1364| 参数名 | 类型 | 必填 | 说明 | 1365| ------- | ------------------------------------ | ---- | ------------ | 1366| options | [CBConfigOptions](#cbconfigoptions7) | 是 | 小区广播配置选项。 | 1367 1368**返回值:** 1369 1370| 类型 | 说明 | 1371| ------------------- | ----------------------------- | 1372| Promise<void> | 以Promise形式返回设置的结果。 | 1373 1374**错误码:** 1375 1376以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1377 1378| 错误码ID | 错误信息 | 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**示例:** 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 1413获取短信段信息。使用callback异步回调。 1414 1415**系统接口:** 此接口为系统接口。 1416 1417**系统能力**:SystemCapability.Telephony.SmsMms 1418 1419**参数:** 1420 1421| 参数名 | 类型 | 必填 | 说明 | 1422| --------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | 1423| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1424| message | string | 是 | 消息。 | 1425| force7bit | boolean | 是 | 是否使用7 bit编码。 | 1426| callback | AsyncCallback<[SmsSegmentsInfo](#smssegmentsinfo8)> | 是 | 指示用于获取短信短信息的回调函数。 | 1427 1428**错误码:** 1429 1430以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1431 1432| 错误码ID | 错误信息 | 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**示例:** 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 1458获取短信段信息。使用Promise异步回调。 1459 1460**系统接口:** 此接口为系统接口。 1461 1462**系统能力**:SystemCapability.Telephony.SmsMms 1463 1464**参数:** 1465 1466| 参数名 | 类型 | 必填 | 说明 | 1467| --------- | ------- | ---- | ----------------------------------------- | 1468| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1469| message | string | 是 | 消息。 | 1470| force7bit | boolean | 是 | 是否使用7 bit编码。 | 1471 1472**返回值:** 1473 1474| 类型 | 说明 | 1475| ------------------------------------------------------- | ----------------------------- | 1476| Promise<[SmsSegmentsInfo](#smssegmentsinfo8)> | 以Promise形式返回短信段信息。 | 1477 1478**错误码:** 1479 1480以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1481 1482| 错误码ID | 错误信息 | 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**示例:** 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 1510如果IMS已注册并且在IMS上支持SMS,则支持通过IMS发送SMS。使用callback异步回调。 1511 1512**系统接口:** 此接口为系统接口。 1513 1514**系统能力**:SystemCapability.Telephony.SmsMms 1515 1516**参数:** 1517 1518| 参数名 | 类型 | 必填 | 说明 | 1519| -------- | ---------------------------- | ---- | ---------- | 1520| slotId | number | 是 | SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1521| callback | AsyncCallback<boolean> | 是 | 指示是否支持IMS发送SMS的回调函数。 | 1522 1523**错误码:** 1524 1525以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1526 1527| 错误码ID | 错误信息 | 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**示例:** 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 1553如果IMS已注册并且在IMS上支持SMS,则支持通过IMS发送SMS。使用Promise异步回调。 1554 1555**系统接口:** 此接口为系统接口。 1556 1557**系统能力**:SystemCapability.Telephony.SmsMms 1558 1559**参数:** 1560 1561| 参数名 | 类型 | 必填 | 说明 | 1562| ------ | ------ | ---- | -------------------------------------- | 1563| slotId | number | 是 | 卡槽ID。<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1564 1565**返回值:** 1566 1567| 类型 | 说明 | 1568| ---------------------- | ----------------------- | 1569| Promise<boolean> | 以Promise形式返回结果。 | 1570 1571**错误码:** 1572 1573以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1574 1575| 错误码ID | 错误信息 | 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**示例:** 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 1603获取IMS上支持的SMS格式。使用callback异步回调。 1604 1605**系统接口:** 此接口为系统接口。 1606 1607**系统能力**:SystemCapability.Telephony.SmsMms 1608 1609**参数:** 1610 1611| 参数名 | 类型 | 必填 | 说明 | 1612| -------- | --------------------------- | ---- | ---------- | 1613| callback | AsyncCallback<string> | 是 | 指示用于获取格式、3gpp、3gpp2或未知的回调函数。 | 1614 1615**错误码:** 1616 1617以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1618 1619| 错误码ID | 错误信息 | 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**示例:** 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 1644获取IMS上支持的SMS格式。使用Promise异步回调。 1645 1646**系统接口:** 此接口为系统接口。 1647 1648**系统能力**:SystemCapability.Telephony.SmsMms 1649 1650**返回值:** 1651 1652| 类型 | 说明 | 1653| --------------------- | -------------------------- | 1654| Promise<string> | 以Promise形式返回SMS格式。 | 1655 1656**错误码:** 1657 1658以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1659 1660| 错误码ID | 错误信息 | 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**示例:** 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 1684彩信解码。使用callback异步回调。 1685 1686**系统接口:** 此接口为系统接口。 1687 1688**系统能力**:SystemCapability.Telephony.SmsMms 1689 1690**参数:** 1691 1692| 参数名 | 类型 | 必填 | 说明 | 1693| --------------- | ------------------------------------------------------- | ---- | -------------- | 1694| mmsFilePathName | string \|Array<number\> | 是 | 彩信文件路径。 | 1695| callback | AsyncCallback<[MmsInformation](#mmsinformation8)> | 是 | 获取{@code MmsInformation}的回调函数。 | 1696 1697**错误码:** 1698 1699以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1700 1701| 错误码ID | 错误信息 | 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**示例:** 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 1732彩信解码。使用Promise异步回调。 1733 1734**系统接口:** 此接口为系统接口。 1735 1736**系统能力**:SystemCapability.Telephony.SmsMms 1737 1738**参数:** 1739 1740| 参数名 | 类型 | 必填 | 说明 | 1741| --------------- | ----------------------- | ---- | -------------- | 1742| mmsFilePathName | string \|Array<number\> | 是 | 彩信文件路径。 | 1743 1744**返回值:** 1745 1746| 类型 | 说明 | 1747| --------------------------------------------------------- | --------------------------- | 1748| Promise<<[MmsInformation](#mmsinformation8)>> | 以Promise形式返回彩信信息。 | 1749 1750**错误码:** 1751 1752以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1753 1754| 错误码ID | 错误信息 | 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**示例:** 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 1790彩信编码。使用callback异步回调。 1791 1792**系统接口:** 此接口为系统接口。 1793 1794**系统能力**:SystemCapability.Telephony.SmsMms 1795 1796**参数:** 1797 1798| 参数名 | 类型 | 必填 | 说明 | 1799| -------- | ----------------------------------- | ---- | ---------- | 1800| mms | [MmsInformation](#mmsinformation8) | 是 | 彩信信息。 | 1801| callback | AsyncCallback<Array<number\>> | 是 | 指示用于获取MMS编码结果的回调函数。 | 1802 1803**错误码:** 1804 1805以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1806 1807| 错误码ID | 错误信息 | 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**示例:** 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 1841彩信编码。使用Promise异步回调。 1842 1843**系统接口:** 此接口为系统接口。 1844 1845**系统能力**:SystemCapability.Telephony.SmsMms 1846 1847**参数:** 1848 1849| 参数名 | 类型 | 必填 | 说明 | 1850| ------ | ---------------------------------- | ---- | ---------- | 1851| mms | [MmsInformation](#mmsinformation8) | 是 | 彩信信息。 | 1852 1853**返回值:** 1854 1855| 类型 | 说明 | 1856| ----------------------------- | ----------------------------------- | 1857| Promise<Array<number\>> | 以Promise形式返回彩信编码后的结果。 | 1858 1859**错误码:** 1860 1861以下错误码的详细介绍请参见[ohos.telephony(电话子系统)错误码](errorcode-telephony.md)。 1862 1863| 错误码ID | 错误信息 | 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**示例:** 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 1897发送彩信的参数。 1898 1899**系统接口:** 此接口为系统接口。 1900 1901**系统能力**:SystemCapability.Telephony.SmsMms 1902 1903| 名称 | 类型 | 必填 | 说明 | 1904| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1905| slotId<sup>11+</sup> | number | 是 | 用于发送短信的SIM卡槽ID:<br/>- 0:卡槽1<br/>- 1:卡槽2 | 1906| mmsc<sup>11+</sup> | string | 是 | 彩信中心地址。 | 1907| data<sup>11+</sup> | string | 是 | 彩信PDU地址。 | 1908| mmsConfig<sup>11+</sup> | MmsConfig | 否 | 彩信配置文件,参考[MmsConfig](#mmsconfig11)。 | 1909 1910## MmsConfig<sup>11+</sup> 1911 1912彩信配置文件。 1913 1914**系统接口:** 此接口为系统接口。 1915 1916**系统能力**:SystemCapability.Telephony.SmsMms 1917 1918| 名称 | 类型 | 必填 | 说明 | 1919| ---------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1920| userAgent<sup>11+</sup> | string | 是 | 用户代理。 | 1921| userAgentProfile<sup>11+</sup> | string | 是 | 用户代理配置。 | 1922 1923 1924 1925## MmsInformation<sup>8+</sup> 1926 1927彩信信息。 1928 1929**系统接口:** 此接口为系统接口。 1930 1931**系统能力**:SystemCapability.Telephony.SmsMms 1932 1933| 名称 | 类型 | 必填 | 说明 | 1934| ----------- | ------------------------------------------------------------ | ---- | ---------- | 1935| messageType | [MessageType](#messagetype8) | 是 | 消息类型。 | 1936| mmsType | [MmsSendReq](#mmssendreq8) \|[MmsSendConf](#mmssendconf8) \|[MmsNotificationInd](#mmsnotificationind8) \|[MmsRespInd](#mmsrespind8) \|[MmsRetrieveConf](#mmsretrieveconf8)\|[MmsAcknowledgeInd](#mmsacknowledgeind8)\|[MmsDeliveryInd](#mmsdeliveryind8)\|[MmsReadOrigInd](#mmsreadorigind8)\|[MmsReadRecInd](#mmsreadrecind8) | 是 | PDU头类型 | 1937| attachment | Array<[MmsAttachment](#mmsattachment8)\> | 否 | 附件 | 1938 1939## MmsSendReq<sup>8+</sup> 1940 1941彩信发送请求。 1942 1943**系统接口:** 此接口为系统接口。 1944 1945**系统能力**:SystemCapability.Telephony.SmsMms 1946 1947| 名称 | 类型 | 必填 | 说明 | 1948| ---------------- | ------------------------------------ | ---- | ------------ | 1949| from | [MmsAddress](#mmsaddress8) | 是 | 彩信来源 | 1950| transactionId | string | 是 | 事务ID | 1951| contentType | string | 是 | 内容类型 | 1952| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 1953| to | Array<[MmsAddress](#mmsaddress8)\> | 否 | 发送至 | 1954| date | number | 否 | 日期 | 1955| cc | Array<[MmsAddress](#mmsaddress8)\> | 否 | 抄送 | 1956| bcc | Array<[MmsAddress](#mmsaddress8)\> | 否 | 暗抄送 | 1957| subject | string | 否 | 主题 | 1958| messageClass | number | 否 | 消息类 | 1959| expiry | number | 否 | 到期 | 1960| priority | [MmsPriorityType](#mmsprioritytype8) | 否 | 优先 | 1961| senderVisibility | number | 否 | 发件人可见性 | 1962| deliveryReport | number | 否 | 交付报告 | 1963| readReport | number | 否 | 阅读报告 | 1964 1965## MmsSendConf<sup>8+</sup> 1966 1967彩信发送配置。 1968 1969**系统接口:** 此接口为系统接口。 1970 1971**系统能力**:SystemCapability.Telephony.SmsMms 1972 1973| 名称 | 类型 | 必填 | 说明 | 1974| ------------- | ---------------------------------- | ---- | -------- | 1975| responseState | number | 是 | 响应状态 | 1976| transactionId | string | 是 | 事务ID | 1977| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 1978| messageId | string | 否 | 消息ID | 1979 1980## MmsNotificationInd<sup>8+</sup> 1981 1982彩信通知索引。 1983 1984**系统接口:** 此接口为系统接口。 1985 1986**系统能力**:SystemCapability.Telephony.SmsMms 1987 1988| 名称 | 类型 | 必填 | 说明 | 1989| --------------- | ---------------------------------- | ---- | -------- | 1990| transactionId | string | 是 | 事务ID | 1991| messageClass | number | 是 | 消息类 | 1992| messageSize | number | 是 | 消息大小 | 1993| expiry | number | 是 | 到期 | 1994| contentLocation | string | 是 | 内容位置 | 1995| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 1996| from | [MmsAddress](#mmsaddress8) | 否 | 来源 | 1997| subject | string | 否 | 主题 | 1998| deliveryReport | number | 否 | 状态报告 | 1999| contentClass | number | 否 | 内容类 | 2000 2001## MmsAcknowledgeInd<sup>8+</sup> 2002 2003彩信确认索引。 2004 2005**系统接口:** 此接口为系统接口。 2006 2007**系统能力**:SystemCapability.Telephony.SmsMms 2008 2009| 名称 | 类型 | 必填 | 说明 | 2010| ------------- | ---------------------------------- | ---- | -------- | 2011| transactionId | string | 是 | 事务ID | 2012| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2013| reportAllowed | [ReportType](#reporttype8) | 否 | 允许报告 | 2014 2015## MmsRetrieveConf<sup>8+</sup> 2016 2017彩信检索配置。 2018 2019**系统接口:** 此接口为系统接口。 2020 2021**系统能力**:SystemCapability.Telephony.SmsMms 2022 2023| 名称 | 类型 | 必填 | 说明 | 2024| -------------- | ------------------------------------ | ---- | -------- | 2025| transactionId | string | 是 | 事务ID | 2026| messageId | string | 是 | 消息ID | 2027| date | number | 是 | 日期 | 2028| contentType | string | 是 | 内容类型 | 2029| to | Array<[MmsAddress](#mmsaddress8)\> | 是 | 发送至 | 2030| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2031| from | [MmsAddress](#mmsaddress8) | 否 | 来源 | 2032| cc | Array<[MmsAddress](#mmsaddress8)\> | 否 | 抄送 | 2033| subject | string | 否 | 主题 | 2034| priority | [MmsPriorityType](#mmsprioritytype8) | 否 | 优先级 | 2035| deliveryReport | number | 否 | 状态报告 | 2036| readReport | number | 否 | 阅读报告 | 2037| retrieveStatus | number | 否 | 检索状态 | 2038| retrieveText | string | 否 | 检索文本 | 2039 2040## MmsReadOrigInd<sup>8+</sup> 2041 2042彩信读取原始索引。 2043 2044**系统接口:** 此接口为系统接口。 2045 2046**系统能力**:SystemCapability.Telephony.SmsMms 2047 2048| 名称 | 类型 | 必填 | 说明 | 2049| ---------- | ---------------------------------- | ---- | -------- | 2050| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2051| messageId | string | 是 | 消息ID | 2052| to | Array<[MmsAddress](#mmsaddress8)\> | 是 | 发送至 | 2053| from | [MmsAddress](#mmsaddress8) | 是 | 来源 | 2054| date | number | 是 | 日期 | 2055| readStatus | number | 是 | 阅读状态 | 2056 2057## MmsReadRecInd<sup>8+</sup> 2058 2059彩信读取记录索引。 2060 2061**系统接口:** 此接口为系统接口。 2062 2063**系统能力**:SystemCapability.Telephony.SmsMms 2064 2065| 名称 | 类型 | 必填 | 说明 | 2066| ---------- | ---------------------------------- | ---- | -------- | 2067| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2068| messageId | string | 是 | 消息ID | 2069| to | Array<[MmsAddress](#mmsaddress8)\> | 是 | 发送至 | 2070| from | [MmsAddress](#mmsaddress8) | 是 | 来源 | 2071| readStatus | number | 是 | 阅读状态 | 2072| date | number | 否 | 日期 | 2073 2074## MmsAttachment<sup>8+</sup> 2075 2076彩信附件。 2077 2078**系统接口:** 此接口为系统接口。 2079 2080**系统能力**:SystemCapability.Telephony.SmsMms 2081 2082| 名称 | 类型 | 必填 | 说明 | 2083| ----------------------- | ------------------------------------ | ---- | ------------------ | 2084| contentId | string | 是 | 内容ID | 2085| contentLocation | string | 是 | 内容位置 | 2086| contentDisposition | [DispositionType](#dispositiontype8) | 是 | 内容处理 | 2087| contentTransferEncoding | string | 是 | 内容传输编码 | 2088| contentType | string | 是 | 内容类型 | 2089| isSmil | boolean | 是 | 同步多媒体集成语言 | 2090| path | string | 否 | 路径 | 2091| inBuff | Array<number\> | 否 | 缓冲区中 | 2092| fileName | string | 否 | 文件名 | 2093| charset | [MmsCharSets](#mmscharsets8) | 否 | 字符集 | 2094 2095## MmsAddress<sup>8+</sup> 2096 2097彩信地址。 2098 2099**系统接口:** 此接口为系统接口。 2100 2101**系统能力**:SystemCapability.Telephony.SmsMms 2102 2103| 名称 | 类型 | 必填 | 说明 | 2104| ------- | ---------------------------- | ---- | ------ | 2105| address | string | 是 | 地址 | 2106| charset | [MmsCharSets](#mmscharsets8) | 是 | 字符集 | 2107 2108## MessageType<sup>8+</sup> 2109 2110消息类型。 2111 2112**系统接口:** 此接口为系统接口。 2113 2114**系统能力**:SystemCapability.Telephony.SmsMms 2115 2116| 名称 | 值 | 说明 | 2117| ------------------------- | ---- | -------------------- | 2118| TYPE_MMS_SEND_REQ | 128 | 彩信发送请求类型 | 2119| TYPE_MMS_SEND_CONF | 129 | 彩信发送配置类型 | 2120| TYPE_MMS_NOTIFICATION_IND | 130 | 彩信通知索引类型 | 2121| TYPE_MMS_RESP_IND | 131 | 彩信回复索引类型 | 2122| TYPE_MMS_RETRIEVE_CONF | 132 | 彩信检索配置类型 | 2123| TYPE_MMS_ACKNOWLEDGE_IND | 133 | 彩信确认索引类型 | 2124| TYPE_MMS_DELIVERY_IND | 134 | 彩信传送索引类型 | 2125| TYPE_MMS_READ_REC_IND | 135 | 彩信读取接收索引类型 | 2126| TYPE_MMS_READ_ORIG_IND | 136 | 彩信读取原始索引类型 | 2127 2128## MmsPriorityType<sup>8+</sup> 2129 2130彩信优先级类型。 2131 2132**系统接口:** 此接口为系统接口。 2133 2134**系统能力**:SystemCapability.Telephony.SmsMms 2135 2136| 名称 | 值 | 说明 | 2137| ---------- | ---- | -------------- | 2138| MMS_LOW | 128 | 彩信优先级低 | 2139| MMS_NORMAL | 129 | 彩信优先级正常 | 2140| MMS_HIGH | 130 | 彩信优先级高 | 2141 2142## MmsVersionType<sup>8+</sup> 2143 2144彩信版本类型。 2145 2146**系统接口:** 此接口为系统接口。 2147 2148**系统能力**:SystemCapability.Telephony.SmsMms 2149 2150| 名称 | 值 | 说明 | 2151| --------------- | ---- | ----------- | 2152| MMS_VERSION_1_0 | 0x10 | 彩信版本1_0 | 2153| MMS_VERSION_1_1 | 0x11 | 彩信版本1_1 | 2154| MMS_VERSION_1_2 | 0x12 | 彩信版本1_2 | 2155| MMS_VERSION_1_3 | 0x13 | 彩信版本1_3 | 2156 2157## MmsCharSets<sup>8+</sup> 2158 2159彩信字符集。 2160 2161**系统接口:** 此接口为系统接口。 2162 2163**系统能力**:SystemCapability.Telephony.SmsMms 2164 2165| 名称 | 值 | 说明 | 2166| --------------- | ------ | ------------------- | 2167| BIG5 | 0X07EA | BIG5格式 | 2168| ISO_10646_UCS_2 | 0X03E8 | ISO_10646_UCS_2格式 | 2169| ISO_8859_1 | 0X04 | ISO_8859_1格式 | 2170| ISO_8859_2 | 0X05 | ISO_8859_2格式 | 2171| ISO_8859_3 | 0X06 | ISO_8859_3格式 | 2172| ISO_8859_4 | 0X07 | ISO_8859_4格式 | 2173| ISO_8859_5 | 0X08 | ISO_8859_5格式 | 2174| ISO_8859_6 | 0X09 | ISO_8859_6格式 | 2175| ISO_8859_7 | 0X0A | ISO_8859_7格式 | 2176| ISO_8859_8 | 0X0B | ISO_8859_8格式 | 2177| ISO_8859_9 | 0X0C | ISO_8859_9格式 | 2178| SHIFT_JIS | 0X11 | SHIFT_JIS格式 | 2179| US_ASCII | 0X03 | US_ASCII格式 | 2180| UTF_8 | 0X6A | UTF_8格式 | 2181 2182## DispositionType<sup>8+</sup> 2183 2184处理类型。 2185 2186**系统接口:** 此接口为系统接口。 2187 2188**系统能力**:SystemCapability.Telephony.SmsMms 2189 2190| 名称 | 值 | 说明 | 2191| ---------- | ---- | -------- | 2192| FROM_DATA | 0 | 数据来源 | 2193| ATTACHMENT | 1 | 附件 | 2194| INLINE | 2 | 内联 | 2195 2196## ReportType<sup>8+</sup> 2197 2198报告类型。 2199 2200**系统接口:** 此接口为系统接口。 2201 2202**系统能力**:SystemCapability.Telephony.SmsMms 2203 2204| 名称 | 值 | 说明 | 2205| ------- | ---- | ---- | 2206| MMS_YES | 128 | YES | 2207| MMS_NO | 129 | NO | 2208 2209## CBConfigOptions<sup>7+</sup> 2210 2211小区广播配置选项。 2212 2213**系统接口:** 此接口为系统接口。 2214 2215**系统能力**:SystemCapability.Telephony.SmsMms 2216 2217| 名称 | 类型 | 必填 | 说明 | 2218| -------------- | -------------------- | ---- | ------------ | 2219| slotId | number | 是 | 卡槽ID | 2220| enable | boolean | 是 | 可行 | 2221| startMessageId | number | 是 | 消息起始ID | 2222| endMessageId | number | 是 | 消息结束ID | 2223| ranType | [RanType](#rantype7) | 是 | 设备网络制式 | 2224 2225## SimMessageStatus<sup>7+</sup> 2226 2227SIM卡消息状态。 2228 2229**系统接口:** 此接口为系统接口。 2230 2231**系统能力**:SystemCapability.Telephony.SmsMms 2232 2233| 名称 | 值 | 说明 | 2234| ------------------------- | ---- | --------------------------- | 2235| SIM_MESSAGE_STATUS_FREE | 0 | SIM卡上的可用空间状态 | 2236| SIM_MESSAGE_STATUS_READ | 1 | 消息已读状态 | 2237| SIM_MESSAGE_STATUS_UNREAD | 3 | 消息未读状态 | 2238| SIM_MESSAGE_STATUS_SENT | 5 | 存储发送消息(仅适用于SMS) | 2239| SIM_MESSAGE_STATUS_UNSENT | 7 | 存储未发送消息(仅适用于SMS) | 2240 2241## RanType<sup>7+</sup> 2242 2243设备网络制式。 2244 2245**系统接口:** 此接口为系统接口。 2246 2247**系统能力**:SystemCapability.Telephony.SmsMms 2248 2249| 名称 | 值 | 说明 | 2250| --------- | ---- | ---- | 2251| TYPE_GSM | 1 | GSM | 2252| TYPE_CDMA | 2 | CMDA | 2253 2254## SmsEncodingScheme<sup>8+</sup> 2255 2256短信编码方案。 2257 2258**系统接口:** 此接口为系统接口。 2259 2260**系统能力**:SystemCapability.Telephony.SmsMms 2261 2262| 名称 | 值 | 说明 | 2263| -------------------- | ---- | ------------ | 2264| SMS_ENCODING_UNKNOWN | 0 | 未知短信编码 | 2265| SMS_ENCODING_7BIT | 1 | 7位短信编码 | 2266| SMS_ENCODING_8BIT | 2 | 8位短信编码 | 2267| SMS_ENCODING_16BIT | 3 | 16位短信编码 | 2268 2269## SimMessageOptions<sup>7+</sup> 2270 2271SIM卡消息选项。 2272 2273**系统接口:** 此接口为系统接口。 2274 2275**系统能力**:SystemCapability.Telephony.SmsMms 2276 2277| 名称 | 类型 | 必填 | 说明 | 2278| ------ | -------------------------------------- | ---- | -------------- | 2279| slotId | number | 是 | 卡槽ID | 2280| smsc | string | 是 | 短消息业务中心 | 2281| pdu | string | 是 | 协议数据单元 | 2282| status | [SimMessageStatus](#simmessagestatus7) | 是 | 状态 | 2283 2284## UpdateSimMessageOptions<sup>7+</sup> 2285 2286更新SIM卡消息选项。 2287 2288**系统接口:** 此接口为系统接口。 2289 2290**系统能力**:SystemCapability.Telephony.SmsMms 2291 2292| 名称 | 类型 | 必填 | 说明 | 2293| --------- | -------------------------------------- | ---- | -------------- | 2294| slotId | number | 是 | 卡槽ID | 2295| msgIndex | number | 是 | 消息索引 | 2296| newStatus | [SimMessageStatus](#simmessagestatus7) | 是 | 新状态 | 2297| pdu | string | 是 | 协议数据单元 | 2298| smsc | string | 是 | 短消息业务中心 | 2299 2300## SimShortMessage<sup>7+</sup> 2301 2302SIM卡短消息。 2303 2304**系统接口:** 此接口为系统接口。 2305 2306**系统能力**:SystemCapability.Telephony.SmsMms 2307 2308| 名称 | 类型 | 必填 | 说明 | 2309| ---------------- | -------------------------------------- | ---- | ------------- | 2310| shortMessage | [ShortMessage](js-apis-sms.md#shortmessage) | 是 | 短消息 | 2311| simMessageStatus | [SimMessageStatus](#simmessagestatus7) | 是 | SIM卡消息状态 | 2312| indexOnSim | number | 是 | SIM卡索引 | 2313 2314## MmsDeliveryInd<sup>8+</sup> 2315 2316彩信发送标识。 2317 2318**系统接口:** 此接口为系统接口。 2319 2320**系统能力**:SystemCapability.Telephony.SmsMms 2321 2322| 名称 | 类型 | 必填 | 说明 | 2323| --------- | ---------------------------------- | ---- | ------ | 2324| messageId | string | 是 | 消息ID | 2325| date | number | 是 | 日期 | 2326| to | Array<[MmsAddress](#mmsaddress8)\> | 是 | 发送至 | 2327| status | number | 是 | 状态 | 2328| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2329 2330## MmsRespInd<sup>8+</sup> 2331 2332彩信回复标志。 2333 2334**系统接口:** 此接口为系统接口。 2335 2336**系统能力**:SystemCapability.Telephony.SmsMms 2337 2338| 名称 | 类型 | 必填 | 说明 | 2339| ------------- | ---------------------------------- | ---- | -------- | 2340| transactionId | string | 是 | 事件ID | 2341| status | number | 是 | 状态 | 2342| version | [MmsVersionType](#mmsversiontype8) | 是 | 版本 | 2343| reportAllowed | [ReportType](#reporttype8) | 否 | 允许报告 | 2344 2345## SmsSegmentsInfo<sup>8+</sup> 2346 2347短信段信息。 2348 2349**系统接口:** 此接口为系统接口。 2350 2351**系统能力**:SystemCapability.Telephony.SmsMms 2352 2353| 名称 | 类型 | 必填 | 说明 | 2354| -------------------- | ---------------------------------------- | ---- | ------------ | 2355| splitCount | number | 是 | 拆分计数 | 2356| encodeCount | number | 是 | 编码计数 | 2357| encodeCountRemaining | number | 是 | 剩余编码计数 | 2358| scheme | [SmsEncodingScheme](#smsencodingscheme8) | 是 | 短信编码方案 | 2359