2011-04-25 97 views
9

我正在製作一個應用程序,在該應用程序中,我將向我的客戶提供反饋功能。爲了實現這一目標,我創建了一個小對話框,用戶可以在其中輸入反饋並將其發送給我的郵件ID。我嘗試了一些我在互聯網上發現的代碼片段,但每當我嘗試從模擬器或實際設備發送一封電子郵件時,我都會收到錯誤「沒有應用程序可以執行此操作」。Android - 嘗試發送電子郵件時出現錯誤「沒有應用程序可以執行此操作」?

這裏是我的代碼: -

public void emailDialog() 
{ 
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); 
    alertDialog.setTitle("Feedback"); 
    alertDialog.setMessage("Please tell us that what you feel about our product. If you are facing any problem or found any bug then please report to us. Your review is important to us. Thanks!!"); 
    final EditText input = new EditText(this); 
    input.setLines(8); 
    alertDialog.setView(input); 
    alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
      String value = input.getText().toString(); 
      String address = "[email protected]"; 
      String subject = "FeedBack"; 
      final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, value); 
      CompleteTaskManager.this.startActivity(Intent.createChooser(emailIntent, "Send Email..")); 
     } 
    }); 
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
     // Canceled. 
     } 
    }); 
alertDialog.show(); 
} 

請幫助。

+0

我可以理解你在可能沒有電子郵件應用程序的模擬器上獲取它。然而,在一個令人困惑的設備上。您能否使用LogCat仔細檢查它是否與設備和仿真器上的錯誤相同。 – 2011-04-25 14:00:22

+0

@Jim是的,這就是我想知道的。我認爲這是因爲我的emulaotr沒有電子郵件應用程序,但是當我在真實設備上嘗試它時,它提示我出現同樣的錯誤和奇怪的是,我的電子郵件應用程序已完全配置,並且在我的設備上正常工作,這個錯誤。 – Varundroid 2011-04-25 14:09:17

回答

18

我認爲你需要設置意圖對象的類型。你可以試試下面的

emailIntent.setType("message/rfc822"); 

emailIntent.setType("text/plain"); 
+0

thansk男人你是一個救星大聲笑,請不要笑我愚蠢的錯誤:P ..... btw現在一切工作正常,但我沒有得到我的電子郵件應用程序的「到」字段中的地址字段。任何想法爲何如此? – Varundroid 2011-04-25 14:31:17

+2

沒問題...地址變量必須是我想的字符串數組。像String address = {「[email protected]」}; – Josnidhin 2011-04-25 14:41:41

0

如果有人試圖從XML首選做到這一點,我通過在偏好元素與添加的意圖不如行動ACTION_SENDTO和數據的mailto做到了這一點: [email protected]。 希望這可以幫助某人。

相關問題