send SMS Intent in Android

nubme picture nubme · Feb 16, 2011 · Viewed 9.3k times · Source
String x="Hello World";
String y="You Rock!!!";
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", x); 
sendIntent.putExtra("sms_body", y); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

I'm trying to send a multiple message bodies via SMS, but only "You Rock!!!" is displayed. What i want to do is be able to display multiple messages and have it pre-formatted (on different lines).

So for example...

Hello World
You Rock!!!

Answer

abombss picture abombss · Feb 16, 2011

If you want to send a multi-line message just put a newline between the 2 strings.

x + "\n" + y

if want to send multiple messages there is no way to do that, that I am aware of. You could use [startActivityForResult][1] then in your activities [onActivityResult][2] method you can send then next message.

[1]:http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)

[2]: http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent)