3

I'm trying to implement sending an SMS from an Android app with a predefined text message. I'm using the native chooser activity by doing:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");

String[] phoneNumber = {selectedContact.getPhoneNumber()};
intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.contact_message_body));
intent.putExtra(Intent.EXTRA_PHONE_NUMBER, phoneNumber);

startActivity(Intent.createChooser(intent, "Send Message"));

The phone number is indeed stored in the phoneNumber variable, but when testing it, it's not being passed over to the recipient field for the Messages option. So the EXTRA_TEXT info fills the new SMS but the recipient is empty.

I've seen others use Intent.ACTION_SEND but this will not work in my case, because I also have to implement Email sending from the same chooser.

Appreciate the help!

Bernardo
  • 103
  • 1
  • 10

1 Answers1

-2

Did you try to use SmsManager I think it's more easy to use

SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
Hayk Petrosyan
  • 363
  • 1
  • 6
  • Thanks but I'm not looking for an alternate way of sending the SMS. I want to use the intent.createChooser activity, since it expands beyond SMS to other apps such as Mail or Whatsapp. – Bernardo May 30 '16 at 10:55