[英]How to check if the user is successful logged out of the Google Sign In Android?
I am using Google Sign in for authentication. 我正在使用Google登录进行身份验证。 Following the tutorial, I am able to log in. Now I want to log out the user.
遵循该教程,我可以登录。现在,我要注销用户。 I got the code for logging out.
我得到了注销的代码。 But how to do I know that the logout is success or fail?
但是我如何知道注销成功还是失败?
private void signOut() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
// What code should I write here to see if the user has successfully logged out. If not, then I need to display an error message.
}
});
}
Google can return 5 types status. Google可以返回5种状态。 Following are the statuses along with the status codes:-
以下是状态以及状态代码:-
SUCCESS(0), INTERNAL_ERROR(8), INTERRUPTED(14), TIMEOUT(15), CANCELED(16) 成功(0),内部错误(8),中断(14),超时(15),已取消(16)
So you can check for status.getStatusCode()
on logout and validate against the above mentioned statuses. 因此,您可以在注销时检查
status.getStatusCode()
并针对上述状态进行验证。
Just use 只需使用
status.toString()
and log it to find out what details it contains. 并记录下来以找出其中包含的详细信息。 Then according to it you can use the below methods to check if you have been successfully logged out.
然后根据它可以使用以下方法检查您是否已成功注销。
status.getStatusCode();
status.getStatusMessage();
Both methods are self explanatory. 两种方法都是不言自明的。
I found a better approach to the question 我找到了解决这个问题的更好方法
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
// user logged out successfully
} else {
// the logout was not sucessful.
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.