我使用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();
}
}
這裡出現了錯誤:
String emailAddresses []= {this.receipantAddress};
setEmailParameters();
應該是下面這樣,因為你在 setEmailParameters()
中做了參數設置
setEmailParameters();
String emailAddresses []= {this.receipantAddress};