Android - Extract text from SMS

若如初见. 提交于 2019-12-05 15:26:42

You can create SmsMessage instances from the Intent in your BroadcastReceiver as follows:

Bundle bundle = intent.getExtras();
Object[] pdus = (Object[])bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
    messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
    //messages[i].getMessageBody();
}

Note that the length of each SMS in a multi-part (concatenated) SMS is not 160 chars, because each of them starts with a data header, so 160 chars is not the actual size of each SMS, it is the chars length from which the message becomes concatenated. Also, this boundary depends on the encoding of the message.

For more info see [link text][1] . This should be a comment and not an answer, but by the time of writing it my reputation does not allows me to leave comments.

[1]: http://en.wikipedia.org/wiki/SMS#Message_size message size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!