我正在尝试查询我的Google Firestore数据库以检索userUID
字段=当前用户的数据。众所周知,我已经对userUID
进行了硬编码,尽管对于任何登录的用户,它都必须更改为唯一。我的代码如下:
public void viewMyAttendance(View v) {
attendanceRef3.whereEqualTo("userUID", "rJe547HwBrWFWa90zVdUl6PYfo03")//("userUID", FirebaseAuth.getInstance().getCurrentUser())
.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
String data = "";
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Attendance attendance = documentSnapshot.toObject(Attendance.class);
//attendance.setDocumentID(documentSnapshot.getId());
//Session session = documentSnapshot.toObject(Session.class);
String sessionID = attendance.getSessionID();
String studentID = attendance.getUserUID();
//String documentID = session.getDocumentID();
data += "Session ID: " + sessionID + "\n" + "User UID: " + studentID + "\n\n";
}
textViewData.setText(data);
}
});
}
答案 0 :(得分:0)
当前,我已经为一个用户进行了硬编码的userUID,我希望每个登录的用户都可以更改它
要解决此问题,您需要使用Firebase Authentication,以便像这样从uid
对象获取FirebaseUser
:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();