public
final
class
SmsManager
extends Object
java.lang.Object | |
↳ | android.telephony.SmsManager |
Manages SMS operations such as sending data, text, and pdu SMS messages.
Get this object by calling the static method getDefault()
.
For information about how to behave as the default SMS app on Android 4.4 (API level 19)
and higher, see Telephony
.
Constants | |
---|---|
String |
EXTRA_MMS_DATA
Intent extra name for MMS sending result data in byte array type |
String |
EXTRA_MMS_HTTP_STATUS
Intent extra name for HTTP status code for MMS HTTP failure in integer type |
String |
MMS_CONFIG_ALIAS_ENABLED
Whether alias is enabled (boolean type) |
String |
MMS_CONFIG_ALIAS_MAX_CHARS
Max alias character count (int type) |
String |
MMS_CONFIG_ALIAS_MIN_CHARS
Min alias character count (int type) |
String |
MMS_CONFIG_ALLOW_ATTACH_AUDIO
Whether audio is allowed to be attached for MMS messages (boolean type) |
String |
MMS_CONFIG_APPEND_TRANSACTION_ID
Whether to append transaction id to MMS WAP Push M-Notification.ind's content location URI when constructing the download URL of a new MMS (boolean type) |
String |
MMS_CONFIG_EMAIL_GATEWAY_NUMBER
Email gateway number (String type) |
String |
MMS_CONFIG_GROUP_MMS_ENABLED
Whether group MMS is enabled for the current carrier (boolean type) |
String |
MMS_CONFIG_HTTP_PARAMS
A list of HTTP headers to add to MMS HTTP request, separated by "|" (String type) |
String |
MMS_CONFIG_HTTP_SOCKET_TIMEOUT
MMS HTTP socket timeout in milliseconds (int type) |
String |
MMS_CONFIG_MAX_IMAGE_HEIGHT
Max MMS image height (int type) |
String |
MMS_CONFIG_MAX_IMAGE_WIDTH
Max MMS image width (int type) |
String |
MMS_CONFIG_MAX_MESSAGE_SIZE
Max MMS message size in bytes (int type) |
String |
MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE
Max message text size (int type) |
String |
MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED
Whether MMS delivery report is enabled (boolean type) |
String |
MMS_CONFIG_MMS_ENABLED
Whether MMS is enabled for the current carrier (boolean type) |
String |
MMS_CONFIG_MMS_READ_REPORT_ENABLED
Whether MMS read report is enabled (boolean type) |
String |
MMS_CONFIG_MULTIPART_SMS_ENABLED
Whether multipart SMS is enabled (boolean type) |
String |
MMS_CONFIG_NAI_SUFFIX
The suffix to append to the NAI header value for MMS HTTP request (String type) |
String |
MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED
If this is enabled, M-NotifyResp.ind should be sent to the WAP Push content location instead of the default MMSC (boolean type) |
String |
MMS_CONFIG_RECIPIENT_LIMIT
Limit of recipients of MMS messages (int type) |
String |
MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES
Whether multipart SMS should be sent as separate messages |
String |
MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS
If true, show the cell broadcast (amber alert) in the SMS settings. |
String |
MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED
Whether SMS delivery report is enabled (boolean type) |
String |
MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD
Some carriers require SMS to be converted into MMS when text length reaches this threshold (int type) |
String |
MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD
When the number of parts of a multipart SMS reaches this threshold, it should be converted into an MMS (int type) |
String |
MMS_CONFIG_SUBJECT_MAX_LENGTH
Max message subject length (int type) |
String |
MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER
Whether the carrier MMSC supports charset field in Content-Type header. |
String |
MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION
Whether content-disposition field should be expected in an MMS PDU (boolean type) |
String |
MMS_CONFIG_UA_PROF_TAG_NAME
The name of the UA Prof URL HTTP header for MMS HTTP request (String type) |
String |
MMS_CONFIG_UA_PROF_URL
The UA Profile URL header value for MMS HTTP request (String type) |
String |
MMS_CONFIG_USER_AGENT
The User-Agent header value for MMS HTTP request (String type) |
int |
MMS_ERROR_CONFIGURATION_ERROR
|
int |
MMS_ERROR_HTTP_FAILURE
|
int |
MMS_ERROR_INVALID_APN
|
int |
MMS_ERROR_IO_ERROR
|
int |
MMS_ERROR_NO_DATA_NETWORK
|
int |
MMS_ERROR_RETRY
|
int |
MMS_ERROR_UNABLE_CONNECT_MMS
|
int |
MMS_ERROR_UNSPECIFIED
|
int |
RESULT_ERROR_GENERIC_FAILURE
Generic failure cause |
int |
RESULT_ERROR_NO_SERVICE
Failed because service is currently unavailable |
int |
RESULT_ERROR_NULL_PDU
Failed because no pdu provided |
int |
RESULT_ERROR_RADIO_OFF
Failed because radio was explicitly turned off |
int |
STATUS_ON_ICC_FREE
Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). |
int |
STATUS_ON_ICC_READ
Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). |
int |
STATUS_ON_ICC_SENT
Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). |
int |
STATUS_ON_ICC_UNREAD
Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). |
int |
STATUS_ON_ICC_UNSENT
Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27). |
Public methods | |
---|---|
ArrayList<String>
|
divideMessage(String text)
Divide a message text into several fragments, none bigger than the maximum SMS message size. |
void
|
downloadMultimediaMessage(Context context, String locationUrl, Uri contentUri, Bundle configOverrides, PendingIntent downloadedIntent)
Download an MMS message from carrier by a given location URL |
Bundle
|
getCarrierConfigValues()
Get carrier-dependent configuration values. |
static
SmsManager
|
getDefault()
Get the SmsManager associated with the default subscription id. |
static
int
|
getDefaultSmsSubscriptionId()
Get default sms subscription id |
static
SmsManager
|
getSmsManagerForSubscriptionId(int subId)
Get the the instance of the SmsManager associated with a particular subscription id |
int
|
getSubscriptionId()
Get the associated subscription id. |
void
|
injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent)
Inject an SMS PDU into the android application framework. |
void
|
sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a data based SMS to a specific application port. |
void
|
sendMultimediaMessage(Context context, Uri contentUri, String locationUrl, Bundle configOverrides, PendingIntent sentIntent)
Send an MMS message |
void
|
sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)
Send a multi-part text based SMS. |
void
|
sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a text based SMS. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
String EXTRA_MMS_DATA
Intent extra name for MMS sending result data in byte array type
Constant Value: "android.telephony.extra.MMS_DATA"
String EXTRA_MMS_HTTP_STATUS
Intent extra name for HTTP status code for MMS HTTP failure in integer type
Constant Value: "android.telephony.extra.MMS_HTTP_STATUS"
String MMS_CONFIG_ALIAS_ENABLED
Whether alias is enabled (boolean type)
Constant Value: "aliasEnabled"
String MMS_CONFIG_ALIAS_MAX_CHARS
Max alias character count (int type)
Constant Value: "aliasMaxChars"
String MMS_CONFIG_ALIAS_MIN_CHARS
Min alias character count (int type)
Constant Value: "aliasMinChars"
String MMS_CONFIG_ALLOW_ATTACH_AUDIO
Whether audio is allowed to be attached for MMS messages (boolean type)
Constant Value: "allowAttachAudio"
String MMS_CONFIG_APPEND_TRANSACTION_ID
Whether to append transaction id to MMS WAP Push M-Notification.ind's content location URI when constructing the download URL of a new MMS (boolean type)
Constant Value: "enabledTransID"
String MMS_CONFIG_EMAIL_GATEWAY_NUMBER
Email gateway number (String type)
Constant Value: "emailGatewayNumber"
String MMS_CONFIG_GROUP_MMS_ENABLED
Whether group MMS is enabled for the current carrier (boolean type)
Constant Value: "enableGroupMms"
String MMS_CONFIG_HTTP_PARAMS
A list of HTTP headers to add to MMS HTTP request, separated by "|" (String type)
Constant Value: "httpParams"
String MMS_CONFIG_HTTP_SOCKET_TIMEOUT
MMS HTTP socket timeout in milliseconds (int type)
Constant Value: "httpSocketTimeout"
String MMS_CONFIG_MAX_IMAGE_HEIGHT
Max MMS image height (int type)
Constant Value: "maxImageHeight"
String MMS_CONFIG_MAX_IMAGE_WIDTH
Max MMS image width (int type)
Constant Value: "maxImageWidth"
String MMS_CONFIG_MAX_MESSAGE_SIZE
Max MMS message size in bytes (int type)
Constant Value: "maxMessageSize"
String MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE
Max message text size (int type)
Constant Value: "maxMessageTextSize"
String MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED
Whether MMS delivery report is enabled (boolean type)
Constant Value: "enableMMSDeliveryReports"
String MMS_CONFIG_MMS_ENABLED
Whether MMS is enabled for the current carrier (boolean type)
Constant Value: "enabledMMS"
String MMS_CONFIG_MMS_READ_REPORT_ENABLED
Whether MMS read report is enabled (boolean type)
Constant Value: "enableMMSReadReports"
String MMS_CONFIG_MULTIPART_SMS_ENABLED
Whether multipart SMS is enabled (boolean type)
Constant Value: "enableMultipartSMS"
String MMS_CONFIG_NAI_SUFFIX
The suffix to append to the NAI header value for MMS HTTP request (String type)
Constant Value: "naiSuffix"
String MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED
If this is enabled, M-NotifyResp.ind should be sent to the WAP Push content location instead of the default MMSC (boolean type)
Constant Value: "enabledNotifyWapMMSC"
String MMS_CONFIG_RECIPIENT_LIMIT
Limit of recipients of MMS messages (int type)
Constant Value: "recipientLimit"
String MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES
Whether multipart SMS should be sent as separate messages
Constant Value: "sendMultipartSmsAsSeparateMessages"
String MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS
If true, show the cell broadcast (amber alert) in the SMS settings. Some carriers don't want this shown. (Boolean type)
Constant Value: "config_cellBroadcastAppLinks"
String MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED
Whether SMS delivery report is enabled (boolean type)
Constant Value: "enableSMSDeliveryReports"
String MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD
Some carriers require SMS to be converted into MMS when text length reaches this threshold (int type)
Constant Value: "smsToMmsTextLengthThreshold"
String MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD
When the number of parts of a multipart SMS reaches this threshold, it should be converted into an MMS (int type)
Constant Value: "smsToMmsTextThreshold"
String MMS_CONFIG_SUBJECT_MAX_LENGTH
Max message subject length (int type)
Constant Value: "maxSubjectLength"
String MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER
Whether the carrier MMSC supports charset field in Content-Type header. If this is false, then we don't add "charset" to "Content-Type"
Constant Value: "supportHttpCharsetHeader"
String MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION
Whether content-disposition field should be expected in an MMS PDU (boolean type)
Constant Value: "supportMmsContentDisposition"
String MMS_CONFIG_UA_PROF_TAG_NAME
The name of the UA Prof URL HTTP header for MMS HTTP request (String type)
Constant Value: "uaProfTagName"
String MMS_CONFIG_UA_PROF_URL
The UA Profile URL header value for MMS HTTP request (String type)
Constant Value: "uaProfUrl"
String MMS_CONFIG_USER_AGENT
The User-Agent header value for MMS HTTP request (String type)
Constant Value: "userAgent"
int MMS_ERROR_CONFIGURATION_ERROR
Constant Value: 7 (0x00000007)
int MMS_ERROR_HTTP_FAILURE
Constant Value: 4 (0x00000004)
int MMS_ERROR_INVALID_APN
Constant Value: 2 (0x00000002)
int MMS_ERROR_NO_DATA_NETWORK
Constant Value: 8 (0x00000008)
int MMS_ERROR_UNABLE_CONNECT_MMS
Constant Value: 3 (0x00000003)
int MMS_ERROR_UNSPECIFIED
Constant Value: 1 (0x00000001)
int RESULT_ERROR_GENERIC_FAILURE
Generic failure cause
Constant Value: 1 (0x00000001)
int RESULT_ERROR_NO_SERVICE
Failed because service is currently unavailable
Constant Value: 4 (0x00000004)
int RESULT_ERROR_NULL_PDU
Failed because no pdu provided
Constant Value: 3 (0x00000003)
int RESULT_ERROR_RADIO_OFF
Failed because radio was explicitly turned off
Constant Value: 2 (0x00000002)
int STATUS_ON_ICC_FREE
Free space (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27).
Constant Value: 0 (0x00000000)
int STATUS_ON_ICC_READ
Received and read (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27).
Constant Value: 1 (0x00000001)
int STATUS_ON_ICC_SENT
Stored and sent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27).
Constant Value: 5 (0x00000005)
int STATUS_ON_ICC_UNREAD
Received and unread (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27).
Constant Value: 3 (0x00000003)
int STATUS_ON_ICC_UNSENT
Stored and unsent (TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27).
Constant Value: 7 (0x00000007)
ArrayList<String> divideMessage (String text)
Divide a message text into several fragments, none bigger than the maximum SMS message size.
Parameters | |
---|---|
text |
String :
the original message. Must not be null. |
Returns | |
---|---|
ArrayList<String> |
an ArrayList of strings that, in order,
comprise the original message |
Throws | |
---|---|
IllegalArgumentException |
if text is null |
void downloadMultimediaMessage (Context context, String locationUrl, Uri contentUri, Bundle configOverrides, PendingIntent downloadedIntent)
Download an MMS message from carrier by a given location URL
Parameters | |
---|---|
context |
Context :
application context |
locationUrl |
String :
the location URL of the MMS message to be downloaded, usually obtained
from the MMS WAP push notification |
contentUri |
Uri :
the content uri to which the downloaded pdu will be written |
configOverrides |
Bundle :
the carrier-specific messaging configuration values to override for
downloading the message. |
downloadedIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is downloaded, or the download is failed |
Throws | |
---|---|
IllegalArgumentException |
if locationUrl or contentUri is empty |
Bundle getCarrierConfigValues ()
Get carrier-dependent configuration values.
Returns | |
---|---|
Bundle |
bundle key/values pairs of configuration values |
SmsManager getDefault ()
Get the SmsManager associated with the default subscription id. The instance will always be associated with the default subscription id, even if the default subscription id is changed.
Returns | |
---|---|
SmsManager |
the SmsManager associated with the default subscription id |
int getDefaultSmsSubscriptionId ()
Get default sms subscription id
Returns | |
---|---|
int |
the default SMS subscription id |
SmsManager getSmsManagerForSubscriptionId (int subId)
Get the the instance of the SmsManager associated with a particular subscription id
Parameters | |
---|---|
subId |
int :
an SMS subscription id, typically accessed using
SubscriptionManager |
Returns | |
---|---|
SmsManager |
the instance of the SmsManager associated with subId |
int getSubscriptionId ()
Get the associated subscription id. If the instance was returned by getDefault()
,
then this method may return different values at different points in time (if the user
changes the default subscription id). It will return < 0 if the default subscription id
cannot be determined.
Additionally, to support legacy applications that are not multi-SIM aware,
if the following are true:
- We are using a multi-SIM device
- A default SMS SIM has not been selected
- At least one SIM subscription is available
then ask the user to set the default SMS SIM.
Returns | |
---|---|
int |
associated subscription id |
void injectSmsPdu (byte[] pdu, String format, PendingIntent receivedIntent)
Inject an SMS PDU into the android application framework. The caller should have carrier privileges.
Parameters | |
---|---|
pdu |
byte :
is the byte array of pdu to be injected into android application framework |
format |
String :
is the format of SMS pdu (3gpp or 3gpp2) |
receivedIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is successfully received by the
android application framework, or failed. This intent is broadcasted at
the same time an SMS received from radio is acknowledged back.
The result code will be RESULT_SMS_HANDLED for success, or
RESULT_SMS_GENERIC_ERROR for error. |
Throws | |
---|---|
IllegalArgumentException |
if format is not one of 3gpp and 3gpp2. |
See also:
void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a data based SMS to a specific application port.
Note: Using this method requires that your app has the
SEND_SMS
permission.
Parameters | |
---|---|
destinationAddress |
String :
the address to send the message to |
scAddress |
String :
is the service center address or null to use
the current default SMSC |
destinationPort |
short :
the port to deliver the message to |
data |
byte :
the body of the message to send |
sentIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is successfully sent, or failed.
The result code will be Activity.RESULT_OK for success,
or one of these errors:RESULT_ERROR_GENERIC_FAILURE RESULT_ERROR_RADIO_OFF RESULT_ERROR_NULL_PDU For RESULT_ERROR_GENERIC_FAILURE the sentIntent may include
the extra "errorCode" containing a radio technology specific value,
generally only useful for troubleshooting.The per-application based SMS control checks sentIntent. If sentIntent is NULL the caller will be checked against all unknown applications, which cause smaller number of SMS to be sent in checking period. |
deliveryIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is delivered to the recipient. The
raw pdu of the status report is in the extended data ("pdu"). |
Throws | |
---|---|
IllegalArgumentException |
if destinationAddress or data are empty |
void sendMultimediaMessage (Context context, Uri contentUri, String locationUrl, Bundle configOverrides, PendingIntent sentIntent)
Send an MMS message
Parameters | |
---|---|
context |
Context :
application context |
contentUri |
Uri :
the content Uri from which the message pdu will be read |
locationUrl |
String :
the optional location url where message should be sent to |
configOverrides |
Bundle :
the carrier-specific messaging configuration values to override for
sending the message. |
sentIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is successfully sent, or failed |
Throws | |
---|---|
IllegalArgumentException |
if contentUri is empty |
void sendMultipartTextMessage (String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)
Send a multi-part text based SMS. The callee should have already
divided the message into correctly sized parts by calling
divideMessage
.
Note: Using this method requires that your app has the
SEND_SMS
permission.
Note: Beginning with Android 4.4 (API level 19), if
and only if an app is not selected as the default SMS app, the system automatically
writes messages sent using this method to the SMS Provider (the default SMS app is always
responsible for writing its sent messages to the SMS Provider). For information about
how to behave as the default SMS app, see Telephony
.
Parameters | |
---|---|
destinationAddress |
String :
the address to send the message to |
scAddress |
String :
is the service center address or null to use
the current default SMSC |
parts |
ArrayList :
an ArrayList of strings that, in order,
comprise the original message |
sentIntents |
ArrayList :
if not null, an ArrayList of
PendingIntent s (one for each message part) that is
broadcast when the corresponding message part has been sent.
The result code will be Activity.RESULT_OK for success,
or one of these errors:RESULT_ERROR_GENERIC_FAILURE RESULT_ERROR_RADIO_OFF RESULT_ERROR_NULL_PDU For RESULT_ERROR_GENERIC_FAILURE each sentIntent may include
the extra "errorCode" containing a radio technology specific value,
generally only useful for troubleshooting.The per-application based SMS control checks sentIntent. If sentIntent is NULL the caller will be checked against all unknown applications, which cause smaller number of SMS to be sent in checking period. |
deliveryIntents |
ArrayList :
if not null, an ArrayList of
PendingIntent s (one for each message part) that is
broadcast when the corresponding message part has been delivered
to the recipient. The raw pdu of the status report is in the
extended data ("pdu"). |
Throws | |
---|---|
IllegalArgumentException |
if destinationAddress or data are empty |
void sendTextMessage (String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
Send a text based SMS.
Note: Using this method requires that your app has the
SEND_SMS
permission.
Note: Beginning with Android 4.4 (API level 19), if
and only if an app is not selected as the default SMS app, the system automatically
writes messages sent using this method to the SMS Provider (the default SMS app is always
responsible for writing its sent messages to the SMS Provider). For information about
how to behave as the default SMS app, see Telephony
.
Parameters | |
---|---|
destinationAddress |
String :
the address to send the message to |
scAddress |
String :
is the service center address or null to use
the current default SMSC |
text |
String :
the body of the message to send |
sentIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is successfully sent, or failed.
The result code will be Activity.RESULT_OK for success,
or one of these errors:RESULT_ERROR_GENERIC_FAILURE RESULT_ERROR_RADIO_OFF RESULT_ERROR_NULL_PDU For RESULT_ERROR_GENERIC_FAILURE the sentIntent may include
the extra "errorCode" containing a radio technology specific value,
generally only useful for troubleshooting.The per-application based SMS control checks sentIntent. If sentIntent is NULL the caller will be checked against all unknown applications, which cause smaller number of SMS to be sent in checking period. |
deliveryIntent |
PendingIntent :
if not NULL this PendingIntent is
broadcast when the message is delivered to the recipient. The
raw pdu of the status report is in the extended data ("pdu"). |
Throws | |
---|---|
IllegalArgumentException |
if destinationAddress or text are empty |