开发者

retrieve gmail account details configured in android

In my application, I have to send a mail when a button is clicked. I have all details for sending the mail except the "from address". This "from address" should be the gmail account configured in the android phone. How can I fetc开发者_StackOverflowh those details? Can anyone please help?


It got worked by using AccountManager class.

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

We can fetch account name using

account.name

and the encrypted password using

manager.getPassword(account)


You can use the built-in ACTION_SEND intent to use default android's mail sending app, here you have an example.

This is the part you would need:

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..."));

Note: I haven't tested it myself

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜