I have been searching for this, found many threads specifying on this. But things are not working for me. Tried setting "exit_on_sent" and also tried using startAcitivityForResult. Here is the code snippet I was trying with
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + phoneNumbers)); // phoneNumbers is a list of phone numbers to which i need to send messages at the same time
sendIntent.putExtra("sms_body", context.getResources().getString(R.string.message_body));
sendIntent.putExtra("exit_on_sent", true);
context.startActivity(sendIntent);
When you use
ACTION_SENDTO
, orACTION_VIEW
, or otherIntent
actions, you are launching a third-party app to go do something. In this case, you are launching a third-party app to send an SMS message.There are ~2 billion Android devices in use, spread across ~10,000 device models. There will be dozens, if not hundreds, of different pre-installed SMS clients across those device models. Users are also welcome to install other SMS clients from the Play Store or other app distribution channels.
What happens when your app starts up one of those hundreds of SMS clients is up to the developers of those SMS clients, not you.
If you want control over the entire user experience, send the SMS message yourself, using
SmsManager
, as Ankit pointed out. If you want to use the user's preferred SMS client, stick withACTION_SENDTO
, but what happens at that point is up to the SMS client developers and the user, not you.You can send SMS silently using SMSManager. as following :