Android 单击按钮打开电子邮件客户端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2734749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening an email client on clicking a button
提问by Rahul Kalidindi
I am designing an app in which i need to open an email client on clicking a button. The email client should be opened with a pre-defined subject and 'to' address. Is there a way to attain this? Please provide me the solution and a code example if possible...
我正在设计一个应用程序,我需要在其中单击按钮打开电子邮件客户端。电子邮件客户端应以预定义的主题和“收件人”地址打开。有没有办法达到这个目标?如果可能,请向我提供解决方案和代码示例...
回答by yanchenko
Goes like this:
是这样的:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Alternatively, you could use IntentFactory.getSendEmailIntent(String mailTo, String mailCC, String subject, CharSequence body, File attachment).
回答by mixel
To show only email clients use this code:
要仅显示电子邮件客户端,请使用以下代码:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:[email protected]?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
If you already chose default email client then it will launch it. Otherwise it will show a list of available email clients.
如果您已经选择了默认电子邮件客户端,那么它将启动它。否则,它将显示可用电子邮件客户端的列表。
回答by Daniel Beltrami
If you have a e-mail address on screen, you can just use in your xml, like this:
如果屏幕上有电子邮件地址,则可以在 xml 中使用,如下所示:
android:autoLink="email"
回答by shailesh
You can open email client on emulator by configuring your email address with email inbuild with email. Then when call the intent will open and send mail.
您可以通过使用电子邮件内置电子邮件配置您的电子邮件地址,在模拟器上打开电子邮件客户端。然后当调用意图将打开并发送邮件。