我想攔截Rich Communication消息(在沃達豐等網絡上稱爲「聊天」)。我已經成功地實現了一個使用意圖過濾器和廣播接收器的短信接收器,這非常棒。但是,如果SMS是豐富的通信消息,則接收方將永遠不會被呼叫。如何在Android上攔截豐富的通信消息
在我的清單:
<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不同,但它在沃達豐的三星手機上的相同默認消息應用程序中處理。我不知道但我假設它不是三星專用功能。你可以看到有些消息在泡泡中有「SMS」,有些則有「聊天」。 Android開發人員文檔中沒有任何內容,因此我懷疑它將成爲供應商特定的意圖,可能只適用於特定設備,但我仍然想知道它們是什麼。我只感興趣的是檢測發件人的詳細信息,所以我不需要更多涉及的代碼來完全解釋郵件。 –