2 zxd 72 zxd_72 于 2013.04.15 13:27 提问

发送邮件时使用 hotmail 和 gmail 出现的问题

我使用Action_Send方法来发送邮件。当我通过点击发送按钮开启activity,得到一个选项发送email是通过 Gmail还是 Hotmail app(hotmail + SEVEN)?
如果选择Gmail的话,activity就会被强行关闭,如果选择Hotmail的话,用户输入的email地址就出现null。
贴出我的代码,哪里出错了呢?

package android.development.tutorial;

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.EditText;

public class EmailActivity extends Activity implements View.OnClickListener
{
    String      receipantAddress,       subject,    message;
    EditText    edtReceipantAddress,    edtSubject, edtMessage;
    Button      btnSend;
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.email);
        initUIComponents();
    }
    private void initUIComponents()
    {
        this.edtReceipantAddress=   (EditText)  findViewById(R.id.edtReceipantAddress);
        this.edtSubject         =   (EditText)  findViewById(R.id.edtSubject);
        this.edtMessage         =   (EditText)  findViewById(R.id.edtMessage);
        this.btnSend            =   (Button)    findViewById(R.id.btnSend);
        btnSend.setOnClickListener(this);
    }
    private void setEmailParameters()
    {
        this.receipantAddress   = this.edtReceipantAddress.getText().toString();
        this.subject            = this.edtSubject.getText().toString();
        this.message            = this.edtMessage.getText().toString();
    }

    public void onClick(View v) 
    {
        String emailAddresses []= {this.receipantAddress};
        setEmailParameters();

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailAddresses );
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, this.subject);
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, this.message);
        this.startActivity(emailIntent);
    }

    protected void onPause() 
    {
        super.onPause();
        EmailActivity.this.finish();
    }
}

1个回答

Baby_Bonnie
Baby_Bonnie   2013.04.15 15:03
已采纳

这里出现了错误:

String emailAddresses []= {this.receipantAddress};
       setEmailParameters();

应该是下面这样,因为你在 setEmailParameters()中做了参数设置

setEmailParameters();
String emailAddresses []= {this.receipantAddress};
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!