Vya*_*lav 7 android google-api-client android-googleapiclient google-signin googlesigninapi
我想要为了登录用户我必须使用这段代码:
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
Run Code Online (Sandbox Code Playgroud)
注销
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
disconnect();
}
});
Run Code Online (Sandbox Code Playgroud)
但是当用户重新启动应用程序并且他已经登录(之前没有退出)是否可以检测到这个"当前登录"状态?
显然,可以将"登录"保存在应用程序的设置(共享首选项)中,但是可以使用google api进行检测吗?
Vya*_*lav 10
在这里我找到了解决方案:
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3199 次 |
| 最近记录: |