[英]In Android, get recently created user's UID in Firebase
I am attempting to create a user and for adding additional information I want to get the UID of recently created user in Android. 我试图创建一个用户,并添加其他信息,我想获取Android中最近创建的用户的UID。
I have a JSON object of users in which i store user information under user's unique UID. 我有一个用户的JSON对象,我将用户信息存储在用户的唯一UID下。
I want to store user's additional information as soon as the user is created. 我想在创建用户后立即存储用户的其他信息。 In the
createUserWithEmailAndPassword()
method it says that if user is successfully created, it is logged in. 在
createUserWithEmailAndPassword()
方法中,它表示如果成功创建了用户,则将其登录。
I tried getting the UID but it was not possible. 我尝试获取UID,但不可能。 I have created a Progress Dialog before creating and I dismiss it after saving the user information in the real time database.
我在创建之前创建了一个“进度对话框”,在将用户信息保存在实时数据库中之后将其关闭。
If I understand well your situation, you can get the user id in this way: 如果我很了解您的情况,您可以通过以下方式获取用户ID:
I get the recently created user with task.getResult().getUser().getUid()
我通过
task.getResult().getUser().getUid()
获得了最近创建的用户
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(SignUpActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (!task.isSuccessful()) {
/*Toast.makeText(SignUpActivity.this, "Authentication failed." + task.getException(),
Toast.LENGTH_SHORT).show();*/
} else {
// THE USER ID
task.getResult().getUser().getUid();
}
}
});
After the task has been successfully completed you can get the users UID calling the following user.getUid(). 成功完成任务后,您可以获取用户UID,该用户ID调用以下user.getUid()。
If you followed the documentation you should have a class variable defined such as "FirebaseUser user;". 如果您遵循文档,则应该定义一个类变量,例如“ FirebaseUser user;”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.