public abstract class CarrierMessagingService
extends Service
| java.lang.Object | ||||
| android.content.Context | ||||
| android.content.ContextWrapper | ||||
| android.app.Service | ||||
| android.service.carrier.CarrierMessagingService | ||||
发送或接收新SMS和MMS时接收系统呼叫的服务。
要扩展此类,您必须在清单文件中声明服务并使用BIND_CARRIER_SERVICES权限,并包含一个包含SERVICE_INTERFACE操作的意向过滤器。 例如:
<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>
Nested classes |
|
|---|---|
interface |
CarrierMessagingService.ResultCallback<T> 用于异步提供结果的回调接口。 |
class |
CarrierMessagingService.SendMmsResult 发送彩信的结果。 |
class |
CarrierMessagingService.SendMultipartSmsResult 发送多部分SMS的结果。 |
class |
CarrierMessagingService.SendSmsResult 发送短信的结果。 |
常量(Constants) |
|
|---|---|
int |
DOWNLOAD_STATUS_ERROR 彩信下载失败。 |
int |
DOWNLOAD_STATUS_OK 成功下载彩信。 |
int |
DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK 彩信下载失败。 |
int |
RECEIVE_OPTIONS_DEFAULT 传递给回调 |
int |
RECEIVE_OPTIONS_DROP 用于设置传递给回调 |
int |
RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE 用于设置传递给 |
int |
SEND_FLAG_REQUEST_DELIVERY_STATUS 标记以请求SMS传递状态报告。 |
int |
SEND_STATUS_ERROR 短信/彩信发送失败。 |
int |
SEND_STATUS_OK 表示SMS或MMS消息已成功发送。 |
int |
SEND_STATUS_RETRY_ON_CARRIER_NETWORK 短信/彩信发送失败。 |
String |
SERVICE_INTERFACE
|
Inherited constants |
|---|
android.app.Service
|
android.content.Context
|
android.content.ComponentCallbacks2
|
Public constructors |
|
|---|---|
CarrierMessagingService() |
|
继承方法(Inherited methods) |
|
|---|---|
android.app.Service
|
|
android.content.ContextWrapper
|
|
android.content.Context
|
|
java.lang.Object
|
|
android.content.ComponentCallbacks2
|
|
android.content.ComponentCallbacks
|
|
int DOWNLOAD_STATUS_ERROR
彩信下载失败。 我们不应该通过运营商网络重试。
常量值:2(0x00000002)
int DOWNLOAD_STATUS_RETRY_ON_CARRIER_NETWORK
彩信下载失败。 我们应该通过运营商网络重试。
常数值:1(0x00000001)
int RECEIVE_OPTIONS_DEFAULT
传递给 onReceiveTextSms(MessagePdu, String, int, int, CarrierMessagingService.ResultCallback
回调的默认位掩码值(全部为 RECEIVE_OPTIONS_x标志)将被清除,以指示应保留该消息并应显示新的消息通知。
也可以看看:
常量值:0(0x00000000)
int RECEIVE_OPTIONS_DROP
用于设置传递给回调 onReceiveTextSms(MessagePdu, String, int, int, CarrierMessagingService.ResultCallback
的位掩码中的标志,以指示应丢弃入站SMS。
常数值:1(0x00000001)
int RECEIVE_OPTIONS_SKIP_NOTIFY_WHEN_CREDENTIAL_PROTECTED_STORAGE_UNAVAILABLE
用于设置传递给onReceiveTextSms(MessagePdu, String, int, int, CarrierMessagingService.ResultCallback
回调的位掩码中的标志,以指示在用户解锁手机之前设备的凭证加密存储不可用时,不应向用户显示新消息通知。 它仅适用于支持基于文件的加密的设备。
常量值:2(0x00000002)
int SEND_FLAG_REQUEST_DELIVERY_STATUS
标记以请求SMS传递状态报告。
常数值:1(0x00000001)
int SEND_STATUS_ERROR
短信/彩信发送失败。 我们不应该通过运营商网络重试。
常量值:2(0x00000002)
int SEND_STATUS_RETRY_ON_CARRIER_NETWORK
短信/彩信发送失败。 我们应该通过运营商网络重试。
常数值:1(0x00000001)
String SERVICE_INTERFACE
Intent必须声明为由服务处理。
常量值:“android.service.carrier.CarrierMessagingService”
IBinder onBind (Intent intent)
将通信信道返回给服务。 如果客户端无法绑定到服务,可能会返回null。 返回IBinder通常是一个复杂的界面已经described using aidl 。
请注意,与其他应用程序组件不同,此处返回的IBinder接口调用可能不会发生在进程的主线程上 。 有关主线程的更多信息可以在Processes and Threads中找到。
| 参数(Parameters) | |
|---|---|
intent |
Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here. |
| 返回(Returns) | |
|---|---|
IBinder |
Return an IBinder through which clients can call on to the service. |
void onDownloadMms (Uri contentUri, int subId, Uri location, ResultCallback<Integer> callback)
重写此方法以下载收到的MMS。
| 参数(Parameters) | |
|---|---|
contentUri |
Uri: the content provider URI of the PDU to be downloaded. |
subId |
int: SMS subscription ID of the SIM |
location |
Uri: the URI of the message to be downloaded. |
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. |
void onFilterSms (MessagePdu pdu, String format, int destPort, int subId, ResultCallback<Boolean> callback)
此方法在API级别24中已弃用。
改为使用onReceiveTextSms(MessagePdu, String, int, int, CarrierMessagingService.ResultCallback
。
重写此方法以过滤入站SMS消息。
| 参数(Parameters) | |
|---|---|
pdu |
MessagePdu: the PDUs of the message |
format |
String: the format of the PDUs, typically "3gpp" or "3gpp2" |
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. |
void onReceiveTextSms (MessagePdu pdu, String format, int destPort, int subId, ResultCallback<Integer> callback)
重写此方法以过滤入站SMS消息。
对于每个传入的文本SMS,此方法将被调用一次。 您可以使用位掩码调用回调函数以告知平台如何处理SMS。 对于凭证加密存储不可用时在基于文件的可加密存储设备上接收的SMS,将在用户解锁手机后凭证加密存储变为可用时再次调用此方法(如果位RECEIVE_OPTIONS_DROP在调用回调时未设置。
| 参数(Parameters) | |
|---|---|
pdu |
MessagePdu: the PDUs of the message |
format |
String: the format of the PDUs, typically "3gpp" or "3gpp2" |
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. |
void onSendDataSms (byte[] data,
int subId,
String destAddress,
int destPort,
ResultCallback<CarrierMessagingService.SendSmsResult> callback)
此方法在API级别23中已弃用。
onSendDataSms(byte[], int, String, int, CarrierMessagingService.ResultCallback
在下面覆盖onSendDataSms(byte[], int, String, int, CarrierMessagingService.ResultCallback
。
重写此方法以拦截从设备发送的二进制SMS。
| 参数(Parameters) | |
|---|---|
data |
byte: the binary content |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
destPort |
int: the destination port |
callback |
ResultCallback: result callback. Call with a CarrierMessagingService.SendSmsResult. |
void onSendDataSms (byte[] data,
int subId,
String destAddress,
int destPort,
int sendSmsFlag,
ResultCallback<CarrierMessagingService.SendSmsResult> callback)
重写此方法以拦截从设备发送的二进制SMS。
| 参数(Parameters) | |
|---|---|
data |
byte: the binary content |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
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 CarrierMessagingService.SendSmsResult. |
void onSendMms (Uri pduUri, int subId, Uri location, ResultCallback<CarrierMessagingService.SendMmsResult> callback)
重写此方法以拦截从设备发送的MMS。
| 参数(Parameters) | |
|---|---|
pduUri |
Uri: the content provider URI of the PDU to send |
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 CarrierMessagingService.SendMmsResult. |
void onSendMultipartTextSms (List<String> parts, int subId, String destAddress, ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)
此方法在API级别23中已弃用。
onSendMultipartTextSms(List
在下面覆盖onSendMultipartTextSms(List
。
重写此方法以拦截从设备发送的长期SMS。
| 参数(Parameters) | |
|---|---|
parts |
List: a List of the message parts |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
callback |
ResultCallback: result callback. Call with a CarrierMessagingService.SendMultipartSmsResult. |
void onSendMultipartTextSms (List<String> parts, int subId, String destAddress, int sendSmsFlag, ResultCallback<CarrierMessagingService.SendMultipartSmsResult> callback)
重写此方法以拦截从设备发送的长期SMS。
| 参数(Parameters) | |
|---|---|
parts |
List: a List of the message parts |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
sendSmsFlag |
int: Flag for sending SMS. Acceptable values are 0 and SEND_FLAG_REQUEST_DELIVERY_STATUS. |
callback |
ResultCallback: result callback. Call with a CarrierMessagingService.SendMultipartSmsResult. |
void onSendTextSms (String text, int subId, String destAddress, int sendSmsFlag, ResultCallback<CarrierMessagingService.SendSmsResult> callback)
重写此方法以拦截从设备发送的文本SMS。
| 参数(Parameters) | |
|---|---|
text |
String: the text to send |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
sendSmsFlag |
int: Flag for sending SMS. Acceptable values are 0 and SEND_FLAG_REQUEST_DELIVERY_STATUS. |
callback |
ResultCallback: result callback. Call with a CarrierMessagingService.SendSmsResult. |
void onSendTextSms (String text, int subId, String destAddress, ResultCallback<CarrierMessagingService.SendSmsResult> callback)
此方法在API级别23中已弃用。
onSendTextSms(String, int, String, CarrierMessagingService.ResultCallback
在下面覆盖onSendTextSms(String, int, String, CarrierMessagingService.ResultCallback
。
重写此方法以拦截从设备发送的文本SMS。
| 参数(Parameters) | |
|---|---|
text |
String: the text to send |
subId |
int: SMS subscription ID of the SIM |
destAddress |
String: phone number of the recipient of the message |
callback |
ResultCallback: result callback. Call with a CarrierMessagingService.SendSmsResult. |