Android - Extract text from SMS

I want to be able to extract text from received SMS. I am not sure if I should use content providers or whether the sms message is included in the intent received by the broadcast receiver.

I have a broadcast receiver waiting for SMS, and I want to check the contents of the received message.

Thanks.

+4
source share
2 answers

You can create SmsMessage instances from Intent in 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(); } 
+5
source

Please note that the length of each SMS message in a multi-part (concatenated) SMS is not 160 characters, because each of them starts with a data header, so 160 characters are not the actual size of each SMS, these are characters the length with which the message becomes concatenated. In addition, this boundary depends on the encoding of the message.

See details in [link text] [1]. This should be a comment, not an answer, but by the time of writing, my reputation does not allow me to leave comments.

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

+2
source

All Articles