HI I'm developing an application in wich I want to permit the user to login to my server with his Google account without asking him the credentials because I know that are saved into the AccountManager class. The problem is that I don't know how to autenticate the user because the account ID is just stored in Google's server, so Where can I find an ID for the account and how can I use it to autenticate user? I'd like to follow these steps: user choose one of the stored account, I get an id, send it from the terminal to the server, and I answere that "he trust" this user, after this I save this id in my server and request an auth token to Google just to use it between my server and the application on android device.
Asked
Active
Viewed 7,313 times
7
-
https://androidbeasts.wordpress.com/2015/08/22/android-login-using-google/ – Aakash Aug 26 '15 at 20:31
1 Answers
4
Is this what you want?
List<String> googleAccounts = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
if (account.type.equals("com.google")) {
googleAccounts.add(account.name);
}
}
You can see a more detailed example in the code of the ChromeToPhone app open-sourced by Google: http://www.google.com/codesearch/p?hl=en#JWblrwroAxw/trunk/android/src/com/google/android/apps/chrometophone/MainActivity.java&l=311
Ozone
- 579
- 2
- 5
-
2Plus this, perhaps?: https://github.com/kaeppler/signpost-examples/blob/master/OAuthGoogleExample/src/GoogleMain.java – David Leonard Dec 29 '10 at 10:20
-
Ok, but, if I got the google account, than, to autenticate the user without asking him to insert the credentials, is sufficient the authToken? – g.geloso Dec 29 '10 at 14:48
-
The user won't have to insert the credentials. He will have to allow your app to access this account. – Ozone Jan 03 '11 at 01:58
-
How can I create the request to allow my application to access the account? – g.geloso Jan 12 '11 at 13:37
-
-
@DavidLeonard: The link is broken now, fixed one: https://github.com/mttkay/signpost-examples/blob/master/OAuthGoogleExample/src/GoogleMain.java – abatishchev Dec 30 '13 at 19:18