Nemanja
Nemanja

Reputation: 228

Pass sms body to default sms app

I found multiple threads here about this, but none of them are working for me. This is my code:

public void sendSMS (String number, String body) {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:" + number));
        i.putExtra("abc", body);
        startActivity(i);
    }

It opens stock SMS app and passes the number to send, but text body is empty. I also tried this Uri.fromParts(body, number, null) but then the app just crashes.

Upvotes: 0

Views: 1144

Answers (2)

mehul chauhan
mehul chauhan

Reputation: 1802

Try this

Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));
            smsIntent.putExtra("address", "12125551212");
            smsIntent.putExtra("sms_body","Body of Message");
            startActivity(smsIntent);

Upvotes: 1

Pragnesh Ghoda  シ
Pragnesh Ghoda シ

Reputation: 8337

Replace your code with below code. You are not passing correct keys to detect number and text body for the sms.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));     
intent.putExtra("sms_body", message); 
startActivity(intent);

Please read this documentation for detailed information. Compose an SMS/MMS message with attachment

Upvotes: 3

Related Questions