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

时间:2011-06-07 01:17:48

标签: android eclipse

我好像在这里遇到了一个问题..我有2个edittext框和一个按钮。当我点击按钮时它给了我一个选择以什么方式发送消息,但是它没有捕获我的输入但是发出一个奇怪的消息说这是一个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();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

尝试:

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