如何从 firestore - android studio 中的文档中知道 ID?
在这段代码中,你可以看到,我如何创建一个新帐户,这里我想用用户id创建新文档,但他没有用这个id创建,他放了其他一个。
if (!confirmarCampos(nome,email,eNdata,id,password)){
fAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
pessoa.put("nome", nome);
pessoa.put("email", email);
pessoa.put("ano", eNdata);
pessoa.put("idBicicleta", id);
pessoa.put("distancia", 0);
pessoa.put("pontos", 0);
db.collection("pessoa")
.document(user_id) //here i put the reference from user id
.set(pessoa)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(Registar.this,"Perfil Criado com Sucesso", Toast.LENGTH_SHORT).show();
}else{
String erro = task.getException().getMessage();
Toast.makeText(Registar.this,"ERRO :" + erro, Toast.LENGTH_SHORT).show();
}
}
});
Intent iConfirmar = new Intent(Registar.this, Login.class);
startActivity(iConfirmar);
finish();
}else{
Toast.makeText(Registar.this, "O email já existe", Toast.LENGTH_LONG).show();
}
}
});
}
在这里您可以看到新用户的 ID。
在这里您可以看到新文档中的 ID,它与用户 ID 不同。
因此,我无法使用文档内的值,因为我想将这些值设置到 profile.xml 中。
文档 ID:
感谢您的帮助。
最佳答案
这里,你是如何获得user_id的?
尝试以这种方式获取用户 ID,
if (task.isSuccessful()) {
// Sign up in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
user_id = user.getUid();
}
}
关于java - Firestore - 如何从文档中知道 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56943719/