android - 如何从输入字段发送电子邮件 - 我的代码调试

标签 android eclipse

我好像在这里遇到了问题.. 我有 2 个编辑文本框和一个按钮。当我单击该按钮时,它为我提供了发送消息的方式选项,但是它没有捕获我的输入内容,而是发出一条奇怪的消息,说这是一个 Testandroid.widget.EditText@47b84299android.widget.EditText@47b8f0d9 .它也不会转到电子邮件并填写主题标题。

这是我的代码。

package com.emailmetest;

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

public class Activity1 extends Activity implements OnClickListener {
    Button sendemail;
    TextView input1, input2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        sendemail =(Button)findViewById(R.id.sendemail);
        input1 = (TextView)findViewById(R.id.input1);
        input2 = (TextView)findViewById(R.id.input2);
        sendemail.setOnClickListener(this);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"test@hotmail.com"});
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_TEXT   , "\nThis is a Test" + input1 + input2);
        try {
            startActivity(Intent.createChooser(i, "Send via..."));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(this.getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
    }
}

最佳答案

尝试:

i.putExtra(Intent.EXTRA_TEXT   , "\nThis is a Test" + input1.getText().toString() + input2.getText().toString());

关于android - 如何从输入字段发送电子邮件 - 我的代码调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6259748/

相关文章:

android - 如何使用 Android 的身份验证标签进行 GCM 加密

eclipse - ActionScript-Eclipse/FlashBuilder : How do I change the color of/prevent the selection of matching selected text?

Eclipse 指标插件

android - Flutter 与来自 snap 的 android studio

java - Collection.contains 产生错误的结果

Java Maven exec-maven-plugin 带有限定名称的 ClassNotFoundException

java - 简单的 java 程序在 Eclipse 中没有输出

java - 通过调用另一个类进行 JUnit 测试

java - 在 Java 中获取特定时间段后的日期

android - 网络.sqlcipher.database.SQLiteException : not an error: