2011-12-29 117 views
2

我編寫了一個使用Action_Send發送電子郵件的小應用程序。 當我通過按發送按鈕開始活動時,我可以選擇使用Gmail或Hotmail應用程序(hotmail + SEVEN)發送電子郵件。 如果我選擇Gmail,則該活動已強制關閉。 如果我選擇Hotmail,用戶輸入的電子郵件地址顯示爲NULL;電子郵件使用Gmail和電子郵件地址的活動崩潰在hotmail上顯示爲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(); 
    } 

} 

回答

2

只是一個愚蠢的錯誤在這行:

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

它應該是下面的,因爲你正在做的setEmailParameters內​​部參數設置()。

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

+1 - 第二組眼睛總是有幫助。這就是我喜歡結對編程的原因。 – 2011-12-29 13:52:30

+0

@MatNadrofsky Thanx :) – 2011-12-29 14:02:56

+0

你保存了一天,帕雷什!完全忽略了這個:) – 2011-12-29 14:50:18

相關問題