Android 按钮 onclick 提交到电子邮件

发布于 2024-12-28 21:27:32 字数 266 浏览 2 评论 0原文

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

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

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

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

我无法在网上找到任何可以告诉我如何执行此操作的内容。

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

I have been working with Java and Xml for a few months now, and have learned a great deal thanks to everyones help on StackOverflow.

My question is about java programming for android in relation to the submit button.

Currently I am trying to figure out how to submit a value to an email address (behind the scenes)

Lets say we have a text field and a button; I want to take the value entered in the text field, and submit that to an email address onclick.

I am unable to find anything online that shows me how to do this.

Thank you in advance for reading through my post and I look forward to your suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情绪操控生活 2025-01-04 21:27:32

这是一个很好的例子,说明如何使用 Intents 非常方便!
Android 有一堆预定义的 Intent,可以在系统内执行某些操作;您之前可能点击过某张图片,然后会弹出一个对话框,询问您是否要在图库中或在 Astro 等第三方应用程序中查看它。图像的观看有其自身预先确定的意图。

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

示例代码:

// 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[]{"[email protected]"});
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

This is a great example of how using Intents can come in great handy!
Android has a bunch of pre-defined Intents that do certain things within the system; you may have clicked on a picture before and a dialog popped up asking whether you would like to view it in your gallery or in a third-party app such as Astro. The viewing of an image has its own pre-determined intent.

Sending an email also has its own pre-determined intent: android.content.Intent.ACTION_SEND. You'll need to create an intent with that property and then attach extra information (ie. the address to send to, the subject/message body, etc.).

Example code:

// 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[]{"[email protected]"});
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."));

I hoped this helped!!

Some sources you might like to check out:
http://developer.android.com/guide/topics/intents/intents-filters.html
http://developer.android.com/reference/android/content/Intent.html#ACTION_SEND

给妤﹃绝世温柔 2025-01-04 21:27:32
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, someEditText.getText());
startActivity(Intent.createChooser(emailIntent, "Send someone an email..."));
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, someEditText.getText());
startActivity(Intent.createChooser(emailIntent, "Send someone an email..."));
も让我眼熟你 2025-01-04 21:27:32

试试这个

Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:Type email address here"));
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }

try this

Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:Type email address here"));
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
清秋悲枫 2025-01-04 21:27:32

效果很好

 String   mail=mailid.getText().toString();
 String   msubject=subject.getText().toString();
 String   mbody=body.getText().toString();
    Log.i("Send email", "");
    String[] TO = {mail};
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Static subject "+ msubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Static body "+ mbody);

    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        finish();

    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }

It works good

 String   mail=mailid.getText().toString();
 String   msubject=subject.getText().toString();
 String   mbody=body.getText().toString();
    Log.i("Send email", "");
    String[] TO = {mail};
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Static subject "+ msubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Static body "+ mbody);

    try {
        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
        finish();

    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文