简体   繁体   中英

Can I get users in my app to sign in with Google?

I've looked at this and this but they make it sound like it has to be a website (not an Android app) to use Google to Sign in, rather than a database of my own.

So, is it possible to use Google to sign in, and how does one go about using Google to make an account in an Android app? Sorry if this question is vague, but I don't know what else to ask.

Well you can try using the AuthenticatorManager and use the Google Account that is already linked at your device, this also applied to others accounts Twitter, LinkedIn, Facebook, etc.

You can find on Android code sample, SampleSyncAdapter , this can get you started, if you are in a hurry and already experiment with Native Account and Sync Adapter you may wanna try the example from Google Code 2011 that uses C2DM and AppEngine as you can see on this post they ask the account for them to be connected on.

No need to use OpenID when you can use the phone accounts, altough you have to use that mechanism on your remote repository OpenID to send the token to the server.

It is possible to use Google to sign in to Android application.

The Android AccountManager class has access to this. Reference: http://developer.android.com/reference/android/accounts/AccountManager.html

This class provides access to a centralized registry of the user's online accounts. The user enters credentials (username and password) once per account, granting applications access to online resources with "one-click" approval.

You can follow the below code for retrieving the Google accounts associated with the phone.

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);
  }
}

And add the "GET_ACCOUNTS" permission in the AndroidManifest.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM