So I get this stack trace:
java.lang.NullPointerException
at android.telephony.SmsMessage$SubmitPdu.<init>(SmsMessage.java:132)
at android.telephony.SmsMessage.getSubmitPdu(SmsMessage.java:551)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:228)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:107)
at com.emergency.button.SMSSender.safeSendSMS(SMSSender.java:91)
at com.emergency.button.EmergencyActivity$EmergencyThread
.sendSMS(EmergencyActivity.java:294)
at com.emergency.button.EmergencyActivity$EmergencyThread
.sendMessages(EmergencyActivity.java:386)
at com.emergency.button.EmergencyActivity$EmergencyThread
.run(EmergencyActivity.java:266)
And this is how I call sendTextMessage, I don't verify message length or phone number validity:
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
This error seems to only occur on HTC Desire or HTC Wildfire with android version 2.2 or 2.21 so I dug up the android platform source (which is actually not as easy to do as I expected) and found:
SmsMessage.java once upon a time though this might not be relevant as I see some of the line numbers don't line up.
The emergency button project is open source so you can check the code out for reference. I should probably note that I can't test this myself, I don't have either phone model.
You might be hitting this issue with a message that is too long. I don't know why it would only be happening for certain phones, though.
http://code.google.com/p/android/issues/detail?id=3718
Replace
sms.sendDataMessage(destinationAddress, scAddress, destinationPort, data, sentIntent, deliveryIntent)
by
sms.sendMultipartTextMessage(phoneNumber, null, message, null, null);
Your message must be an ArrayList for that, use this method before calling sendSMS
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(locationMessage);
sendSMS(telNumber.getText().toString(),parts );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With