Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新firebase(android)中用户的displayname_Android_Firebase_Firebase Authentication - Fatal编程技术网

更新firebase(android)中用户的displayname

更新firebase(android)中用户的displayname,android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,我正在使用firebase创建一个登录屏幕项目。我试图用下面的代码更新用户的显示名,但它没有更新显示名。帮帮我 FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(name)

我正在使用firebase创建一个登录屏幕项目。我试图用下面的代码更新用户的显示名,但它没有更新显示名。帮帮我

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                .setDisplayName(name)
                .build();
        user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if(task.isSuccessful()){
                    Toast.makeText(VerifyUser.this,"Name updated successfully",Toast.LENGTH_LONG).show();
                    startActivity(new Intent(VerifyUser.this,MainActivity.class));
                }else
                    Toast.makeText(VerifyUser.this,"Name update Failed",Toast.LENGTH_LONG).show();
            }
        });
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates=新建UserProfileChangeRequest.Builder()
.setDisplayName(名称)
.build();
user.updateProfile(profileUpdates).addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
Toast.makeText(VerifyUser.this,“名称更新成功”,Toast.LENGTH_LONG.show();
startActivity(新意图(VerifyUser.this、MainActivity.class));
}否则
Toast.makeText(VerifyUser.this,“名称更新失败”,Toast.LENGTH_LONG.show();
}
});

您需要在登录或验证电子邮件和密码后立即更新用户配置文件

我知道我迟到了,但对于子孙后代来说,要更新firebase上的用户属性,他们需要先登录

比如:

 mAuth.signInWithCredential(credential)
            .addOnCompleteListener(LordRegister.this,
                    new OnCompleteListener<AuthResult>() {

                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if (task.isSuccessful()) {
                                //verification successful we will start the profile activity
                                FirebaseUser user = task.getResult().getUser();
                                String name = nameInput.getText().toString().trim();
                                //user.updateProfile()
                                UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                                        .setDisplayName(name)
                                        .build();
                                user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if(task.isSuccessful()){
                                            Intent intent = new Intent(LordRegister.this, LordHome.class);
                                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                            startActivity(intent);
                                        }else
                                            Toast.makeText(LordRegister.this,"Name update Failed, try again",Toast.LENGTH_LONG).show();
                                    }
                                });

                            } else {

                                //verification unsuccessful.. display an error message

                                String message = "Somthing is wrong, we will fix it soon...";

                                if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                    message = "Invalid code entered...";
                                }
                                Toast.makeText(LordRegister.this,message,Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
}
mAuth.signInWithCredential(凭证)
.addOnCompleteListener(LordRegister.this,
新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
//验证成功,我们将启动配置文件活动
FirebaseUser=task.getResult().getUser();
字符串名称=nameInput.getText().toString().trim();
//user.updateProfile()文件
UserProfileChangeRequest profileUpdates=新建UserProfileChangeRequest.Builder()
.setDisplayName(名称)
.build();
user.updateProfile(profileUpdates).addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
意向意向=新意向(LordRegister.this,LordHome.class);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TASK);
星触觉(意向);
}否则
Toast.makeText(LordRegister.this,“名称更新失败,请重试”,Toast.LENGTH_LONG.show();
}
});
}否则{
//验证失败..显示错误消息
String message=“有问题,我们很快就会解决…”;
if(FirebaseAuthInvalidCredentialsException的task.getException()实例){
message=“输入的代码无效…”;
}
Toast.makeText(LordRegister.this,message,Toast.LENGTH_SHORT).show();
}
}
});
}

如上所述,我使用用户电话号码登录,或者首先验证用户,然后更新名称或任何其他属性。

我也面临同样的问题,因此我使用Firebase admin SDK更改displayName