如何将Firebase Auth UI登录按钮用作onClickListener的id

时间:2018-06-15 20:59:50

标签: android firebase

我在我的应用程序中使用firebase AuthUi for Google登录,我想在我的导航栏中显示名称,电子邮件,个人资料图片等用户信息。 如何设置,当有人点击firebase auth ui中的google登录时,他/她的详细信息可用于在导航栏中显示项目。我知道如何实现这个,但我需要在firebase Ui google登录按钮上设置onClickListener,这就出现了问题。因为对于普通按钮我们使用findViewById(R.id.button_name).setOnClickListener但是在这里我不知道firebase auth ui按钮的id?我是新手,所以也许你觉得我的问题很傻。 请指导我。

1 个答案:

答案 0 :(得分:1)

  

当他/她通过谷歌帐户登录时,如何在导航栏中显示姓名,电子邮件,个人资料图片等人的信息。?

onActivityResult()方法中,请添加以下代码:

public void onActivityResult(int requestCode, int resultCode, Intent result) {
    if (requestCode == GOOGLE_REQUEST_CODE) {
       handleSignInResult(Auth.GoogleSignInApi.getSignInResultFromIntent(result));
    }
}

handleSignInResult()方法应如下所示:

private void handleSignInResult(GoogleSignInResult googleSignInResult) {
    if (googleSignInResult.isSuccess()) {
        GoogleSignInAccount googleSignInAccount = googleSignInResult.getSignInAccount();
        if (googleSignInAccount != null) {
            //Get the data you need from the googleSignInAccount object
        } else {
            Toast.makeText(context.getApplicationContext(), "error", Toast.LENGTH_SHORT).show();
        }
    }
}

您可以在信息here找到更多信息。