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