Sending a SMS Message from an Android Application

2019-01-27 05:10发布

In my android application I have implemented sending SMS by using below code.

   Intent smsIntent = new Intent(Intent.ACTION_VIEW);

    smsIntent.putExtra("sms_body", "Hello World!"); 
    smsIntent.putExtra("address", "0123456789");
    smsIntent.setType("vnd.android-dir/mms-sms");

    startActivity(smsIntent);

My problem is that if I have more than one SMS application on the device, it opens the chooser to choose the sender application. I don't want the chooser to be opened; I want to send from Android's native SMS app without opening the chooser. So any help to achieve this will be appreciated.

2条回答
Evening l夕情丶
2楼-- · 2019-01-27 05:52

In my android application i have implemented sending SMS by using below code.

That is not the proper way to send SMS messages. Please use ACTION_SEND or ACTION_SENDTO (the latter with an smsto: Uri). You may encounter devices which can send SMS messages but do not respond to the particular Intent structure that you are using, since that is not the way to send SMS messages.

I don't want that chooser to be opened

If your user chose to install another SMS client, they have the right to use it, since it is their device, their SMS message fee, etc. The user can elect to make your app be the default for your Intent structure if the user chooses to do so, so the user will not be presented with the chooser all of the time.

I wants to send from android Native SMS app without opening chooser

Different devices can have different "native SMS apps", put their by device manufacturers, so you have no means of determining what is the "native SMS app". And, as I noted earlier, the "native SMS app" may not even respond to that strange Intent structure that you are using.

查看更多
地球回转人心会变
3楼-- · 2019-01-27 06:07

Use the SMS Manager?

http://developer.android.com/reference/android/telephony/SmsManager.html

void    sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)

Send a text based SMS.

查看更多
登录 后发表回答