2

I am working on an SMS receiver module in my app in which I am receiving an sms with my app, and if sms is more than 160 characters than I have to concate that SMS with its next part and display it. Currently I am working with a simple receiver code. Please suggest me to perform this task.

Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67

1 Answers1

5

Yes, try as handle multipart messages :

@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]);
                    }
                       StringBuffer content = new StringBuffer();
                        if (messages.length > 0) {
                        for (int i = 0; i < messages.length; i++) {
                            content.append(messages[i].getMessageBody());
                              }
                          }
                         String mySmsText = content.toString();
                        }
                    }

                }
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213