Getting back to my application after sending sms u

2020-02-06 20:13发布

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);

2条回答
够拽才男人
2楼-- · 2020-02-06 20:24

My requirement is to go back to my application after sending message.

When you use ACTION_SENDTO, or ACTION_VIEW, or other Intent 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 with ACTION_SENDTO, but what happens at that point is up to the SMS client developers and the user, not you.

查看更多
疯言疯语
3楼-- · 2020-02-06 20:27

You can send SMS silently using SMSManager. as following :

       try {

            String ph="1234568790";
            String msg="Hello";

            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(ph, null,msg, null, null);
            Toast.makeText(MainActivity.this, "Message Sent",
                    Toast.LENGTH_LONG).show();
        }
        catch (Exception e)
        {
            Toast.makeText(MainActivity.this, "Message not Sent",
                    Toast.LENGTH_LONG).show();
        }
查看更多
登录 后发表回答