Dismiss SMS activity/screen after sending sms in Android

I cannot find a way to dismiss the SMS screen/activity after sending SMS successfully.

At the moment i can send SMS, but to come back to my app i have to press back.

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

This is the code i am using:

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

Answers


You need to use exit on sent to return back to your application.

sendIntent.putExtra("exit_on_sent", true);

You have to create activity in your application which sends SMS then you can call finish() from your activity to exit from activity. By using built-in SMS screen you cannot exit the screen until you do it by your self. Here is a good tutorial for sending SMS from your application.


i create a separate activity, and implemented the listeners for 'SmsManager', the code will even send SMS longer than 160 characters.

Here is my code;

private void sendSMS()
{
    LoadingView.showLoading(this, false);
    String SENT = "SMS_SENT";
    PendingIntent sentPI = PendingIntent.getBroadcast(SMSActivity.this, 0, new Intent(SENT), 0);

    //--- When the SMS has been sent ---
    registerReceiver(new BroadcastReceiver(){
        @Override
        public void onReceive(Context arg0, Intent arg1) {
            LoadingView.dismissLoading();
            switch (getResultCode())
            {
                case Activity.RESULT_OK:
                    Toast.makeText(SMSActivity.this, "SMS sent", Toast.LENGTH_SHORT).show();
                    finish();
                    break;
                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                    Toast.makeText(SMSActivity.this, "Generic failure", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NO_SERVICE:
                    Toast.makeText(SMSActivity.this, "No service", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_NULL_PDU:
                    Toast.makeText(SMSActivity.this, "Null PDU", Toast.LENGTH_SHORT).show();
                    break;
                case SmsManager.RESULT_ERROR_RADIO_OFF:
                    Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show();
                    break;
            }
        }
    }, new IntentFilter(SENT));


    ArrayList<PendingIntent> arrPI = new ArrayList<PendingIntent>();
    arrPI.add(sentPI);

    // Because SMS has more than 160 characters, we will divide it in multiple parts.
    SmsManager sms = SmsManager.getDefault();
    ArrayList<String> parts =sms.divideMessage(mMessage.getText().toString());
    sms.sendMultipartTextMessage(mNumbers, null, parts, arrPI, null);
}

Need Your Help