场景是:json 对象从 rest api 上传并由 android 应用程序访问。
问题:在每次上传时,对象都存储在唯一的推送 ID 下。这是可变的,在接收端是未知的。所以完整的路径是未知的。
在给定的部分代码中:
mRootRef = new Firebase("https://solvewa2y.firebaseio.com");
Firebase messagesRef=mRootRef.child(postId);
我需要用一些东西替换 postId,这样我就可以存储对象,而不管唯一 ID 或每次获取唯一 ID 的方法
最佳答案
答案很简单。在找到这个答案之前,我一直在努力寻找事件监听器的解决方案 here
//Create new reference calling push creates the unique key in firebase database but has no data yet
DatabaseReference mypostref = databaseRef.push();
//Use the new reference to add the data
mypostref.setValue(data);
//Call getKey on the ref - you must have 'key' in your data class
String mypostref.getKey());
关于android - 在 Firebase 中获取唯一推送 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522831/