将编辑文本字段中的文本添加到电子邮件中

2023-12-14

我有一个应用程序,希望与我们联系,以便用户输入姓名、地址、电话号码和评论部分。然后他们将单击“撰写邮件”按钮,它将自动将文本加载到电子邮件中。已经解决了一些代码,但不确定如何将编辑文本中的文本放入我的电子邮件消息中。任何人对我如何做到这一点有任何建议。我已附上 xml 文件和 java 文件中的代码。

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;

 public class Contactform extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactform);

    Button email = (Button) findViewById(R.id.button30);
    email.setOnClickListener(new View.OnClickListener()  {

        @Override
        public void onClick(View v){
            //TODO Auto-generated method stub
            Intent email = new Intent(android.content.Intent.ACTION_SEND);

            /* Fill it with Data */
            email.setType("plain/text");
            email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
            email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
            email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");

            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(email, "Send mail..."));
        }
    });
}


 }

这是 xml 文件

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#bf311a" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:text="@string/name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_marginLeft="37dp"
        android:layout_toRightOf="@+id/textView1"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText1"
        android:layout_marginTop="35dp"
        android:text="@string/addy"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentRight="true"
        android:inputType="textPostalAddress" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/editText2"
        android:layout_marginTop="30dp"
        android:textColor="#000000"
        android:text="@string/cell"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView3"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/editText2"
        android:inputType="phone" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText3"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:textColor="#000000"
        android:text="@string/questions"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="25dp"
        android:inputType="textMultiLine" />

    <Button
        android:id="@+id/button30"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText4"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="47dp"
        android:background="@drawable/composemail" />

</RelativeLayout>

这是我的表单的样子,如果有帮助的话

enter image description here

感谢您提供的任何帮助。仍在学习如何做这些事情,所以如果之前有人问过这个问题,我深表歉意,但我已经搜索了两天,似乎找不到我需要做的事情。

对于那些想知道的人来说,这是正确的代码。我需要修改的唯一代码是 Java 文件的代码,因此这是我将发布的唯一代码。

 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;

 public class Contactform extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contactform);

    final EditText name = (EditText) findViewById(R.id.editText1);
    final EditText addy = (EditText) findViewById(R.id.editText2);
    final EditText cell = (EditText) findViewById(R.id.editText3);
    final EditText questions = (EditText) findViewById(R.id.editText4);

    Button email = (Button) findViewById(R.id.button30);
    email.setOnClickListener(new View.OnClickListener()  {

        @Override
        public void onClick(View v){
            //TODO Auto-generated method stub
            Intent email = new Intent(android.content.Intent.ACTION_SEND);

            /* Fill it with Data */
            email.setType("plain/text");
            email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
            email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
            email.putExtra(android.content.Intent.EXTRA_TEXT, 
                    "name:"+name.getText().toString()+'\n'+"address:"+addy.getText().toString()+'\n'+"phone:"+cell.getText().toString()+'\n'+'\n'+questions.getText().toString()+'\n'+'\n'+"Sent from the Lads to Leaders/Leaderettes Android App.");

            /* Send it off to the Activity-Chooser */
            startActivity(Intent.createChooser(email, "Send mail..."));
        }
    });
}


 }

好的,简单解释一下。您必须在 oncreate 方法之后在代码中声明您的编辑文本。它前面也必须说final。然后将字符串输入到 EXTRA TEXT 的意图中。我还在单引号中添加了“\n”。此操作将充当输入按钮,为每个项目提供自己的行,因此例如我只想在一行上显示名称,因此我执行了 name+mystring+'\n'。这将使您的姓名和字符串显示在一行上,然后向下一行显示下一行。希望这能帮助其他人。


您可以将所有数据放入其中email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");

首先在oncreate中通过ID获取所有EditText

 EditText name = (EditText) findViewById(R.id.editext1);
 EditText address = (EditText) findViewById(R.id.editext2);
 EditText phone = (EditText) findViewById(R.id.editext3);

然后把所有数据

email.putExtra(android.content.Intent.EXTRA_TEXT, 
"name:"+name.getText().toString()+"address:"+address.getText().toString()+"phone:
 "+phone.getText().toString());

Enjoy :)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将编辑文本字段中的文本添加到电子邮件中 的相关文章

  • Android - 如何访问 onResume 中 onCreate 中实例化的 View 对象?

    In my onCreate 方法 我正在实例化一个ImageButton View public void onCreate Bundle savedInstanceState super onCreate savedInstanceSt
  • 检查双精度值的等于和不等于条件

    我在比较两者时遇到困难double values using and 我创建了 6 个双变量并尝试进行比较If健康 状况 double a b c d e f if a b c d e f My code here in case of t
  • 在 Android 中的活动、服务和应用程序之间传递变量

    有人可以给我提供以下活动 服务 应用程序组合的示例吗 我拥有这三个 但我已经把我的应用程序弄得一团糟 试图在这个地方传递一堆变量 现在我不知道发生了什么 请注意 我是 Android 新手 最近我一直在努力解决这个问题 因为有很多方法可以实
  • 在 Android 2.2 上运行 HelloCordova 时找不到类“android.webkit.WebResourceResponse”

    我尝试按照本教程进行操作 http docs phonegap com en 2 7 0 guide getting started android index md html Getting 20 Started 20with 20 An
  • 更改 AChartEngine 中的图例大小

    我想专门更改饼图的图例大小输出 我已经尝试了所有可以找到的 AChartEngine 方法 但没有一个只能更改图例文本大小 我必须重写 onDraw 函数吗 如果是这样 怎么办 要设置图例高度 请使用 renderer setLegendH
  • MI设备中即使应用程序被杀死,如何运行后台服务

    您好 我正在使用 alaram 管理器运行后台服务 它工作正常 但对于某些 mi 设备 后台服务无法工作 我使用了服务 但它无法工作 如何在 mi 中运行我的后台服务 MI UI有自己的安全选项 所以你需要的不仅仅是上面提到的粘性服务 你需
  • 方法断点可能会大大减慢调试速度

    每当向方法声明行添加断点 在 Intellij IDEA 或 Android Studio 中 时 都会出现一个弹出窗口 方法断点可能会大大减慢调试速度 为什么会这样戏剧性地减慢调试速度 是我的问题吗 将断点放在函数的第一行有什么不同 Th
  • 6:需要显示BuyFlow UI

    There is a problem when i am click on payWithGoogle Button I am implementing Google Pay in my Android Application and wh
  • iPhone 标签栏上的未读计数

    在 Cocoa Touch 上实现 TabBar 上图标的未读计数的最佳方法是什么 我想模仿 SMS 或邮件应用程序的行为 向我的应用程序的用户显示未读消息计数 并使用包含数字的红点 您正在寻找的属性称为徽章 您可以通过执行以下操作来设置它
  • 使用 java 按电子邮件发送日历邀请

    我正在尝试使用 java 发送每封电子邮件的日历邀请 收件人收到电子邮件 但不会显示接受或拒绝的邀请 而是将该事件自动添加到他的日历中 我正在使用 ical4j jar 构建活动 邀请 private Calendar getInvite
  • 海报风格的电子邮件验证

    我正在考虑创建一个类似于Posterous的服务 用户可以在其中发布到固定地址 例如 电子邮件受保护 cdn cgi l email protection然后帖子的身份验证将基于发件人地址和标头签名的某种组合 Posterous 似乎正在做
  • Python Kivy - 在本机网络浏览器中打开 url 的应用程序

    我尝试制作一个简单的应用程序 在单击 Screen One 上的按钮后 在 Kivy 中打开一个网页 我使用了这个主题 Python 在应用程序中直接显示网络浏览器 iframe https stackoverflow com questi
  • Facebook LoginActivity 未正确显示

    我有一个使用 Facebook 登录的应用程序 我有 FacebookSDK 并且使用 com facebook LoginActivity 问题是 在 10 英寸平板电脑上 当显示软键盘时 活动无法正确显示 我使用的是 Samsung G
  • 当应用程序未运行时如何堆叠 Firebase Cloud Messaging 通知?

    我在用Firebase Cloud Messaging将推送通知从我的服务器发送到我的 Android 应用程序 当应用程序运行时 通知是stacked因为我将它们设置为我的一个组FirebaseMessagingService 这很好 但
  • 无法在 Android 模拟器中安装 apk

    我正在尝试通过 adb shell 在 ICS 模拟器中安装 apk 从一个站点下载 但出现以下错误 失败 INSTALL FAILED UID CHANGED 可能是什么问题 只需 rm r 有问题的数据目录即可 如果您在安装时遇到此错误
  • 如何在android sdk上使用PowerMock

    我想为我的 android 项目编写一些单元测试和仪器测试 然而 我遇到了一个困扰我一段时间的问题 我需要模拟静态方法并伪造返回值来测试项目 经过一些论坛的调查 唯一的方法是使用PowerMock来模拟静态方法 这是我的 gradle 的一
  • 如何更改锁屏自定义文本(所有者信息)?

    我写了程序代码 String message This is test Settings System putString context getContentResolver Settings Secure LOCK PATTERN EN
  • ormlite 将日期读取为 'yyyy-MM-dd'

    我需要读取给我的 sqlite 数据库 因此我无法更改表中的日期格式 yyyy MM dd 当我尝试使用 ormlite 为我生成对象时 使用以下注释 DatabaseField columnName REVISION DATE dataT
  • 基于BluetoothChat示例通过蓝牙套接字发送文件

    大家好 根据我之前问的一个问题 我已经能够将文件转换为其他字节数组 以便使用以下写入方法 public void sendFile Log d TAG sending data InputStream inputStream null Ur
  • 绘制大位图时 nSyncAndDrawFrame 速度极慢

    我想用多个大位图优化视差滚动视图 在我的 Nexus 5 上 一切都很顺利 Traceview 转储如下所示 doFrame 方法大约需要 18 毫秒才能完成 但是 当使用我的 Nexus 7 或 Android 6 模拟器 Genymot

随机推荐

  • edu.stanford.nlp.io.RuntimeIOException:无法连接到服务器

    我正在尝试使用 CoreNLP 服务器注释多个句子 但是 如果我尝试这样做too many我得到的句子 Exception in thread Thread 48 edu stanford nlp io RuntimeIOException
  • Android 片段无法正确替换

    我正在尝试使用片段构建 3 0 的应用程序 应用程序的左侧有一个静态片段 右侧有一个动态片段 我的动态部分中的每个片段都有一个标题 每当我去替换初始片段时 第一个片段的标题仍然显示在第一个片段的标题上方 连续的替换替换了下部 但仍然显示初始
  • 并发更新期间的 Hibernate StaleObjectStateException

    我在 Java J2EE Web 应用程序中使用 Hibernate 3 5 2 和 Spring Core 3 0 1 当不同的用户同时更新同一记录时 我收到 StaleObjectStateExcpetion 事务由 javax per
  • 带有 2 行文本的 Windows Phone 8.1 AppBarButton 图标

    我想知道如何使 AppBarButton 图标具有 2 行文本 我想让它像 Windows 日历中一样 AppBarButton 不在其图标中显示文本或任意 Xaml 它必须是来自字体 位图或路径的符号 对于这样的日历显示 最好使用位图 由
  • 如何在 Isabelle 中定义偏函数?

    我尝试用以下方法定义偏函数partial function关键词 它不起作用 这是最能表达直觉的 partial function tailrec oddity nat gt nat where oddity Zero Zero oddit
  • 如何通过 Google Apps 日历脚本向访客发送邀请

    我正在尝试通过 Google Apps 脚本将访客添加到日历活动 并在我的脚本添加访客后立即发送邀请 但我找不到向客人发送电子邮件邀请的方法 var events calendar getEvents start date end date
  • firebase实时数据库安全规则允许特定用户

    我当前的 Firebase 实时安全规则如下 rules users read true indexOn email user id read true write auth null user id auth uid 它们翻译为只有经过身
  • ASIHTTPRequest 支持的 RestKit 对象映射

    我们必须支持一些使用 ASIHTTPRequest 运行的旧代码 但我们希望 RestKit 提供对象映射和核心数据支持 有谁知道有什么方法可以将这两者 粘合 在一起吗 我想象使用 ASIHTTPRequest 来处理请求 然后有人手动将有
  • 双精度重载运算符=

    是否可以重载 double 类型的 运算符 我有以下内容 double operator double a Length b return a b getInches 12 b getFeet 3 2808 0 9144 它抛出以下错误 d
  • 在视图上创建遮罩效果

    我想在 UIView 上创建遮罩效果以完成以下任务 我将在屏幕中显示一个密封的盒子 用户将能够触摸 刮擦 屏幕以显示该图像 UIView 后面的内容 类似于那些彩票 你应该刮掉结果顶部的一些封面材料 如果有人能指出我正确的方向那就太棒了 我
  • 如何更改 UITableView 的高度以适应其动态内容?

    我有一个 UITableView 其中包含一个单元格 该单元格又 包含一个 TTTextEditor Three20 控件 它的所有意图和目的都是 UITextView 我使用 TTTextEditor 以便用户可以输入动态数量的文本 并且
  • xcode 中的调试符号是什么

    什么是调试符号 用法是什么 能够将带有调试符号的应用程序提交到应用程序商店吗 请帮忙 提前致谢 dSym 在您归档项目时生成 您无需为此做任何事情 它允许你符号化你的崩溃日志 否则它只是毫无意义的内存地址 它是构建代码和源代码之间的链接
  • Android 弹出菜单填充父级

    我尝试设置弹出菜单来填充网格上的孔项目 目前它看起来像所附的第一张图片 下一张是我想要的效果 My code private void showPopupMenu View view inflate menu ContextThemeWra
  • 使用 Laravel 5.3 的 Amazon SES 403 Forbidden SignatureDoesNotMatch

    我正在使用 Laravel 5 3 EC2 和 SES 发送电子邮件 配置 邮件 php driver gt env MAIL DRIVER smtp host gt env MAIL HOST smtp mailgun org port
  • 存储性能不良:原因不明

    是什么原因造成的错误的存储属性 成员 resetQueryStatus Employee employeeId 上的 employeeId 例外 例外似乎出现在我的连接点处 Database public class FireEvacuat
  • 获取 18 号下一次出现的日期

    好的 所以我需要使用 PHP 来获取下一次出现 18 号的日期 例如 假设我在 2011 年 12 月 28 日运行了脚本 我需要一些能够输出 2012 年 1 月 18 日的代码 如果是 2011 年 4 月 9 日 我需要将代码吐出 2
  • 为什么括号会导致对象解除绑定?

    当我用括号包围一个新对象调用并立即调用它的方法时 Node 或者一般来说只是 v8 将抛出 TypeError this getName 不是函数 错误 如果我不将它包裹在括号中 则不会抛出任何错误this已正确绑定 function Gr
  • 使用javascript 下载base64 数据| IE11 [重复]

    这个问题在这里已经有答案了 我正在尝试使用 JavaScript 中的 window location href 下载 base64 数据 它在 Chrome 中工作正常 但相同的代码在 IE11 中不起作用 您能否让我知道解决方法或解决方
  • 连接单元格

    我有两个细胞 A 100x2 double 80x2 double 50x2 double B 100x5 double 80x5 double 50x5 double 我怎样才能将它们连接起来以获得类似的东西C cat 2 A B 对于每
  • 将编辑文本字段中的文本添加到电子邮件中

    我有一个应用程序 希望与我们联系 以便用户输入姓名 地址 电话号码和评论部分 然后他们将单击 撰写邮件 按钮 它将自动将文本加载到电子邮件中 已经解决了一些代码 但不确定如何将编辑文本中的文本放入我的电子邮件消息中 任何人对我如何做到这一点