I am trying to get a field called services which is an array of Strings from the Firestore document.
I am doing it like this:
fAuth = FirebaseAuth.getInstance();
fStore = FirebaseFirestore.getInstance();
fAuth.signInWithEmailAndPassword(Etemail.getText().toString(), Etpassword.getText().toString()).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
Uid = authResult.getUser().getUid();
checkUserAccessLevel(Uid);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(LoginActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
private void checkUserAccessLevel(String uid) {
DocumentReference df = fStore.collection("Users").document(uid);
df.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
List<String> services = new ArrayList<>();
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Map<String, Object> map = document.getData();
for (Map.Entry<String, Object> entry : map.entrySet()) {
services.add(entry.getValue().toString());
}
Log.d(TAG, services.toString());
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
}
This is the screenshot of Firebase Firestore DB!
Please help me to achieve the task.
