【发布时间】:2016-04-30 10:33:22
【问题描述】:
我想截获 Rich Communication 消息(在 Vodafone 等某些网络上称为 Chat)。我已经使用意图过滤器和广播接收器成功地实现了一个 SMS 接收器,效果很好。但是,如果 SMS 是富通信消息,则接收者永远不会被调用。
在我的清单中:
<receiver
android:name=".IncomingSMS"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
我的广播接收器看起来像这样:
public class IncomingSMS extends WakefulBroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
if (bundle != null)
{
final Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage currentMessage;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
String format = bundle.getString("format");
currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[0], format);
}
else
{
//noinspection deprecation
currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[0]);
}
String number = currentMessage.getDisplayOriginatingAddress();
Intent serviceintent = new Intent(context, ChargingMonitorService.class);
serviceintent.putExtra(NUMBER, number);
startWakefulService(context, serviceintent);
} // bundle is null
}
}
这一切都很完美,除非文本消息是富通信(或聊天)消息,否则永远不会调用 onReceive()。
Android 文档中没有任何内容,所以我假设它是供应商特定的意图,但它是什么?
【问题讨论】:
-
RCS 确实与 SMS 没有任何关系,因此您的 Receiver 永远不会为这些而开火。您可以查看几个适用于 Android 的开源 RCS 实现,但它比处理简单的文本消息要复杂得多。
-
虽然 RCS 与 SMS 不同,但它在 Vodafone 上的三星手机上的相同默认消息应用程序中处理。我不知道,但我假设它不是三星独有的功能。您可以在气泡中看到一些消息带有“SMS”,而有些消息带有“Chat”。 Android 开发人员文档中没有任何内容,因此我怀疑这将是供应商特定的意图,可能仅适用于特定设备,但我仍然想知道它们是什么。我只对检测发件人详细信息感兴趣,因此我不需要更多涉及的代码来完全解释消息。
标签: android broadcastreceiver sms chat intentfilter