Android 按钮 onclick 提交到电子邮件

标签 android form-submit email-client

我已经使用 Java 和 Xml 工作了几个月,感谢大家在 StackOverflow 上的帮助,我学到了很多东西。

我的问题是关于与提交按钮相关的 android java 编程。

目前我正在尝试弄清楚如何向电子邮件地址提交值(在幕后)

假设我们有一个文本字段和一个按钮;我想获取在文本字段中输入的值,并将其提交到电子邮件地址 onclick。

我无法在网上找到任何向我展示如何执行此操作的内容。

预先感谢您阅读我的帖子,我期待您的建议。

最佳答案

这是一个很好的例子,说明如何使用 Intents 派上用场! Android 有一堆预定义的 Intent,可以在系统内做某些事情;您可能之前点击过一张图片,然后会弹出一个对话框,询问您是要在图库中还是在 Astro 等第三方应用程序中查看它。图像的观看具有其自身的预定 Intent 。

发送电子邮件也有其自己的预定 Intent :android.content.Intent.ACTION_SEND。您需要使用该属性创建 Intent ,然后附加额外信息(即发送地址、主题/消息正文等)。

示例代码:

// Data members
private Intent emailIntent;
private String feedback;
private EditText feedbackBox;

// Create the Intent, and give it the pre-defined value
// that the Android machine automatically associates with
// sending an email.
emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");

// Put extra information into the Intent, including the email address
// that you wish to send to, and any subject (optional, of course).
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"your_email@whatever.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Insert subject here");

// Acquire feedback from an EditText and save it to a String.
feedback = feedbackBox.getText().toString();

// Put the message into the Intent as more extra information,                   
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, feedback);

// Start the Intent, which will launch the user's email 
// app (make sure you save any necessary information in YOUR app
// in your onPause() method, as launching the email Intent will
// pause your app). This will create what I discussed above - a
// popup box that the user can use to determine which app they would like
// to use in order to send the email.
startActivity(Intent.createChooser(emailIntent, "Insert title for dialog box."));

希望对您有所帮助!!

您可能想查看的一些来源:
http://developer.android.com/guide/topics/intents/intents-filters.html
http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND

关于Android 按钮 onclick 提交到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8994488/

相关文章:

android - Crashlytics 连接被拒绝 - 无法连接到无法连接到 api.crashlytics.com

javascript - Alert.alert() 在 React Native 0.36.1 中不起作用

java - 为什么我的 Toast 不显示?

javascript - 提交按钮在模态弹出窗口中不起作用,但单击按钮有效

android - fragment 不可分配给 android.app.Activity

javascript - 如何使 Web 表单在下拉选择中自动提交

javascript - 一旦我刷新通过表单获取数据的页面,一切都会消失

php - mailto 正文中的换行符 : link

c++ - 如何对电子邮件客户端进行单元测试

email - 发送 8 位电子邮件安全吗?