我发现,为了在用户中签名,我必须使用以下代码:
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);发出信号
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
disconnect();
}
});但是当用户重新启动应用程序时,他已经登录了(之前没有登录),是否有可能检测到这个“当前登录”状态?
显然,在应用程序的设置(共享首选项)中保存“登录”是可能的,但是使用google的方法在哪里呢?
发布于 2016-02-04 10:19:47
这里我找到了解决方案:
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, "Got cached sign-in");
GoogleSignInResult result = opr.get();
handleSignInResult(result);
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
showProgressDialog();
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
hideProgressDialog();
handleSignInResult(googleSignInResult);
}
});
}发布于 2018-01-05 05:35:54
在这里,我找到了这个问题的简单解决方案
GoogleSignInAccount lastSignedInAccount= GoogleSignIn.getLastSignedInAccount(context);
if(lastSignedInAccount==null){
// user has already logged in, you can check user's email, name etc from lastSignedInAccount
String email = lastSignedInAccount.getEmail();
}else{
// user is not logged in with any account
}https://stackoverflow.com/questions/35195673
复制相似问题