Listen to incoming multipart SMS message

2019-05-29 19:10发布

I can catch newly incoming SMS messages. But if that is a multipart message, my broadcast receiver receives all parts of the message at several times.

Is there a way to receive the whole message at one time - like default messaging app does?

1条回答
唯我独甜
2楼-- · 2019-05-29 19:39

Holy...!

After reading the Android source (this file), I realize that this is such a stupid question...

Here is my receiver:

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(ClassName, "received SMS");

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        // here is what I need, just combine them all  :-)
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        Log.d(ClassName, String.format("message count = %s", messages.length));
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        }
    }
}// onReceive()

Oops... I was too lazy to look at my code. I already got all parts of the message at a time.

查看更多
登录 后发表回答