progmatically send sms on android 8

2019-01-29 09:47发布

问题:

I want the SMS screen to be dismissed AND control to come to my app automatically after sending the SMS. i'm using this code to send sms:

 Uri uri = Uri.parse("smsto:" + "074********; 074********");
    Intent smsSIntent = new Intent(Intent.ACTION_SENDTO, uri);
    smsSIntent.putExtra("sms_body", "iconference sms");
    sendIntent.putExtra("exit_on_sent", true);
    startActivity(smsSIntent);

this code works fine in all versions of android but in android 8 when i click send my application goes on background can you help me ?

回答1:

this code works fine in all versions of android

There are hundreds of different apps that might respond to ACTION_SENDTO with an smsto: Uri.

I want the SMS screen to be dismissed AND control to come to my app automatically after sending the SMS

What the SMS client does is up to the developers of the SMS client. And, again, there are hundreds of those.

i'm using this code to send sms

Neither sms_body nor exit_on_sent are documented Intent extras for ACTION_SENDTO. Only some of of the hundreds of SMS clients will honor them.

but in android 8 when i click send my application goes on background

The developers of that SMS client do not honor exit_on_sent, or didn't test that case.

If you want absolute control over the SMS-sending experience, send it yourself, using SmsManager. Otherwise, please understand that you are starting any one of hundreds of possible apps, and those apps will do whatever their developers want.