My cellphone carrier offers an sms-email gateway. This is done simply by entering the email address as the SMS message's destination. The email is delivered as 5555555555@mycarrier.com
I am attempting to use this with my new Android device. The standard android messaging application converts all messages with an email address as the destination to "MMS" and attempts to send them as data - not what I want to do.
Attempting with android.telephony.SmsManager
:
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("address@example.com", null, "Message body here", null, null);
This throws the following exception:
Caused by: java.lang.NullPointerException
at com.android.internal.telephony.gsm.SmsMessage.getSubmitPduHead(SmsMessage.java:595)
at com.android.internal.telephony.gsm.SmsMessage.getSubmitPdu(SmsMessage.java:295)
at android.telephony.SmsMessage.getSubmitPdu(SmsMessage.java:599)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:228)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:107)
I've looked at this project, android-sms-email, which attempts to do the same thing. It also crashes in the same fashion when configured for my carrier.
This does not seem like the desired behaviour and I assume it is an Android bug (some bug reports hint at the issue). I've experimented a bit and can see that appending any number and some symbols to the email address do not cause the same failure but the message is not delivered either.
I've also tried using SmsManager.sendMultipartTextMessage
but this runs into the same problem within SmsMessage.getSubmitPduHead
.
Again:
SmsManager manager = SmsManager.getDefault();
// Works
manager.sendTextMessage("15555555555", null, "Message body here", null, null);
// Fails
manager.sendTextMessage("address@example.com", null, "Message body here", null, null);
Tested on an HTC Desire Z - Android v2.2