开发者

What's up with that array of SmsMessages I'm getting in my BroadcastReceiver in Android?

This is how my BroadcastReceiver looks like:

public class IncomingSMSListener extends BroadcastReceiver {
priv开发者_Go百科ate static final String SMS_EXTRA_NAME = "pdus";

@Override
public void onReceive(Context context, Intent intent) {
    SmsMessage[] messages = fetchSMSMessagesFromIntent(intent);

}

private SmsMessage[] fetchSMSMessagesFromIntent(Intent intent) {
    ArrayList<SmsMessage> receivedMessages = new ArrayList<SmsMessage>();
    Object[] messages = (Object[]) intent.getExtras().get(SMS_EXTRA_NAME);
    for (Object message : messages) {
        SmsMessage finalMessage = SmsMessage
                .createFromPdu((byte[]) message);
        receivedMessages.add(finalMessage);
    }
    return receivedMessages.toArray(new SmsMessage[0]);
}

}

So what's that array of messages I'm getting? Are each one of those messages in the array a single message split by the system when it exceeds the valid number of characters for an SMS, that is 160 characters? Or are they really completely different messages that come in at the same time when the phone has been offline for a while? Can someone clear this up for me? I cannot use the emulator to find out because there is a reported bug that causes the emulator to scramble long incoming SMS messages. Thanks in advance.


Multiple messages may be delivered (at the system's discretion): each is a separate SMS message PDU (protocol description unit). If a message is fragmented (the user sent more than 140 characters) then you will get 2 PDUs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜