public final class SmsManager
extends Object
java.lang.Object | |
↳ | android.telephony.SmsManager |
管理SMS操作,例如发送数据,文本和pdu SMS消息。 通过调用静态方法getDefault()
获取此对象。
有关如何在Android 4.4(API级别19)及更高级别上作为默认SMS应用程序的信息,请参阅 Telephony
。
Public methods |
|
---|---|
ArrayList<String> |
divideMessage(String text) 将消息文本分成几个片段,不能超过最大SMS消息大小。 |
void |
downloadMultimediaMessage(Context context, String locationUrl, Uri contentUri, Bundle configOverrides, PendingIntent downloadedIntent) 通过给定的位置URL从运营商下载MMS消息 |
Bundle |
getCarrierConfigValues() 获取与运营商相关的配置值。 |
static SmsManager |
getDefault() 获取与默认订阅ID关联的SmsManager。 |
static int |
getDefaultSmsSubscriptionId() 获取默认的短信订阅ID |
static SmsManager |
getSmsManagerForSubscriptionId(int subId) 获取与特定订阅ID关联的SmsManager实例 |
int |
getSubscriptionId() 获取关联的订阅ID。 |
void |
injectSmsPdu(byte[] pdu, String format, PendingIntent receivedIntent) 将一个SMS PDU注入到android应用程序框架中。 |
void |
sendDataMessage(String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) 将基于数据的SMS发送到特定的应用程序端口。 |
void |
sendMultimediaMessage(Context context, Uri contentUri, String locationUrl, Bundle configOverrides, PendingIntent sentIntent) 发送彩信 |
void |
sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) 发送基于短信的多部分文字。 |
void |
sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent) 发送基于文本的短信。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
String EXTRA_MMS_DATA
MMS以字节数组类型发送结果数据的意图额外名称
常量值:“android.telephony.extra.MMS_DATA”
String EXTRA_MMS_HTTP_STATUS
用于整数类型的MMS HTTP失败的HTTP状态码的意图额外名称
常量值:“android.telephony.extra.MMS_HTTP_STATUS”
String MMS_CONFIG_ALIAS_ENABLED
是否启用别名(布尔类型)
常量值:“aliasEnabled”
String MMS_CONFIG_ALIAS_MAX_CHARS
最大别名字符数(int类型)
常量值:“aliasMaxChars”
String MMS_CONFIG_ALIAS_MIN_CHARS
Min别名字符数(int类型)
常量值:“aliasMinChars”
String MMS_CONFIG_ALLOW_ATTACH_AUDIO
是否允许为MMS消息附加音频(布尔类型)
常量值:“allowAttachAudio”
String MMS_CONFIG_APPEND_TRANSACTION_ID
是否将事务ID附加到彩信WAP构建新MMS(布尔类型)的下载URL时推送M-Notification.ind的内容位置URI
常量值:“enabledTransID”
String MMS_CONFIG_EMAIL_GATEWAY_NUMBER
电子邮件网关号(字符串类型)
常量值:“emailGatewayNumber”
String MMS_CONFIG_GROUP_MMS_ENABLED
是否为当前运营商启用组MMS(布尔类型)
常量值:“enableGroupMms”
String MMS_CONFIG_HTTP_PARAMS
要添加到MMS HTTP请求的HTTP标头列表,用“|”分隔 (字符串类型)
常量值:“httpParams”
String MMS_CONFIG_HTTP_SOCKET_TIMEOUT
MMS HTTP套接字超时(毫秒)(int类型)
常量值:“httpSocketTimeout”
String MMS_CONFIG_MAX_IMAGE_HEIGHT
最大MMS图像高度(int类型)
常量值:“maxImageHeight”
String MMS_CONFIG_MAX_IMAGE_WIDTH
最大彩信图像宽度(int类型)
常量值:“maxImageWidth”
String MMS_CONFIG_MAX_MESSAGE_SIZE
以字节为单位的最大MMS消息大小(int类型)
常量值:“maxMessageSize”
String MMS_CONFIG_MESSAGE_TEXT_MAX_SIZE
最大消息文本大小(int类型)
常量值:“maxMessageTextSize”
String MMS_CONFIG_MMS_DELIVERY_REPORT_ENABLED
MMS传送报告是否启用(布尔类型)
常量值:“enableMMSDeliveryReports”
String MMS_CONFIG_MMS_ENABLED
MMS是否为当前运营商启用(布尔型)
常量值:“enabledMMS”
String MMS_CONFIG_MMS_READ_REPORT_ENABLED
是否启用MMS读取报告(布尔型)
常量值:“enableMMSReadReports”
String MMS_CONFIG_MULTIPART_SMS_ENABLED
是否启用多部分SMS(布尔类型)
常量值:“enableMultipartSMS”
String MMS_CONFIG_NAI_SUFFIX
附加到MMS HTTP请求的NAI标头值的后缀(字符串类型)
常数值:“naiSuffix”
String MMS_CONFIG_NOTIFY_WAP_MMSC_ENABLED
如果启用此选项,则应将M-NotifyResp.ind发送到WAP Push内容位置,而不是默认的MMSC(布尔类型)
常量值:“enabledNotifyWapMMSC”
String MMS_CONFIG_RECIPIENT_LIMIT
MMS消息接收者的限制(int类型)
常量值:“recipientLimit”
String MMS_CONFIG_SEND_MULTIPART_SMS_AS_SEPARATE_MESSAGES
多部分SMS是否应作为单独的消息发送
常量值:“sendMultipartSmsAsSeparateMessages”
String MMS_CONFIG_SHOW_CELL_BROADCAST_APP_LINKS
如果为true,则在短信设置中显示小区广播(琥珀色警报)。 有些运营商不希望显示这一点。 (布尔类型)
常量值:“config_cellBroadcastAppLinks”
String MMS_CONFIG_SMS_DELIVERY_REPORT_ENABLED
是否启用SMS传送报告(布尔类型)
常量值:“enableSMSDeliveryReports”
String MMS_CONFIG_SMS_TO_MMS_TEXT_LENGTH_THRESHOLD
当文本长度达到此阈值(int类型)时,某些运营商需要将SMS转换为MMS
常量值:“smsToMmsTextLengthThreshold”
String MMS_CONFIG_SMS_TO_MMS_TEXT_THRESHOLD
当多部分SMS的部分数量达到此阈值时,应将其转换为MMS(int类型)
常量值:“smsToMmsTextThreshold”
String MMS_CONFIG_SUBJECT_MAX_LENGTH
最大邮件主题长度(int类型)
常量值:“maxSubjectLength”
String MMS_CONFIG_SUPPORT_HTTP_CHARSET_HEADER
运营商MMSC是否支持Content-Type头中的字符集字段。 如果这是错误的,那么我们不会将“charset”添加到“Content-Type”
常量值:“supportHttpCharsetHeader”
String MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION
在MMS PDU(布尔类型)中是否应该预期内容处置字段
常量值:“supportMmsContentDisposition”
String MMS_CONFIG_UA_PROF_TAG_NAME
MMS HTTP请求的UA Prof URL HTTP标头的名称(字符串类型)
常量值:“uaProfTagName”
String MMS_CONFIG_UA_PROF_URL
MMS HTTP请求的UA配置文件URL标头值(字符串类型)
常数值:“uaProfUrl”
String MMS_CONFIG_USER_AGENT
MMS HTTP请求的User-Agent标头值(字符串类型)
常量值:“userAgent”
int MMS_ERROR_CONFIGURATION_ERROR
常量值:7(0x00000007)
int MMS_ERROR_NO_DATA_NETWORK
Constant Value: 8 (0x00000008)
int MMS_ERROR_UNABLE_CONNECT_MMS
常量值:3(0x00000003)
int RESULT_ERROR_GENERIC_FAILURE
通用故障原因
常数值:1(0x00000001)
int RESULT_ERROR_NO_SERVICE
因服务当前不可用而失败
常量值:4(0x00000004)
int RESULT_ERROR_RADIO_OFF
因无线电被明确关闭而失败
常量值:2(0x00000002)
int STATUS_ON_ICC_FREE
可用空间(TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27)。
常量值:0(0x00000000)
int STATUS_ON_ICC_READ
收到并阅读(TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27)。
常数值:1(0x00000001)
int STATUS_ON_ICC_SENT
存储和发送(TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27)。
常量值:5(0x00000005)
int STATUS_ON_ICC_UNREAD
已接收和未读(TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27)。
常量值:3(0x00000003)
int STATUS_ON_ICC_UNSENT
存储和未发送(TS 51.011 10.5.3 / 3GPP2 C.S0023 3.4.27)。
常量值:7(0x00000007)
ArrayList<String> divideMessage (String text)
将消息文本分成几个片段,不能超过最大SMS消息大小。
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)
通过给定的位置URL从运营商下载MMS消息
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 ()
获取与运营商相关的配置值。
Returns | |
---|---|
Bundle |
bundle key/values pairs of configuration values |
SmsManager getDefault ()
获取与默认订阅ID关联的SmsManager。 该实例将始终与默认订阅ID关联,即使默认订阅ID已更改。
Returns | |
---|---|
SmsManager |
the SmsManager associated with the default subscription id |
int getDefaultSmsSubscriptionId ()
获取默认的短信订阅ID
Returns | |
---|---|
int |
the default SMS subscription id |
SmsManager getSmsManagerForSubscriptionId (int subId)
获取与特定订阅ID关联的SmsManager实例
Parameters | |
---|---|
subId |
int : an SMS subscription id, typically accessed using SubscriptionManager |
Returns | |
---|---|
SmsManager |
the instance of the SmsManager associated with subId |
int getSubscriptionId ()
获取关联的订阅ID。 如果实例是由getDefault()
返回的,则此方法可能会在不同的时间点返回不同的值(如果用户更改默认订阅ID)。 如果无法确定默认订阅ID,它将返回<0。 此外,为了支持不支持多SIM的传统应用程序,如果满足以下条件: - 我们正在使用多SIM卡设备 - 尚未选择默认的SMS SIM卡 - 至少有一个SIM卡预订可用,然后询问用户设置默认的短信SIM卡。
Returns | |
---|---|
int |
associated subscription id |
void injectSmsPdu (byte[] pdu, String format, PendingIntent receivedIntent)
将一个SMS PDU注入到android应用程序框架中。 来电者应具有运营商权限。
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. |
也可以看看:
void sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent)
将基于数据的SMS发送到特定的应用程序端口。
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)
发送彩信
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)
发送基于短信的多部分文字。 被叫方应该已经通过调用divideMessage
将消息分成正确大小的部分。
注意:使用此方法要求您的应用具有 SEND_SMS
权限。
注意:从Android 4.4(API级别19)开始,当且仅当没有选择应用程序作为默认SMS应用程序时,系统会自动将使用此方法发送的消息写入SMS提供程序(默认的SMS应用程序始终负责撰写其发送的消息给SMS提供商)。 有关如何表现为默认SMS应用程序的信息,请参阅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_SMS
权限。
注意:从Android 4.4(API级别19)开始,当且仅当没有选择应用程序作为默认SMS应用程序时,系统会自动将使用此方法发送的消息写入SMS提供程序(默认的SMS应用程序始终负责撰写其发送的消息给SMS提供商)。 有关如何表现为默认SMS应用程序的信息,请参阅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 |