I'm trying to develop an app that sends SMS messages to email addresses. Using the default messaging app on my Note 5, I can enter in my email address as the recipient and send a message no problem. (I have Sprint.) But when I try to do this in code:
Intent intentSent = new Intent(Globals.SENT);
intentSent.putExtra("phoneNumber",phoneNumber);
Intent intentDelivered = new Intent(Globals.DELIVERED);
intentDelivered.putExtra("emailAddress",emailAddress);
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0,
intentSent, 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,
intentDelivered, 0);
SmsManager sms = SmsManager.getDefault();
if (emailAddress != null && messageBody.length() > 0) {
sms.sendTextMessage(emailAddress, null, messageBody, sentPI, deliveredPI);
}
The Sent receiver is not called and the message shows up in my messaging app as that it was sent to "Anonymous" and that delivery failed. The Delivered receiver does call onReceive():
public class SMSDeliveredReceiver extends BroadcastReceiver {
private String TAG = "SMSDeliveredReceiver";
Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
Bundle extras = intent.getExtras();
if (extras != null) {
String emailAddress = extras.getString("emailAddress","");
Log.d(TAG,emailAddress );
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(context,"Email received",Toast.LENGTH_LONG).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(context, "SMS not delivered",
Toast.LENGTH_LONG).show();
break;
}
}
}
}
Is there a way to do this successfully? This answer will not help me as I want to do this for all carriers. Android: How to send SMS to email account