OpenID for android apps that require SignIn

前端 未结 3 1061
庸人自扰
庸人自扰 2020-12-23 10:51

I am a fresh developer on Googles Android Platform - my HTC Desire arrived last week.

Now i need a way to sign in to my existing application (Java, currently running

3条回答
  •  囚心锁ツ
    2020-12-23 11:08

    I think what you want is to use AccountManager

    To find out what type the google account is, use something like:

    AuthenticatorDescription[] types = mAccountManager.getAuthenticatorTypes(); //
    for (AuthenticatorDescription type : types) {
      Log.d("account types", type.type);
    }
    

    Then do something like

    AccountManager mAccountManager = AccountManager.get(context);
    Account[] mAccounts = AccountManager.get(context).getAccountsByType("com.google");
    // Choose which account to use if there are multiple google accounts registered, save to Account mAccount
    AccountManagerFuture response = mAccountManager.getAuthToken(mAccount, type, options, activity, mCallback, mHandler); // define callback and handler yourself for where to return
    

    When the user reaches mCallback in your mHandler, the login process is done. The usual google login dialogue will be used if the user is not already logged in to his/her Google account.

    Try it out for yourself and let me know if it helped you!

提交回复
热议问题