Using the native sms app to send an sms without launching itself

前端 未结 5 1152
忘掉有多难
忘掉有多难 2020-12-15 14:48

I want to send an SMS, but not using the SmsManager class. I want to do it with the native SMS app which is there on an Android phone.

And here is the twist : I do

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 15:16

    Try this:

    String phoneNo = textPhoneNo.getText().toString();
    String sms = textSMS.getText().toString();
    
    
    
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, sms, null, null);
        Toast.makeText(getApplicationContext(), "SMS Sent!",
            Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),
            "SMS faild, please try again later!",
            Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
    

提交回复
热议问题