Can I use AccountManager to let users sign in with their Google account?
Solution 1
Yes, you can get users to log into their Google Services using their Google credentials, for example, I have an app on Google Tasks and I use the Android AccountManager to let users authenticate themselves using their Google account on the android device (No need for users to enter their password!)
There are some really good examples to get you started:
This is an in-depth look into how you can authenticate based on the users Android credentials, has an example of how things work and how the UI should be: http://www.finalconcept.com.au/article/view/android-account-manager-step-by-step-2
This is an example of getting AccountManager to work with a Google service like Google Tasks: https://developers.google.com/google-apps/tasks/oauth-and-tasks-on-android
- The last example is using the same concept for accessing the Google Picasa service: http://code.google.com/p/google-api-java-client/wiki/AndroidAccountManager
The other options you have is to have users manually enter their username/password. For that you have to use a third party authentication API (like signpost for OAuth) for them to log in.
In my tasks/todo application I provide users both options to sign in, using their android credentials or using third party authentication for users that want to log in using some other account (an account which is not enabled on that device)
Let me know if you have more questions
Solution 2
Although it is a new development, Google Plus Sign-in introduced as part of Google Play Services can also be used. More info can be found at Android developers blog. See example implementation from Banjo app
There seems to be a big limitation - The user need to have Google+ app installed on the device to use this.
Also this is a pretty good blog if someone is interested in implementing the solution.
Related videos on Youtube
Cole
Updated on June 27, 2022Comments
-
Cole almost 2 years
I'm creating an app that will need users to create an account. (Like Facebook or Twitter would require you to.)
BUT, since it's an Android app, should/can I let them sign in with their Google Account using AccountManager or some other service? It'd be very helpful if they could just sign in to their Google account and their settings and other options would be saved to that account.
Main questions summed up:
- Is it possible to let a user just use their Google account in my app?
- If so, do I use AccountManager to have them sign in and save account information/settings?
- What are other options?
- If so, do I use AccountManager to have them sign in and save account information/settings?
- Is it possible to let a user just use their Google account in my app?
-
Cole about 12 yearsSo that screen would come up when they run the app for the first time? (It would say my app's name instead of TasksSample obviously) and then they'd stay signed in to the app or how does that work?
-
Soham about 12 yearsYup, that would come up when you asked for access to use the users credentials on android. Once you get access, you can generate a temporary authorization token based on the users credentials (which you cannot directly see). This temporary token can be used to access the google (or other API like FB/Twitter as the case may be) API on the users behalf. Once the token expires, you can refresh it programmatically to regain access to the service without having to show the user such a screen.
-
android developer almost 12 yearsis there any tutorial available for getting such tokens for gmail&facebook , in order to be able to fetch data from them?
-
Soham almost 12 yearsThere is a very good example on facebook authentication on android here blog.doityourselfandroid.com/2011/02/28/… I can't find any example specific to gmail, but for google services in general (like tasks) you can use AccountManager developer.android.com/training/id-auth/authenticate.html