openharmony 鸿蒙 js-apis-sms-sys

2025-06-12 浏览 (1)

@ohos.telephony.sms (SMS) (System API)

The 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.

NOTE

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.

This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.telephony.sms (SMS).

Modules to Import

import { sms } from '@kit.TelephonyKit';

sms.sendMms11+

sendMms(context: Context, mmsParams: MmsParams, callback: AsyncCallback<void>): void

Sends an MMS message. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contextContextYesApplication context.
For details about the application context of the FA model, see Context.
For details about the application context of the stage model, see Context.
mmsParamsMmsParamsYesParameters (including the callback) for sending MMS messages. For details, see MmsParams.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

FA model:

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common, featureAbility } from '@kit.AbilityKit';

// Obtain the context.
let context: common.BaseContext = featureAbility.getContext();

// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
const sandBoxPath: string = '/data/storage/el2/base/files/';
let filePath: string  = sandBoxPath + 'SendReq.mms';

// Options for sending MMS messages (The MMSC is for reference only.)
let mmsPars: sms.MmsParams = {
  slotId : 0,
  mmsc: 'http://mmsc.myuni.com.cn',
  data: filePath,
  mmsConfig: {
   userAgent:'ua',
   userAgentProfile: 'uaprof'
  }
};

// Call the sendMms API.
sms.sendMms(context, mmsPars, async(err: BusinessError) =>{
  if (err) {
      console.error(`sendMms fail, err : ${JSON.stringify(err)}`);
      return;
  }
  console.log(`sendMms Success`);
})

Stage model:

import { UIAbility } from '@kit.AbilityKit';
import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
const sandBoxPath = '/data/storage/el2/base/files/';
let filePath  = sandBoxPath + 'SendReq.mms';

// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements. 
let mmsConf: sms.MmsConfig = {
  userAgent:'ua',
  userAgentProfile: 'uaprof'
};

// Options for sending MMS messages (The MMSC is for reference only.)
let mmsPars: sms.MmsParams = {
  slotId : 0,
  mmsc: 'http://mmsc.myuni.com.cn',
  data: filePath,
  mmsConfig: mmsConf
};

class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage: window.WindowStage) {
    sms.sendMms(this.context, mmsPars, async(err: BusinessError) =>{
        if (err) {
            console.error(`sendMms fail, err : ${JSON.stringify(err)}`);
            return;
        }
        console.log(`sendMms Success`);
        })
    }
}

sms.sendMms11+

sendMms(context: Context, mmsParams: MmsParams): Promise<void>

Sends an MMS message. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contextContextYesApplication context.
For details about the application context of the FA model, see Context.
For details about the application context of the stage model, see Context.
mmsParamsMmsParamsYesParameters (including the callback) for sending MMS messages. For details, see MmsParams.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

FA model:

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common, featureAbility } from '@kit.AbilityKit';

// Obtain the context.
let context: common.BaseContext = featureAbility.getContext();

// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
const sandBoxPath: string = '/data/storage/el2/base/files/';
let filePath: string = sandBoxPath + 'SendReq.mms';

// Options for sending MMS messages (The MMSC is for reference only.)
let mmsPars: sms.MmsParams = {
  slotId: 0,
  mmsc: 'http://mmsc.myuni.com.cn',
  data: filePath,
  mmsConfig: {
   userAgent:'ua',
   userAgentProfile: 'uaprof'
  }
};

// Call the sendMms API.
let promise = sms.sendMms(context, mmsPars);
promise.then(() => {
    console.log(`sendMms success`);
}).catch((err: BusinessError) => {
    console.error(`sendMms failed, promise: err->${JSON.stringify(err)}`);
});

Stage model:

import { UIAbility } from '@kit.AbilityKit';
import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// Configure the path for storing PDUs of MMS messages. Such PDUs are sent from the encoding API.
const sandBoxPath = '/data/storage/el2/base/files/';
let filePath  = sandBoxPath + 'SendReq.mms';

// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements. 
let mmsConf: sms.MmsConfig = {
  userAgent:'ua',
  userAgentProfile: 'uaprof'
};

// Options for sending MMS messages (The MMSC is for reference only.)
let mmsPars: sms.MmsParams = {
  slotId : 0,
  mmsc: 'http://mmsc.myuni.com.cn',
  data: filePath,
  mmsConfig: mmsConf
};

class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage: window.WindowStage) {
    let promise = sms.sendMms(this.context, mmsPars);
    promise.then(() => {
        console.log(`sendMms success`);
    }).catch((err: BusinessError) => {
        console.error(`sendMms failed, promise: err->${JSON.stringify(err)}`);
    });
    }
}

sms.downloadMms11+

downloadMms(context: Context, mmsParams: MmsParams, callback: AsyncCallback<void>): void

Downloads an MMS message. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_MMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contextContextYesApplication context.
For details about the application context of the FA model, see Context.
For details about the application context of the stage model, see Context.
mmsParamsMmsParamsYesParameters (including the callback) for downloading MMS messages. For details, see MmsParams.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

FA model:

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common, featureAbility } from '@kit.AbilityKit';

// Obtain the context.
let context: common.BaseContext = featureAbility.getContext();

// Configure the path for storing the PDU of the MMS message.
const sandBoxPath: string = '/data/storage/el2/base/files/';
let filePath: string = sandBoxPath + 'RetrieveConf.mms';

// Parse the MMS URL from the WAP Push message.
let wapPushUrl: string = 'URL';

// Configure the parameters (including the callback) for downloading MMS messages.
let mmsPars: sms.MmsParams = {
  slotId: 0,
  mmsc: wapPushUrl,
  data: filePath,
  mmsConfig: {
   userAgent:'ua',
   userAgentProfile: 'uaprof'
  }
};

// Call the downloadMms API.
sms.downloadMms(context, mmsPars, async(err: BusinessError) =>{
  if (err) {
      console.error(`downloadMms fail, err : ${JSON.stringify(err)}`);
      return;
  }
  console.log(`downloadMms Success`);
})

Stage model:

import { UIAbility } from '@kit.AbilityKit';
import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// Configure the path for storing the PDU of the MMS message.
const sandBoxPath = '/data/storage/el2/base/files/';
let filePath  = sandBoxPath + 'RetrieveConf.mms';

// Parse the MMS URL from the WAP Push message.
let wapPushUrl  = 'URL';

// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements. 
let mmsConf: sms.MmsConfig = {
  userAgent:'ua',
  userAgentProfile: 'uaprof'
};

// Configure the parameters (including the callback) for downloading MMS messages.
let mmsPars: sms.MmsParams = {
  slotId : 0,
  mmsc: wapPushUrl,
  data: filePath,
  mmsConfig: mmsConf
};

class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage: window.WindowStage) {
    sms.downloadMms(this.context, mmsPars, async(err: BusinessError) =>{
        if (err) {
            console.error(`downloadMms fail, err : ${JSON.stringify(err)}`);
            return;
        }
        console.log(`downloadMms Success`);
        });
    }
}

sms.downloadMms11+

downloadMms(context: Context, mmsParams: MmsParams): Promise<void>

Sends an MMS message. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_MMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contextContextYesApplication context.
For details about the application context of the FA model, see Context.
For details about the application context of the stage model, see Context.
mmsParamsMmsParamsYesParameters (including the callback) for sending MMS messages. For details, see MmsParams.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

FA model:

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { common, featureAbility } from '@kit.AbilityKit';

// Obtain the context.
let context: common.BaseContext = featureAbility.getContext();

// Configure the path for storing the PDU of the MMS message.
const sandBoxPath: string = '/data/storage/el2/base/files/';
let filePath: string = sandBoxPath + 'RetrieveConf.mms';

// Parse the MMS URL from the WAP Push message.
let wapPushUrl: string = 'URL';

// Configure the parameters (including the callback) for downloading MMS messages.
let mmsPars: sms.MmsParams = {
  slotId: 0,
  mmsc: wapPushUrl,
  data: filePath,
  mmsConfig: {
   userAgent:'ua',
   userAgentProfile: 'uaprof'
  }
};

// Call the sendMms API.
let promise = sms.downloadMms(context, mmsPars);
promise.then(() => {
    console.log(`downloadMms success`);
}).catch((err: BusinessError) => {
    console.error(`downloadMms failed, promise: err->${JSON.stringify(err)}`);
});

Stage model:

import { UIAbility } from '@kit.AbilityKit';
import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { window } from '@kit.ArkUI';

// Configure the path for storing the PDU of the MMS message.
const sandBoxPath = '/data/storage/el2/base/files/';
let filePath  = sandBoxPath + 'RetrieveConf.mms';

// Parse the MMS URL from the WAP Push message.
let wapPushUrl  = 'URL';

// Configure the MMS user agent and profile. The default values are ua and uaprof, respectively. The configuration is subject to the carrier's requirements. 
let mmsConf: sms.MmsConfig = {
  userAgent:'ua',
  userAgentProfile: 'uaprof'
};

// Configure the parameters (including the callback) for downloading MMS messages.
let mmsPars: sms.MmsParams = {
  slotId : 0,
  mmsc: wapPushUrl,
  data: filePath,
  mmsConfig: mmsConf
};

class EntryAbility extends UIAbility {
    onWindowStageCreate(windowStage: window.WindowStage) {
    let promise = sms.downloadMms(this.context, mmsPars);
    promise.then(() => {
        console.log(`downloadMms success`);
    }).catch((err: BusinessError) => {
        console.error(`downloadMms failed, promise: err->${JSON.stringify(err)}`);
    });
    }
}

sms.setDefaultSmsSlotId7+

setDefaultSmsSlotId(slotId: number, callback: AsyncCallback<void>): void

Sets the default slot ID of the SIM card used to send SMS messages. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
- -1: Clears the default configuration.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

sms.setDefaultSmsSlotId(0, (err: BusinessError) => {
    console.log(`callback: err->${JSON.stringify(err)}.`);
});

sms.setDefaultSmsSlotId7+

setDefaultSmsSlotId(slotId: number): Promise<void>

Sets the default slot ID of the SIM card used to send SMS messages. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SET_TELEPHONY_STATE

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
- -1: Clears the default configuration.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300004Do not have sim card.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

sms.setDefaultSmsSlotId(0).then(() => {
    console.log(`setDefaultSmsSlotId success.`);
}).catch((err: BusinessError) => {
    console.error(`setDefaultSmsSlotId failed, promise: err->${JSON.stringify(err)}`);
});

sms.setSmscAddr7+

setSmscAddr(slotId: number, smscAddr: string, callback: AsyncCallback<void>): void

Sets the short message service center (SMSC) address. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SET_TELEPHONY_STATE (a system permission)

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
smscAddrstringYesSMSC address.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let smscAddr: string = '+861xxxxxxxxxx';
sms.setSmscAddr(slotId, smscAddr, (err: BusinessError) => {
      console.log(`callback: err->${JSON.stringify(err)}`);
});

sms.setSmscAddr7+

setSmscAddr(slotId: number, smscAddr: string): Promise<void>

Sets the SMSC address. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SET_TELEPHONY_STATE (a system permission)

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
smscAddrstringYesSMSC address.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let smscAddr: string = '+861xxxxxxxxxx';
sms.setSmscAddr(slotId, smscAddr).then(() => {
    console.log(`setSmscAddr success.`);
}).catch((err: BusinessError) => {
    console.error(`setSmscAddr failed, promise: err->${JSON.stringify(err)}`);
});

sms.getSmscAddr7+

getSmscAddr(slotId: number, callback: AsyncCallback<string>): void

Obtains the SMSC address. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_TELEPHONY_STATE (a system permission)

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
sms.getSmscAddr(slotId, (err: BusinessError, data: string) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.getSmscAddr7+

getSmscAddr(slotId: number): Promise<string>

Obtains the SMSC address. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.GET_TELEPHONY_STATE (a system permission)

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
sms.getSmscAddr(slotId).then((data: string) => {
    console.log(`getSmscAddr success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSmscAddr failed, promise: err->${JSON.stringify(err)}`);
});

sms.splitMessage8+

splitMessage(content: string, callback: AsyncCallback<Array<string>>): void

Splits an SMS message into multiple segments. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contentstringYesSMS message content. The value cannot be null.
callbackAsyncCallback<Array<string>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let content: string = "long message";
sms.splitMessage(content, (err: BusinessError, data: string[]) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.splitMessage8+

splitMessage(content: string): Promise<Array<string>>

Splits an SMS message into multiple segments. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
contentstringYesSMS message content. The value cannot be null.

Return value

TypeDescription
Promise<Array<string>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let content: string = "long message";
let promise = sms.splitMessage(content);
promise.then((data: string[]) => {
    console.log(`splitMessage success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`splitMessage failed, promise: err->${JSON.stringify(err)}`);
});

sms.addSimMessage7+

addSimMessage(options: SimMessageOptions, callback: AsyncCallback<void>): void

Adds 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.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsSimMessageOptionsYesSIM message options.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let simMessageOptions: sms.SimMessageOptions = {
    slotId: 0,
    smsc: "test",
    pdu: "xxxxxx",
    status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
};
sms.addSimMessage(simMessageOptions, (err: BusinessError) => {
      console.log(`callback: err->${JSON.stringify(err)}`);
});

sms.addSimMessage7+

addSimMessage(options: SimMessageOptions): Promise<void>

Adds 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.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsSimMessageOptionsYesSIM message options.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let simMessageOptions: sms.SimMessageOptions = {
    slotId: 0,
    smsc: "test",
    pdu: "xxxxxx",
    status: sms.SimMessageStatus.SIM_MESSAGE_STATUS_READ
};
sms.addSimMessage(simMessageOptions).then(() => {
    console.log(`addSimMessage success.`);
}).catch((err: BusinessError) => {
    console.error(`addSimMessage failed, promise: err->${JSON.stringify(err)}`);
});

sms.delSimMessage7+

delSimMessage(slotId: number, msgIndex: number, callback: AsyncCallback<void>): void

Deletes 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.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
msgIndexnumberYesMessage index.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let msgIndex: number = 1;
sms.delSimMessage(slotId, msgIndex, (err: BusinessError) => {
      console.log(`callback: err->${JSON.stringify(err)}`);
});

sms.delSimMessage7+

delSimMessage(slotId: number, msgIndex: number): Promise<void>

Deletes 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.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
msgIndexnumberYesMessage index.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let msgIndex: number = 1;
let promise = sms.delSimMessage(slotId, msgIndex);
promise.then(() => {
    console.log(`delSimMessage success.`);
}).catch((err: BusinessError) => {
    console.error(`delSimMessage failed, promise: err->${JSON.stringify(err)}`);
});

sms.updateSimMessage7+

updateSimMessage(options: UpdateSimMessageOptions, callback: AsyncCallback<void>): void

Updates a SIM message. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsUpdateSimMessageOptionsYesSIM message updating options.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let updateSimMessageOptions: sms.UpdateSimMessageOptions = {
    slotId: 0,
    msgIndex: 1,
    newStatus: sms.SimMessageStatus.SIM_MESSAGE_STATUS_FREE,
    pdu: "xxxxxxx",
    smsc: "test"
};
sms.updateSimMessage(updateSimMessageOptions, (err: BusinessError) => {
      console.log(`callback: err->${JSON.stringify(err)}`);
});

sms.updateSimMessage7+

updateSimMessage(options: UpdateSimMessageOptions): Promise<void>

Updates a SIM message. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS and ohos.permission.SEND_MESSAGES

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsUpdateSimMessageOptionsYesSIM message updating options.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let updateSimMessageOptions: sms.UpdateSimMessageOptions = {
    slotId: 0,
    msgIndex: 1,
    newStatus: sms.SimMessageStatus.SIM_MESSAGE_STATUS_FREE,
    pdu: "xxxxxxx",
    smsc: "test"
};
let promise = sms.updateSimMessage(updateSimMessageOptions);
promise.then(() => {
    console.log(`updateSimMessage success.`);
}).catch((err: BusinessError) => {
    console.error(`updateSimMessage failed, promise: err->${JSON.stringify(err)}`);
});

sms.getAllSimMessages7+

getAllSimMessages(slotId: number, callback: AsyncCallback<Array<SimShortMessage>>): void

Obtains all SIM card messages. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<Array<SimShortMessage>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
sms.getAllSimMessages(slotId, (err: BusinessError, data: sms.SimShortMessage[]) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.getAllSimMessages7+

getAllSimMessages(slotId: number): Promise<Array<SimShortMessage>>

Obtains all SIM card messages. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<Array<SimShortMessage>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let promise = sms.getAllSimMessages(slotId);
promise.then((data: sms.SimShortMessage[]) => {
    console.log(`getAllSimMessages success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getAllSimMessages failed, promise: err->${JSON.stringify(err)}`);
});

sms.setCBConfig7+

setCBConfig(options: CBConfigOptions, callback: AsyncCallback<void>): void

Sets the cell broadcast configuration. This API uses an asynchronous callback to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsCBConfigOptionsYesCell broadcast configuration options.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let cbConfigOptions: sms.CBConfigOptions = {
    slotId: 0,
    enable: true,
    startMessageId: 100,
    endMessageId: 200,
    ranType: sms.RanType.TYPE_GSM
};
sms.setCBConfig(cbConfigOptions, (err: BusinessError) => {
      console.log(`callback: err->${JSON.stringify(err)}`);
});

sms.setCBConfig7+

setCBConfig(options: CBConfigOptions): Promise<void>

Sets the cell broadcast configuration. This API uses a promise to return the result.

System API: This is a system API.

Required permissions: ohos.permission.RECEIVE_SMS

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
optionsCBConfigOptionsYesCell broadcast configuration options.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
201Permission denied.
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let cbConfigOptions: sms.CBConfigOptions = {
    slotId: 0,
    enable: true,
    startMessageId: 100,
    endMessageId: 200,
    ranType: sms.RanType.TYPE_GSM
};
let promise = sms.setCBConfig(cbConfigOptions);
promise.then(() => {
    console.log(`setCBConfig success.`);
}).catch((err: BusinessError) => {
    console.error(`setCBConfig failed, promise: err->${JSON.stringify(err)}`);
});

sms.getSmsSegmentsInfo8+

getSmsSegmentsInfo(slotId: number, message: string, force7bit: boolean, callback: AsyncCallback<SmsSegmentsInfo>): void

Obtains SMS message segment information. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
messagestringYesSMS message.
force7bitbooleanYesWhether to use 7-bit coding.
callbackAsyncCallback<SmsSegmentsInfo>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
sms.getSmsSegmentsInfo(slotId, "message", false, (err: BusinessError, data: sms.SmsSegmentsInfo) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.getSmsSegmentsInfo8+

getSmsSegmentsInfo(slotId: number, message: string, force7bit: boolean): Promise<SmsSegmentsInfo>

Obtains SMS message segment information. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
messagestringYesSMS message.
force7bitbooleanYesWhether to use 7-bit coding.

Return value

TypeDescription
Promise<SmsSegmentsInfo>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let promise = sms.getSmsSegmentsInfo(slotId, "message", false);
promise.then((data: sms.SmsSegmentsInfo) => {
    console.log(`getSmsSegmentsInfo success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getSmsSegmentsInfo failed, promise: err->${JSON.stringify(err)}`);
});

sms.isImsSmsSupported8+

isImsSmsSupported(slotId: number, callback: AsyncCallback<boolean>): void

Checks whether SMS is supported on IMS. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesSIM card slot ID.
- 0: card slot 1
- 1: card slot 2
callbackAsyncCallback<boolean>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
sms.isImsSmsSupported(slotId, (err: BusinessError, data: boolean) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.isImsSmsSupported8+

isImsSmsSupported(slotId: number): Promise<boolean>

Checks whether SMS is supported on IMS. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
- 0: card slot 1
- 1: card slot 2

Return value

TypeDescription
Promise<boolean>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let slotId: number = 0;
let promise = sms.isImsSmsSupported(slotId);
promise.then((data: boolean) => {
    console.log(`isImsSmsSupported success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`isImsSmsSupported failed, promise: err->${JSON.stringify(err)}`);
});

sms.getImsShortMessageFormat8+

getImsShortMessageFormat(callback: AsyncCallback<string>): void

Obtains the SMS format supported by the IMS, for example, 3gpp, 3gpp2, or unknown. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<string>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

sms.getImsShortMessageFormat((err: BusinessError, data: string) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.getImsShortMessageFormat8+

getImsShortMessageFormat(): Promise<string>

Obtains the SMS format supported by the IMS, for example, 3gpp, 3gpp2, or unknown. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Return value

TypeDescription
Promise<string>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

sms.getImsShortMessageFormat().then((data: string) => {
    console.log(`getImsShortMessageFormat success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`getImsShortMessageFormat failed, promise: err->${JSON.stringify(err)}`);
});

sms.decodeMms8+

decodeMms(mmsFilePathName: string|Array<number>, callback: AsyncCallback<MmsInformation>): void

Decodes MMS messages. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
mmsFilePathNamestring |Array<number>YesMMS message file path.
callbackAsyncCallback<MmsInformation>YesCallback used to return the result, which is carried in {@code MmsInformation}.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mmsFilePathName: string = "filename";
sms.decodeMms(mmsFilePathName, (err: BusinessError, data: sms.MmsInformation) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

const 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];
sms.decodeMms(mmsPdu, (err: BusinessError, data: sms.MmsInformation) => {
    console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.decodeMms8+

decodeMms(mmsFilePathName: string|Array<number>): Promise<MmsInformation>

Decodes MMS messages. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
mmsFilePathNamestring |Array<number>YesMMS message file path.

Return value

TypeDescription
Promise<<MmsInformation>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mmsFilePathName: string = "filename";
let promise = sms.decodeMms(mmsFilePathName);
promise.then((data: sms.MmsInformation) => {
    console.log(`decodeMms success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`decodeMms failed, promise: err->${JSON.stringify(err)}`);
});

const 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];
let promiseArr = sms.decodeMms(mmsPdu);
promiseArr.then((data: sms.MmsInformation) => {
    console.log(`decodeMms success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`decodeMms failed, promise: err->${JSON.stringify(err)}`);
});

sms.encodeMms8+

encodeMms(mms: MmsInformation, callback: AsyncCallback<Array<number>>): void

MMS message code. This API uses an asynchronous callback to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
mmsMmsInformationYesMMS message information.
callbackAsyncCallback<Array<number>>YesCallback used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mmsAcknowledgeInd: sms.MmsAcknowledgeInd = {
    transactionId: "100",
    version: sms.MmsVersionType.MMS_VERSION_1_0,
    reportAllowed: sms.ReportType.MMS_YES
};
let mmsInformation: sms.MmsInformation = {
    messageType: sms.MessageType.TYPE_MMS_ACKNOWLEDGE_IND,
    mmsType: mmsAcknowledgeInd
};
sms.encodeMms(mmsInformation, (err: BusinessError, data: number[]) => {
      console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});

sms.encodeMms8+

encodeMms(mms: MmsInformation): Promise<Array<number>>

MMS message code. This API uses a promise to return the result.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

Parameters

NameTypeMandatoryDescription
mmsMmsInformationYesMMS message information.

Return value

TypeDescription
Promise<Array<number>>Promise used to return the result.

Error codes

For details about the error codes, see Telephony Error Codes.

IDError Message
202Non-system applications use system APIs.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed.
8300001Invalid parameter value.
8300002Operation failed. Cannot connect to service.
8300003System internal error.
8300999Unknown error code.

Example

import { sms } from '@kit.TelephonyKit';
import { BusinessError } from '@kit.BasicServicesKit';

let mmsAcknowledgeInd: sms.MmsAcknowledgeInd = {
    transactionId: "100",
    version: sms.MmsVersionType.MMS_VERSION_1_0,
    reportAllowed: sms.ReportType.MMS_YES
};
let mmsInformation: sms.MmsInformation = {
    messageType: sms.MessageType.TYPE_MMS_ACKNOWLEDGE_IND,
    mmsType: mmsAcknowledgeInd
};
sms.encodeMms(mmsInformation).then((data: number[]) => {
    console.log(`encodeMms success, promise: data->${JSON.stringify(data)}`);
}).catch((err: BusinessError) => {
    console.error(`encodeMms failed, promise: err->${JSON.stringify(err)}`);
});

MmsParams11+

Defines the parameters for sending SMS messages.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
slotId11+numberYesSlot ID of the SIM card used for sending SMS messages.
- 0: card slot 1
- 1: card slot 2
mmsc11+stringYesMMSC address.
data11+stringYesMMS PDU address.
mmsConfig11+MmsConfigNoMMS configuration file. For details, see MmsParams.

MmsConfig11+

MMS configuration file.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
userAgent11+stringYesUser agent.
userAgentProfile11+stringYesUser agent profile.

MmsInformation8+

Defines the MMS message information.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
messageTypeMessageTypeYesMessage type.
mmsTypeMmsSendReq |MmsSendConf |MmsNotificationInd |MmsRespInd |MmsRetrieveConf|MmsAcknowledgeInd|MmsDeliveryInd|MmsReadOrigInd|MmsReadRecIndYesPDU header type.
attachmentArray<MmsAttachment>NoAttachment.

MmsSendReq8+

Defines an MMS message sending request.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
fromMmsAddressYesMMS message source.
transactionIdstringYesTransaction ID.
contentTypestringYesContent type.
versionMmsVersionTypeYesVersion.
toArray<MmsAddress>NoDestination address.
datenumberNoDate.
ccArray<MmsAddress>NoCarbon copy.
bccArray<MmsAddress>NoBlind carbon copy.
subjectstringNoSubject.
messageClassnumberNoMessage class.
expirynumberNoExpiration.
priorityMmsPriorityTypeNoPriority.
senderVisibilitynumberNoSender visibility.
deliveryReportnumberNoDelivery report.
readReportnumberNoRead report.

MmsSendConf8+

Defines the MMS message sending configuration.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
responseStatenumberYesResponse status.
transactionIdstringYesTransaction ID.
versionMmsVersionTypeYesVersion.
messageIdstringNoMessage ID.

MmsNotificationInd8+

Defines an MMS notification index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
transactionIdstringYesTransaction ID.
messageClassnumberYesMessage class.
messageSizenumberYesMessage size.
expirynumberYesExpiration.
contentLocationstringYesContent location.
versionMmsVersionTypeYesVersion.
fromMmsAddressNoSource address.
subjectstringNoSubject.
deliveryReportnumberNoStatus report.
contentClassnumberNoContent class.

MmsAcknowledgeInd8+

Defines an MMS confirmation index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
transactionIdstringYesTransaction ID.
versionMmsVersionTypeYesVersion.
reportAllowedReportTypeNoReport allowed.

MmsRetrieveConf8+

Defines the MMS message retrieval configuration.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
transactionIdstringYesTransaction ID.
messageIdstringYesMessage ID.
datenumberYesDate.
contentTypestringYesContent type.
toArray<MmsAddress>YesDestination address.
versionMmsVersionTypeYesVersion.
fromMmsAddressNoSource address.
ccArray<MmsAddress>NoCarbon copy.
subjectstringNoSubject.
priorityMmsPriorityTypeNoPriority.
deliveryReportnumberNoStatus report.
readReportnumberNoRead report.
retrieveStatusnumberNoRetrieval status.
retrieveTextstringNoRetrieval text.

MmsReadOrigInd8+

Defines the original MMS message reading index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
versionMmsVersionTypeYesVersion.
messageIdstringYesMessage ID.
toArray<MmsAddress>YesDestination address.
fromMmsAddressYesSource address.
datenumberYesDate.
readStatusnumberYesRead status.

MmsReadRecInd8+

Defines the MMS message reading index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
versionMmsVersionTypeYesVersion.
messageIdstringYesMessage ID.
toArray<MmsAddress>YesDestination address.
fromMmsAddressYesSource address.
readStatusnumberYesRead status.
datenumberNoDate.

MmsAttachment8+

Defines the attachment of an MMS message.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
contentIdstringYesContent ID.
contentLocationstringYesContent location.
contentDispositionDispositionTypeYesContent disposition.
contentTransferEncodingstringYesEncoding for content transfer.
contentTypestringYesContent type.
isSmilbooleanYesWhether the synchronized multimedia integration language is used.
pathstringNoPath.
inBuffArray<number>NoWhether the message is in the buffer.
fileNamestringNoFile name.
charsetMmsCharSetsNoCharacter set.

MmsAddress8+

Defines an MMSC address.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
addressstringYesNetwork address.
charsetMmsCharSetsYesCharacter set.

MessageType8+

Message type.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
TYPE_MMS_SEND_REQ128MMS message sending request.
TYPE_MMS_SEND_CONF129MMS message sending configuration.
TYPE_MMS_NOTIFICATION_IND130MMS notification index.
TYPE_MMS_RESP_IND131MMS message response index.
TYPE_MMS_RETRIEVE_CONF132MMS message retrieval configuration.
TYPE_MMS_ACKNOWLEDGE_IND133MMS message acknowledgement index.
TYPE_MMS_DELIVERY_IND134MMS message delivery index.
TYPE_MMS_READ_REC_IND135MMS message reading and receiving index.
TYPE_MMS_READ_ORIG_IND136Original MMS message reading index.

MmsPriorityType8+

Enumerates MMS message priorities.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
MMS_LOW128Low priority.
MMS_NORMAL129Normal priority.
MMS_HIGH130High priority.

MmsVersionType8+

Enumerates MMS versions.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
MMS_VERSION_1_00x10MMS version 1_0.
MMS_VERSION_1_10x11MMS version 1_1.
MMS_VERSION_1_20x12MMS version 1_2.
MMS_VERSION_1_30x13MMS version 1_3.

MmsCharSets8+

Enumerates MMS character sets.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
BIG50X07EABIG5 format.
ISO_10646_UCS_20X03E8ISO_10646_UCS_2 format.
ISO_8859_10X04ISO_8859_1 format.
ISO_8859_20X05ISO_8859_2 format.
ISO_8859_30X06ISO_8859_3 format.
ISO_8859_40X07ISO_8859_4 format.
ISO_8859_50X08ISO_8859_5 format.
ISO_8859_60X09ISO_8859_6 format.
ISO_8859_70X0AISO_8859_7 format.
ISO_8859_80X0BISO_8859_8 format.
ISO_8859_90X0CISO_8859_9 format.
SHIFT_JIS0X11SHIFT_JIS format.
US_ASCII0X03US_ASCII format.
UTF_80X6AUTF_8 format.

DispositionType8+

Enumerates disposition types.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
FROM_DATA0Data source.
ATTACHMENT1Attachment.
INLINE2Inlining.

ReportType8+

Enumerates report types.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
MMS_YES128YES
MMS_NO129NO

CBConfigOptions7+

Defines the cell broadcast configuration options.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
enablebooleanYesWhether to enable cell broadcast.
startMessageIdnumberYesStart message ID.
endMessageIdnumberYesEnd message ID.
ranTypeRanTypeYesRAN type.

SimMessageStatus7+

Defines the SIM message status.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
SIM_MESSAGE_STATUS_FREE0Free space state of the SIM card.
SIM_MESSAGE_STATUS_READ1Read state.
SIM_MESSAGE_STATUS_UNREAD3Unread state.
SIM_MESSAGE_STATUS_SENT5Storage of sent messages (applicable only to SMS).
SIM_MESSAGE_STATUS_UNSENT7Storage of unsent messages (applicable only to SMS).

RanType7+

RAN type.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
TYPE_GSM1GSM
TYPE_CDMA2CMDA

SmsEncodingScheme8+

Enumerates SMS encoding schemes.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameValueDescription
SMS_ENCODING_UNKNOWN0Unknown code.
SMS_ENCODING_7BIT17-digit code.
SMS_ENCODING_8BIT28-digit code.
SMS_ENCODING_16BIT316-digit code.

SimMessageOptions7+

Defines the SIM message options.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
smscstringYesShort message service center.
pdustringYesProtocol data unit.
statusSimMessageStatusYesStatus.

UpdateSimMessageOptions7+

Defines the updating SIM message options.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
slotIdnumberYesCard slot ID.
msgIndexnumberYesMessage index.
newStatusSimMessageStatusYesNew status.
pdustringYesProtocol data unit.
smscstringYesShort message service center.

SimShortMessage7+

Defines a SIM message.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
shortMessageShortMessageYesSMS message.
simMessageStatusSimMessageStatusYesSIM message status.
indexOnSimnumberYesSIM card index.

MmsDeliveryInd8+

Defines an MMS message delivery index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
messageIdstringYesMessage ID.
datenumberYesDate.
toArray<MmsAddress>YesDestination address.
statusnumberYesStatus.
versionMmsVersionTypeYesVersion.

MmsRespInd8+

Defines an MMS response index.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
transactionIdstringYesEvent ID.
statusnumberYesStatus.
versionMmsVersionTypeYesVersion.
reportAllowedReportTypeNoReport allowed.

SmsSegmentsInfo8+

Defines the SMS message segment information.

System API: This is a system API.

System capability: SystemCapability.Telephony.SmsMms

NameTypeMandatoryDescription
splitCountnumberYesSplit count.
encodeCountnumberYesEncoding count.
encodeCountRemainingnumberYesRemaining encoding count.
schemeSmsEncodingSchemeYesEncoding scheme.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Telephony Kit

harmony 鸿蒙Telephony_NetworkState

harmony 鸿蒙Telephony Error Codes

harmony 鸿蒙js-apis-call-sys

harmony 鸿蒙@ohos.telephony.call (Call)

harmony 鸿蒙@ohos.telephony.esim (eSIM Management) (System API)

harmony 鸿蒙@ohos.telephony.esim (eSIM Management)

harmony 鸿蒙@ohos.telephony.observer (Observer) (System API)

harmony 鸿蒙@ohos.telephony.observer (Observer)

harmony 鸿蒙@ohos.telephony.radio (Radio) (System API)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/nAprEj