4

When I use this code:

String numberToSendFor = "21987654321";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(numberToSendFor, null, "Test Message", null, null);

The SMS Message is sent normally (and goes to sent messages list in my phone).

But, when I use this:

String numberToSendFor = "21987654321";
String messageToSend = "Test Message"; // store the message into a variable
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(numberToSendFor, null, messageToSend, null, null);

The message don't is sent and don't goes to sent messages list.

What should I do to send message from a variable?

Note: I have the permission to send SMS (AndroidManifest.xml).

Thanks.

Silvio Delgado
  • 6,798
  • 3
  • 18
  • 22

1 Answers1

0

Why dont you use the already existing intent provided by android

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content"); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

Also this requires permission :

<uses-permission android:name="android.permission.SEND_SMS" />

Let me know if it works

  • 2
    This does not do the same thing the OP's code is doing. This opens another app to send the message. This also does not require the `SEND_SMS` permission. – Mike M. Jun 29 '16 at 22:37