Android:将反馈发送到默认电子邮件

时间:2016-09-27 10:14:22

标签: android email

我有一个反馈表单和发送和取消按钮。当单击发送按钮时,如何使反馈发送响应默认电子邮件?我该如何设置默认电子邮件。这可能吗?请告诉我。谢谢。

这是我的反馈表格的java:

KrTree* tree = new KrTree();
tree->printTree();
tree->addTreeNode(7);
tree->addTreeNode(2);
tree->addTreeNode(10);
tree->addTreeNode(1);
tree->addTreeNode(5);
tree->addTreeNode(9);
tree->addTreeNode(20);

tree->printTree();

Feedback Form

2 个答案:

答案 0 :(得分:0)

您可以使用以下代码段:

     private void sendEmail(String email) {

                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO);

                    String aEmailList[] = {email};
                    emailIntent.setData(Uri.parse("mailto:")); // only email apps should handle this
                    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
                    String feedback_msg = getString(R.string.feedback_msg);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<i><font color='your color'>" + feedback_msg + "</font></i>"));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_msg));

                    PackageManager packageManager = getActivity().getPackageManager();
                    boolean isIntentSafe = emailIntent.resolveActivity(packageManager) != null;
                    if (isIntentSafe) {
                        startActivity(emailIntent);
                    } else {
                        Toast.makeText(getActivity(), R.string.email_app_not_installed, Toast.LENGTH_SHORT).show();
                    }
                } 
   }

答案 1 :(得分:0)

使用选择器以编程方式打开您的电子邮件客户端:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some@email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));

要以编程方式发送电子邮件而不使用选择器,您可以使用this链接。