首先我對firebase數據庫非常陌生。我正在研究如何從firebase中檢索當前的UID(即currenty登錄到的),並通過oncreate將其插入到firebase的子項以及值中。如何從Firebase中檢索UID並將其添加到Firebase的子項目DB
我試圖推送mycurrent UID,它對Firebase有價值。我無法將其推送到Firebase。這裏是我的火力結構:
(例如,UID Fo2SfEfryWEjmxr4yIQwM5LQQx2
和消防基礎價值'720'
)
嘗試後,我仍然無法得到以下代碼來檢索UID。我在(new ValueEventListener()
以及這條線路上遇到了問題。
Map<String, Queue> data = postSnapshot.getValue(new GenericTypeIndicator<Map<String, Queue>>() {});
這裏是我的參考
mRef = new Firebase("https://sunwayfinancequeue.firebaseio.com/");
mRef.child("UserQueue");
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Queue queue = postSnapshot.getValue(Queue.class);
System.out.println(Queue.getTotalqueue() + " - " + Queue.getServingqueue());
Map<String, Queue> data = postSnapshot.getValue(new GenericTypeIndicator<Map<String, Queue>>() {});
Map.Entry<String, Queue> entry = data.entrySet().iterator().next();
String uid = entry.getKey();
Log.d("Firebase UID ", uid);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
的onCreate這裏是我的構造函數:
public class Queue {
private static double servingqueue;
private static double totalqueue;
private static String uid;
public Queue(Double servingqueue, Double totalqueue) {
Queue.servingqueue = servingqueue;
Queue.totalqueue = totalqueue;
}
public static double getServingqueue() {
return servingqueue;
}
public static void setServingqueue(double servingqueue) {
Queue.servingqueue = servingqueue;
}
public static double getTotalqueue() {
return totalqueue;
}
public static void setTotalqueue(double totalqueue) {
Queue.totalqueue = totalqueue;
}
public static String getUid() {
return uid;
}
public static void setUid(String uid) {
Queue.uid = uid;
}
}
感謝您的回覆,我設置了不久前的Firebase身份驗證。但我遇到了將uid發送回firebase db的問題以及我在商店中存儲的值。 –