0

我正在调用一个意图,即从字符串数组中设置“收件人”字段的 GMail 模板没有问题,但我无法让它设置“主题”和“文本”字段。

希望有人能看到我哪里出错了

这是我的代码:

package com.example.flybase2;

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

public class ContactsEmail extends Activity implements OnClickListener{

    String emailPassed;
    String emailAdd;
    String emailSub;
    String emailMess;
    EditText setEmailAddress;
    EditText setEmailSubject;
    EditText setEmailMessage;
    Button btnSendEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    setContentView(R.layout.emaillayout);

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) {
        emailPassed = extras.getString("passedEmailAdd"); 
    }

    setEmailAddress = (EditText) findViewById (R.id.inputEmailAddress);
    setEmailAddress.setText(emailPassed);
    setEmailSubject = (EditText) findViewById (R.id.inputEmailSubject);
    setEmailMessage = (EditText) findViewById (R.id.inputEmailMessage);

    emailAdd = setEmailAddress.getText().toString();
    emailSub = setEmailSubject.getText().toString();
    emailMess = setEmailMessage.getText().toString();

    btnSendEmail = (Button)findViewById(R.id.btnSendEmail);

    btnSendEmail.setOnClickListener(this);
    }

    @Override
    public void onClick(View sendEmailClick) {
        Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); 
        sendEmailIntent.setType("plain/text");
        sendEmailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {emailAdd});  
        sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSub); 
        sendEmailIntent.putExtra(Intent.EXTRA_TEXT, emailMess); 
        startActivity(Intent.createChooser(sendEmailIntent, "Send mail..."));   
    }
}   
4

1 回答 1

0

试试这个。

实际上,当活动创建时,您会获得这些编辑文本的值。那时这些值都是空的。所以你需要在onclick方法中编写这些。

当您单击按钮时,您将获得当前的编辑文本值。

我希望这能解决你的问题。

@Override
public void onClick(View sendEmailClick) {
    emailAdd = setEmailAddress.getText().toString();
    emailSub = setEmailSubject.getText().toString();
    emailMess = setEmailMessage.getText().toString();
    Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); 
    sendEmailIntent.setType("plain/text");
    sendEmailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {emailAdd});  
    sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSub); 
    sendEmailIntent.putExtra(Intent.EXTRA_TEXT, emailMess); 
    startActivity(Intent.createChooser(sendEmailIntent, "Send mail..."));
}

onCreate()并从方法中删除这三行。

emailAdd = setEmailAddress.getText().toString();
emailSub = setEmailSubject.getText().toString();
emailMess = setEmailMessage.getText().toString();
于 2013-02-05T17:50:56.993 回答