BroadcastReceiver for multi-page SMS

I need to save sms in sqlite db when i get it. It currently works fine with sms (160 characters), but if I get multi-page sms, it trims sms by about 155 characters.

This is my code:

SmsBR.java

public class SmsBR extends BroadcastReceiver { private DBManager dbm; @Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[])bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]); } if (messages.length > 0) { dbm=DBManager.getDBM(null); dbm.insertSMS(messages[0]); }}}} 

DBManager is a singleton class that I wrote to simplify read / write operations, and I'm sure it has no problems with long texts!

+4
source share
2 answers

according to several applications, it seems that multiple SMSs are received in the same intent and that they are represented by an array of messages.

so basically you get the full message:

 StringBuffer content = new StringBuffer(); for (Message sms : messages) { content.append(sms.getDisplayMessageBody()); } String mySmsText = content.toString(); 

As far as I know, it seems that the messages are in the correct order. In any case, I don't know how to get the message header (except for pdu parsing myself).

+7
source

155 characters sound like the length of user data when the user header for multiple SMS was taken into account. In other words, it doesn't seem like there is a problem here - the PDU is stored correctly. You will need to collect other SMS PDUs to display / save everything.

0
source

All Articles