It seems that if an SMS with some larger text comes, it is cut for some reason so not whole sms comes in, here is my code:
public class SmsReceiver extends BroadcastReceiver {
// vars here
@Override
public void onReceive(Context context, Intent intent) {
// Get SMS map from Intent
Bundle extras = intent.getExtras();
if (extras != null) {
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);
String address = "";
String body = "";
for (int i = 0; i < smsExtra.length; ++i) {
SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
body = sms.getMessageBody().toString();
address = sms.getOriginatingAddress();
}
// show the popup
Intent intnt = new Intent(context, ShowNotification.class);
intnt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intnt.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intnt.putExtra("address", address);
intnt.putExtra("body", body);
context.startActivity(intnt);
}
}
}
Now let's assume sms text was:
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra.
And i show received sms from above broadcast receiver in toast, only last few words are being shown in toast or even if I pass this sms body to another popup intent, only as much text is passed over as shown in toast:
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, body, duration);
toast.show();
So for some reason not whole sms text is coming in :(
Can anyone tell how to handle this ? As I have seen other sms apps such as SMS Popup or Go SMS Pro, they do get full sms text and show in popup or conversations.
Thanks for your help