我正在使用Firebase开发我的安卓应用,并已经实现了Google账户登录。但是,当弹出“选择Google账户”对话框时,如果你点击其他地方,它就会自动关闭。有没有办法让这个对话框不可取消?
我正在使用Firebase开发我的安卓应用,并已经实现了Google账户登录。但是,当弹出“选择Google账户”对话框时,如果你点击其他地方,它就会自动关闭。有没有办法让这个对话框不可取消?
@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);
}
}
点击外部事件会导致状态码返回为12501,我们可以将其用于验证并再次调用登录提示,因为登录失败了。
以下代码应该可以完成工作:
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
// Signed in successfully, show authenticated UI.
Toast.makeText(this, "Success!", Toast.LENGTH_SHORT).show();
getUserAccountInfo();
} catch (ApiException e) {
Log.e(TAG, "signInResult:failed code=" + e.getStatusCode());
if(e.getStatusCode()==12501) { // check for sign-in cancellation
signIn(); // if cancelled then call signIn() again
}
}
}