Tuesday 1 February 2011

Login using your Google account

Since 99,99% of all android users have a gmail account it can sometimes be useful to use that email address as a login or username for the users of your app. Here's how to do it:

protected AccountManager accountManager; accountManager = AccountManager.get(getApplicationContext()); Account[] accounts = accountManager.getAccountsByType("com.google");
The variable accounts will now hold an array of all the google accounts ever used on the phone. So to get the first account/email address registered on the phone try something like

konto = accounts[0].name;
You can then use the account name/email address for login, shoutbox name, etc. etc.

No comments:

Post a Comment