2011-01-07 88 views
2

在我的應用程序中,我必須在單擊按鈕時發送郵件。除了「發件人地址」之外,我還有關於發送郵件的所有詳細信息。這個「發件人地址」應該是android手機中配置的Gmail帳戶。我如何獲取這些細節?任何人都可以幫忙嗎?檢索在android中配置的gmail帳戶詳細信息

回答

3

它得到了工作用的AccountManager類。

AccountManager manager = AccountManager.get(this); 
Account[] accounts = manager.getAccountsByType("com.google"); 
Account account = accounts[0]; 

我們可以獲取使用

account.name 

帳戶名和使用

manager.getPassword(account) 
+1

到目前爲止,這是行不通的。我得到以下錯誤:「java.lang.SecurityException:調用者uid 10155是不同於認證者的uid」。我不認爲你可以從第三方應用程序獲得Google密碼。請糾正我,如果我錯了,併發布解決這個問題。謝謝! – 2012-07-30 14:32:10

-1

您可以使用內置的ACTION_SEND意圖使用默認的Android的郵件發送應用程序here你有一個例子。

這是你所需要的零件:

final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
//set the content-type 
emailIntent.setType("plain/text"); 
//set the receivers address 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() }); 
//set the subject 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText()); 
//set the text 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText()); 
Email.this.startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

注:我沒有測試它自己

+0

我在後臺發送郵件的加密密碼。如果我這樣做,然後屏幕會彈出詢問詳細信息...任何人有任何想法?有沒有人使用過GoogleLoginServiceHelper? – Mathew 2011-01-07 11:10:18

相關問題