检查用户是否使用谷歌帐户

时间:2016-01-23 05:52:43

标签: android

我正在制作一个使用谷歌提供登录的Android应用程序。我已成功登录。现在我想在下次打开应用程序时将用户直接带到仪表板。那么如何检查他是否已经使用谷歌帐户登录。

1 个答案:

答案 0 :(得分:2)

使用silentSignIn中所示的GoogleSignInApi,如@Override public void onStart() { super.onStart(); OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient); //If the user is signIn and cached or else try again logging Log.d(TAG, "Got cached sign-in|| " + opr.isDone()); if (opr.isDone() && BankerPrefs.isLogin(this)) { GoogleSignInResult result = opr.get(); handleSignInResult(result); } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); handleSignInResult(result); } } 所示。这很棒。并且还使用sharedPreference将状态维护为loggedIn或loggedOut。

// Right now, Constants.ttt contains {"aa", "bb", "cc"}
Constants.ttt[1] = "foobar";
// Right now, Constants.ttt contains {"aa", "foobar", "cc"}
相关问题