CarrierMessagingService

public abstract class CarrierMessagingService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.carrier.CarrierMessagingService


A service that receives calls from the system when new SMS and MMS are sent or received.

To extend this class, you must declare the service in your manifest file with the Manifest.permission.BIND_CARRIER_SERVICES permission and include an intent filter with the SERVICE_INTERFACE action. For example:

 <service android:name=".MyMessagingService"
          android:label="@string/service_name"
          android:permission="android.permission.BIND_CARRIER_SERVICES">
     <intent-filter>
         <action android:name="android.service.carrier.CarrierMessagingService" />
     </intent-filter>
 </service>

Summary

Nested classes

interface CarrierMessagingService.ResultCallback<T>

A callback interface used to provide results asynchronously. 

class CarrierMessagingService.SendMmsResult

The result of sending an MMS. 

class CarrierMessagingService.SendMultipartSmsResult

The result of sending a multipart SMS. 

class CarrierMessagingService.SendSmsResult

The result of sending an SMS. 

Constants

int DOWNLOAD_STATUS_ERROR

MMS downloading failed.

int DOWNLOAD_STATUS_OK

Successfully downloaded an MMS message.

int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK

MMS downloading failed.

int RECEIVE_OPTIONS_DEFAULT

The default bitmask value passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) with all RECEIVE_OPTIONS_x flags cleared to indicate that the message should be kept and a new message notification should be shown.

int RECEIVE_OPTIONS_DROP

Used to set the flag in the bitmask passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) to indicate that the inbound SMS should be dropped.

int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE

Used to set the flag in the bitmask passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) to indicate that a new message notification should not be shown to the user when the credential-encrypted storage of the device is not available before the user unlocks the phone.

int SEND_FLAG_REQUEST_DELIVERY_STATUS

Flag to request SMS delivery status report.

int SEND_STATUS_ERROR

SMS/MMS sending failed.

int SEND_STATUS_OK

Indicates that an SMS or MMS message was successfully sent.

int SEND_STATUS_RETRY_ON_CARRIER_NETWORK

SMS/MMS sending failed.

String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Inherited constants

Public constructors

CarrierMessagingService()

Public methods

IBinder onBind(Intent intent)

Return the communication channel to the service.

void onDownloadMms(Uri contentUri, int subId, Uri location, ResultCallback<Integer> callback)

Override this method to download MMSs received.

void onFilterSms(MessagePdu pdu, String format, int destPort, int subId, ResultCallback<Boolean> callback)

This method was deprecated in API level 24. Use onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) instead.

void onReceiveTextSms(MessagePdu pdu, String format, int destPort, int subId, ResultCallback<Integer> callback)

Override this method to filter inbound SMS messages.

void onSendDataSms(byte[] data, int subId, String destAddress, int destPort, ResultCallback<CarrierMessagingService.SendSmsResult> callback)

This method was deprecated in API level 23. Override onSendDataSms(byte, int, String, int, ResultCallback) below instead.

void onSendDataSms(byte[] data, int subId, String destAddress, int destPort, int sendSmsFlag, ResultCallback<CarrierMessagingService.SendSmsResult> callback)

Override this method to intercept binary SMSs sent from the device.

void onSendMms(Uri pduUri, int subId, Uri location, ResultCallback<CarrierMessagingService.SendMmsResult> callback)

Override this method to intercept MMSs sent from the device.

void onSendMultipartTextSms(List<String> parts, int subId, String destAddress, ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)

This method was deprecated in API level 23. Override onSendMultipartTextSms(List, int, String, ResultCallback) below instead.

void onSendMultipartTextSms(List<String> parts, int subId, String destAddress, int sendSmsFlag, ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)

Override this method to intercept long SMSs sent from the device.

void onSendTextSms(String text, int subId, String destAddress, int sendSmsFlag, ResultCallback<CarrierMessagingService.SendSmsResult> callback)

Override this method to intercept text SMSs sent from the device.

void onSendTextSms(String text, int subId, String destAddress, ResultCallback<CarrierMessagingService.SendSmsResult> callback)

This method was deprecated in API level 23. Override onSendTextSms(String, int, String, ResultCallback) below instead.

Inherited methods

Constants

DOWNLOAD_STATUS_ERROR

Added in API level 22
public static final int DOWNLOAD_STATUS_ERROR

MMS downloading failed. We should not retry via the carrier network.

Constant Value: 2 (0x00000002)

DOWNLOAD_STATUS_OK

Added in API level 22
public static final int DOWNLOAD_STATUS_OK

Successfully downloaded an MMS message.

Constant Value: 0 (0x00000000)

DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK

Added in API level 22
public static final int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK

MMS downloading failed. We should retry via the carrier network.

Constant Value: 1 (0x00000001)

RECEIVE_OPTIONS_DEFAULT

Added in API level 24
public static final int RECEIVE_OPTIONS_DEFAULT

The default bitmask value passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) with all RECEIVE_OPTIONS_x flags cleared to indicate that the message should be kept and a new message notification should be shown.

Constant Value: 0 (0x00000000)

RECEIVE_OPTIONS_DROP

Added in API level 24
public static final int RECEIVE_OPTIONS_DROP

Used to set the flag in the bitmask passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) to indicate that the inbound SMS should be dropped.

Constant Value: 1 (0x00000001)

RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE

Added in API level 24
public static final int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE

Used to set the flag in the bitmask passed to the callback of onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) to indicate that a new message notification should not be shown to the user when the credential-encrypted storage of the device is not available before the user unlocks the phone. It is only applicable to devices that support file-based encryption.

Constant Value: 2 (0x00000002)

SEND_FLAG_REQUEST_DELIVERY_STATUS

Added in API level 23
public static final int SEND_FLAG_REQUEST_DELIVERY_STATUS

Flag to request SMS delivery status report.

Constant Value: 1 (0x00000001)

SEND_STATUS_ERROR

Added in API level 22
public static final int SEND_STATUS_ERROR

SMS/MMS sending failed. We should not retry via the carrier network.

Constant Value: 2 (0x00000002)

SEND_STATUS_OK

Added in API level 22
public static final int SEND_STATUS_OK

Indicates that an SMS or MMS message was successfully sent.

Constant Value: 0 (0x00000000)

SEND_STATUS_RETRY_ON_CARRIER_NETWORK

Added in API level 22
public static final int SEND_STATUS_RETRY_ON_CARRIER_NETWORK

SMS/MMS sending failed. We should retry via the carrier network.

Constant Value: 1 (0x00000001)

SERVICE_INTERFACE

Added in API level 22
public static final String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

Constant Value: "android.service.carrier.CarrierMessagingService"

Public constructors

CarrierMessagingService

public CarrierMessagingService ()

Public methods

onBind

Added in API level 22
public IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: This value cannot be null.

Returns
IBinder This value may be null.

onDownloadMms

Added in API level 22
public void onDownloadMms (Uri contentUri, 
                int subId, 
                Uri location, 
                ResultCallback<Integer> callback)

Override this method to download MMSs received.

Parameters
contentUri Uri: the content provider URI of the PDU to be downloaded. This value cannot be null.

subId int: SMS subscription ID of the SIM

location Uri: the URI of the message to be downloaded. This value cannot be null.

callback ResultCallback: result callback. Call with a status code which is one of DOWNLOAD_STATUS_OK, DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK, or DOWNLOAD_STATUS_ERROR. This value cannot be null.

onFilterSms

Added in API level 22
Deprecated in API level 24
public void onFilterSms (MessagePdu pdu, 
                String format, 
                int destPort, 
                int subId, 
                ResultCallback<Boolean> callback)

This method was deprecated in API level 24.
Use onReceiveTextSms(MessagePdu, String, int, int, ResultCallback) instead.

Override this method to filter inbound SMS messages.

Parameters
pdu MessagePdu: the PDUs of the message This value cannot be null.

format String: the format of the PDUs, typically "3gpp" or "3gpp2" This value cannot be null.

destPort int: the destination port of a binary SMS, this will be -1 for text SMS

subId int: SMS subscription ID of the SIM

callback ResultCallback: result callback. Call with true to keep an inbound SMS message and deliver to SMS apps, and false to drop the message. This value cannot be null.

onReceiveTextSms

Added in API level 24
public void onReceiveTextSms (MessagePdu pdu, 
                String format, 
                int destPort, 
                int subId, 
                ResultCallback<Integer> callback)

Override this method to filter inbound SMS messages.

This method will be called once for every incoming text SMS. You can invoke the callback with a bitmask to tell the platform how to handle the SMS. For a SMS received on a file-based encryption capable device while the credential-encrypted storage is not available, this method will be called for the second time when the credential-encrypted storage becomes available after the user unlocks the phone, if the bit RECEIVE_OPTIONS_DROP is not set when invoking the callback.

Parameters
pdu MessagePdu: the PDUs of the message This value cannot be null.

format String: the format of the PDUs, typically "3gpp" or "3gpp2" This value cannot be null.

destPort int: the destination port of a binary SMS, this will be -1 for text SMS

subId int: SMS subscription ID of the SIM

callback ResultCallback: result callback. Call with a bitmask integer to indicate how the incoming text SMS should be handled by the platform. Use RECEIVE_OPTIONS_DROP and RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE to set the flags in the bitmask. This value cannot be null.

onSendDataSms

Added in API level 22
Deprecated in API level 23
public void onSendDataSms (byte[] data, 
                int subId, 
                String destAddress, 
                int destPort, 
                ResultCallback<CarrierMessagingService.SendSmsResult> callback)

This method was deprecated in API level 23.
Override onSendDataSms(byte, int, String, int, ResultCallback) below instead.

Override this method to intercept binary SMSs sent from the device.

Parameters
data byte: the binary content This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

destPort int: the destination port

callback ResultCallback: result callback. Call with a SendSmsResult. This value cannot be null.

onSendDataSms

Added in API level 23
public void onSendDataSms (byte[] data, 
                int subId, 
                String destAddress, 
                int destPort, 
                int sendSmsFlag, 
                ResultCallback<CarrierMessagingService.SendSmsResult> callback)

Override this method to intercept binary SMSs sent from the device.

Parameters
data byte: the binary content This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

destPort int: the destination port

sendSmsFlag int: Flag for sending SMS. Acceptable values are 0 and SEND_FLAG_REQUEST_DELIVERY_STATUS.

callback ResultCallback: result callback. Call with a SendSmsResult. This value cannot be null.

onSendMms

Added in API level 22
public void onSendMms (Uri pduUri, 
                int subId, 
                Uri location, 
                ResultCallback<CarrierMessagingService.SendMmsResult> callback)

Override this method to intercept MMSs sent from the device.

Parameters
pduUri Uri: the content provider URI of the PDU to send This value cannot be null.

subId int: SMS subscription ID of the SIM

location Uri: the optional URI to send this MMS PDU. If this is {code null}, the PDU should be sent to the default MMSC URL.

callback ResultCallback: result callback. Call with a SendMmsResult. This value cannot be null.

onSendMultipartTextSms

Added in API level 22
Deprecated in API level 23
public void onSendMultipartTextSms (List<String> parts, 
                int subId, 
                String destAddress, 
                ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)

This method was deprecated in API level 23.
Override onSendMultipartTextSms(List, int, String, ResultCallback) below instead.

Override this method to intercept long SMSs sent from the device.

Parameters
parts List: a List of the message parts This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

callback ResultCallback: result callback. Call with a SendMultipartSmsResult. This value cannot be null.

onSendMultipartTextSms

Added in API level 23
public void onSendMultipartTextSms (List<String> parts, 
                int subId, 
                String destAddress, 
                int sendSmsFlag, 
                ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)

Override this method to intercept long SMSs sent from the device.

Parameters
parts List: a List of the message parts This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

sendSmsFlag int: Flag for sending SMS. Acceptable values are 0 and SEND_FLAG_REQUEST_DELIVERY_STATUS.

callback ResultCallback: result callback. Call with a SendMultipartSmsResult. This value cannot be null.

onSendTextSms

Added in API level 23
public void onSendTextSms (String text, 
                int subId, 
                String destAddress, 
                int sendSmsFlag, 
                ResultCallback<CarrierMessagingService.SendSmsResult> callback)

Override this method to intercept text SMSs sent from the device.

Parameters
text String: the text to send This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

sendSmsFlag int: Flag for sending SMS. Acceptable values are 0 and SEND_FLAG_REQUEST_DELIVERY_STATUS.

callback ResultCallback: result callback. Call with a SendSmsResult. This value cannot be null.

onSendTextSms

Added in API level 22
Deprecated in API level 23
public void onSendTextSms (String text, 
                int subId, 
                String destAddress, 
                ResultCallback<CarrierMessagingService.SendSmsResult> callback)

This method was deprecated in API level 23.
Override onSendTextSms(String, int, String, ResultCallback) below instead.

Override this method to intercept text SMSs sent from the device.

Parameters
text String: the text to send This value cannot be null.

subId int: SMS subscription ID of the SIM

destAddress String: phone number of the recipient of the message This value cannot be null.

callback ResultCallback: result callback. Call with a SendSmsResult. This value cannot be null.