Send SMS Intent to Android

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 try to send several message bodies via SMS, but only "You Rock !!!" is displayed. What I want to do is display several messages and pre-format them (on different lines).

So for example ...

Hello World
You Rock!!!
+3
source share
2 answers

If you want to send a multi-line message, just put a new line between the two lines.

x + "\n" + y

if you want to send some messages, there is no way to do this that I know of. You can use the [startActivityForResult] [1], and then in your action [onActivityResult] [2] method you can send the following 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)

+6

, , putExtra , Bundle (), . , "sms_body" "Hello World", reset "You Rock!!!".

, , - :

String smsBody="Hello World\nYou Rock!!!";
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", smsBody); 
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);

\n (http://en.wikipedia.org/wiki/Newline), , ( , \n).\n , . .

, , ( x y). , , x y.

+3

Source: https://habr.com/ru/post/1792444/


All Articles