【发布时间】:2020-08-20 19:58:28
【问题描述】:
我需要返回从文档快照中检索到的值。我可以在 LOG 中看到正确的值,但由于它超出了范围,并且仅在 onComplete 中,我无法访问它。
你能帮忙吗?
public String getCoEmail() {
coUserReference = db.collection("users").document(email);
coUserReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String coEmail = document.getString("coEmail");
Log.d(TAG, "DocumentSnapshot data: " + document.getString("coEmail"));
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
return coEmail;
}
【问题讨论】:
标签: java android google-cloud-firestore