Nay*_*air 1 android push unique firebase
场景是:json对象从rest api上传,并由android应用程序访问.
Isuue:在每次上传时,对象都存储在唯一的推送ID下.这是可变的,在接收端不知道.所以完整的路径是未知的.
在给定的代码部分:
mRootRef = new Firebase("https://solvewa2y.firebaseio.com");
Firebase messagesRef=mRootRef.child(postId);
Run Code Online (Sandbox Code Playgroud)
我需要用一些东西替换postId,这样我就可以存储对象而不管唯一的id或者每次获取唯一id的方法
小智 7
答案很简单.我一直在努力寻找一个带有eventlisteners的解决方案,直到我在这里找到了这个答案
//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());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8108 次 |
| 最近记录: |