I am trying to send a SMS through an intent, I want to add a body to the message. After user press send
I want to return to the app. I've added extra as sms_body
and exit_on_sent
. But when I use them both the SMS appears without the body. If i don't use the exit_on_sent
extra everything works fine.
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + phoneNumber));
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra("exit_on_sent", true);
context.startActivity(sendIntent);
You could try using
startActivityForResult(sendIntent, SOME_REQUEST_CODE)
but in my experience it doesn't works most of the time. I would recommend instead using SmsManager.
SmsManager smsMgr = SmsManager.getDefault();
if(smsMgr != null){
PendingIntent sentIntent = PendingIntent.getBroadcast(
getActivity().getApplicationContext(), 0,
new Intent(MY_ACTION_INTENT_SENT), 0);
smsMgr.sendTextMessage(phone, null, message, sentIntent, null);
}
Depending on your application you can do the rest of processing when MY_ACTION_INTENT is sent (indicating the message has actually been sent) or right after sendTextMessage(...) returns.
From API Level 19 there are some interesting features you may found useful http://developer.android.com/reference/android/provider/Telephony.html
Hope it helps.
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