I am working on an Android app which uses a broadcastReceiver to extract and show certain text messages. These messages will always be quite long and the broadcastReceiver is failing to get them. After gradually cutting the test messages smaller and smaller I have found the upper limit is about 154 characters (give or take a few).
My code is
public class SmsReceiver extends BroadcastReceiver {
public static final String EXTRA_MESSAGE = "com.example.alert10.MESSAGE";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
String smsSender = "";
String smsBody = "";
for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
smsSender = smsMessage.getOriginatingAddress();
smsBody = smsMessage.getMessageBody();
}
if (smsSender.equals("+447800966043")) {
if (smsBody.contains("Attendance Request")) {
Intent secondintent = new Intent(context, MainActivity.class);
Bundle bundle = new Bundle();
bundle.putString(EXTRA_MESSAGE, smsBody);
bundle.putInt("VIS", 1);
secondintent.putExtras(bundle);
secondintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(secondintent);
abortBroadcast();
}
}
}
}
}
Why is this happening? What can I do to make it work with long messages?