0

我的应用程序中有一个文本框(EditText)和一个按钮,我想要做的是,当任何人点击按钮时,文本框(EditText)中写入的文本会被复制并且此文本可以共享到任何应用程序,例如作为 - 消息传递、Gmail、Ymail 等。现在我正在做的是从“EditText”中获取文本并将其存储到一个新变量(字符串)中,比如“a”,现在应用 Intent“ACTION_SEND_MULTIPLE”

这是意图的代码

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"example@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "a");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, a);
startActivity(Intent.createChooser(emailIntent, "Share it via..."));
4

2 回答 2

0

您可能需要“createChooser”:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, edittext.getText().toString());
startActivity(Intent.createChooser(intent, "chooser title"));
于 2013-03-16T13:11:40.910 回答
0

我不确定您的问题是什么,但这就是您从 editText 获取文本的方式

String mString= et.getText().toString();

然后放到分享意图中

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, mString);
shareIntent.setType("text/plain");
startActivity(shareIntent);

如果您只想将其作为电子邮件发送,并且只允许电子邮件客户端响应意图,则如下所示。

Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("mail to address") 
   + "?subject=" + Uri.encode("subject here") 
   + "&body=" + Uri.encode("body here");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send..."));   

这允许您输入主题字段和 mailto 字段...等

于 2013-03-16T13:02:25.930 回答