How I can know the ID from a document in firestore - android studio?
In this code, you can see, how I create a new account, here I want to create the new document with the user id, but he don't create with this id, he put other-one.
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();
}
}
});
}
Here you can see the id from the new user.
Here you can see the id from the new document it's different from the user id. And because of that, I can't work with the values inside of a document, because I want to set the values into a profile.xml .
Document id : Thank you for helping.
here, how did you get the user_id?
try to get user id like this way,
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.