1

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
    How do you know that the default messaging app receives the entire message at once? I would guess it receives them separately and then combines them internally. – slayton Apr 05 '12 at 17:13
  • @slayton Thanks. So I think I can compare datetime and combine all parts into one. Do you think that there is a flag somewhere -- which indicates that this message is a piece of a large message? –  Apr 05 '12 at 17:29
  • I don't know but you can always look at the Android sources and see how they do it. – slayton Apr 05 '12 at 17:31

1 Answers1

3

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.

  • Please check the answer here http://stackoverflow.com/questions/7469881/broadcastreceiver-for-multipart-sms Each intent contains a single message including all its parts together. It is easy – M.Hefny Sep 06 '15 at 04:06