RSS

Code to fetch account details in Android

05 Sep

We can fetch account name using:
account.name;
and the encrypted password using:
manager.getPassword(account);

one more way:
public String getUsername()
{
AccountManager manager = AccountManager.get(this);
Account[] accounts = manager.getAccountsByType(“com.google”);
List<String> possibleEmails = new LinkedList<String>();

for (Account account : accounts) {
// TODO: Check possibleEmail against an email regex or treat
// account.name as an email address only for certain account.type values.
possibleEmails.add(account.name);
}

if(!possibleEmails.isEmpty() && possibleEmails.get(0) != null){
String email = possibleEmails.get(0);
String[] parts = email.split(“@”);
if(parts.length > 0 && parts[0] != null)
return parts[0];
else
return null;
}else
return null;
}

Advertisements
 
Leave a comment

Posted by on September 5, 2011 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: