在Android中发送短信后,关闭短信活动/屏幕

时间:2015-05-08 15:37:17

标签: android android-intent android-activity sms back

成功发送短信后,我无法找到解除短信屏幕/活动的方法。

目前我可以发送短信,但要回到我的应用程序,我必须按回来。

我想在发送短信后自动关闭短信屏幕并控制我的应用程序。

这是我正在使用的代码:

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

3 个答案:

答案 0 :(得分:4)

您需要使用exit on return返回您的应用程序。

sendIntent.putExtra("exit_on_sent", true);

答案 1 :(得分:1)

您必须在发送activity的{​​{1}}中创建application,然后您可以从SMS致电finish()以退出activity 。通过使用内置的activity屏幕,您无法退出屏幕,直到您自己完成。从SMS发送tutorialHere是一个很好的SMS

答案 2 :(得分:0)

我创建了一个单独的活动,并实现了'SmsManager'的监听器,代码甚至会发送超过160个字符的短信。

这是我的代码;

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);
}
相关问题