我有这段代码:
Intent sharingIntent = new Intent(Intent.ACTION_SENDTO);
sharingIntent.setType("text/plain");
//String shareBody = (employeeName.getText().toString());
String [] shareBody = {employeeName.getText().toString(), employeeSurname.getText().toString(), absenceType.getText().toString()};
sharingIntent.setData(Uri.parse("mailto:myemail@gmail.com"));
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "ABSENCE CARD");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
成功发送一段文字。我怎样才能包含更多内容?这answer并没有给我很多帮助。注释行适用于一个,但String
数组似乎不起作用。
答案 0 :(得分:2)
尝试序列化和反序列化字符串数组:
String stringToSent = employeeName.getText().toString()+";"+ employeeSurname.getText().toString()+";"+absenceType.getText().toString();
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, stringToSent);
并反序列化如下:
String[] receivedInfo = new String[2];
receivedInfo = receivedString.split(";");
在特定情况下,您希望在电子邮件中发送多行,您也可以尝试:(未经测试,可能需要调试)
sharingIntent.setType("text/html");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<html>")
.append(employeeName.getText().toString())
.append("<br/>")
.append(employeeSurname.getText().toString())
.append("<br/>")
.append(absenceType.getText().toString())
.append("<br/></html>").toString()
));
答案 1 :(得分:0)
使用此代码:
ArrayList<String>st= new ArrayList<String>();
st.add("string1"); // Add your text here
st.add("string 2");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, st);
shareIntent.setType("text/*");
startActivity(Intent.createChooser(shareIntent, "Share text to.."));
请查看此link以获取更多信息