gpt4 book ai didi

android - 如何监控android Google登录中的取消状态?

转载 作者:行者123 更新时间:2023-12-05 00:17:18 26 4
gpt4 key购买 nike

enter image description here

我引用以下链接集成Google登录,这是最新的Google登录。 https://developers.google.com/identity/sign-in/android/start?hl=zh-cn

但是这个版本无法取消状态监听,就像上图,如果用户点击区域之外的对话框,如何监听取消事件?

官方优惠代码如下:

private void handleSignInResult(GoogleSignInResult result) {
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acct = result.getSignInAccount();
mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
updateUI(true);
} else {
// Signed out, show unauthenticated UI.
updateUI(false);
}
}

但是如何监听取消呢?

最佳答案

看看我的例子:

    Log.d("result=", String.valueOf(result));
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();

try {
Log.i("Signin", acct.getDisplayName());
}
catch (NullPointerException e) {
Log.d(TAG, "Error retrieving some account information");
}
} else {
Status status = result.getStatus();
int statusCode = status.getStatusCode();
Log.d("StatusCode", String.valueOf(statusCode));
if (statusCode == GoogleSignInStatusCodes.SIGN_IN_CANCELLED) {

}
else if (statusCode == GoogleSignInStatusCodes.SIGN_IN_FAILED) {

}
else {

}
}

您可以使用 result.getStatus(); 检索状态代码现在,您可以将 else 部分中的 statusCode 与 GoogleSignInStatusCodes.SIGN_IN_CANCELLED

进行比较

关于android - 如何监控android Google登录中的取消状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38896209/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com