Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Pushid与Uid Firebase android一起使用_Android_Firebase_Firebase Realtime Database_Firebase Authentication - Fatal编程技术网

如何将Pushid与Uid Firebase android一起使用

如何将Pushid与Uid Firebase android一起使用,android,firebase,firebase-realtime-database,firebase-authentication,Android,Firebase,Firebase Realtime Database,Firebase Authentication,我正在尝试从android应用程序向Firebase添加此结构中的数据: UserID: { uniqueId: { Data1: "" Data1: "" } uniqueId: { Data2: "" Data2: "" } } 但是我正在努力让用户ID与uniqueID一起工作,请有人帮忙 DatabaseReference mypostref = databaseReference.push(); datab

我正在尝试从android应用程序向Firebase添加此结构中的数据:

UserID: { 
  uniqueId: {
     Data1: ""
     Data1: ""
   }
  uniqueId: {
     Data2: ""
     Data2: ""
   }
}
但是我正在努力让用户ID与uniqueID一起工作,请有人帮忙

DatabaseReference mypostref = databaseReference.push();
        databaseReference.child(user.getUid()).setValue(Personname: "Data", personaddress: "Data");
我已经设法(我想)通过创建这个:mypostref获得了唯一的id,但是我如何将两者连接在一起呢?Own-its在下面的代码中运行良好,但它仅与Uid一起使用。我想把它进一步细分,这样每个数据集都有唯一的ID

 databaseReference.child(user.getUid()).setValue(Friend1Name: "Data", Friend1Address: "Data");
如果我的问题不清楚,请告诉我。谢谢。

试试这个:

DatabaseReference parentUserNode = databaseReference.child(user.getUid);
//Edit: Added way of saving the key generated by push
String keyFromPush = parentUserNode.push().getKey();
parentUserNode.child(keyFromPush).setValue(/*Add whatever value you want in here*/).
这将创建如下节点:

uid: { 
  uniqueid01: {
    ...
  }
  uniqueid02: {
   ...
  }
}

希望这能有所帮助。

你说的“将两者结合在一起”是什么意思?是否要将
push()
方法中的按键字符串与
user.getUid()
中的字符串组合为对象的一个字符串键?为什么不将其与用户的uid一起保存为对象的键,而不是将uid与push键组合?谢谢,这就是我想要的:)快速问,有没有办法在android中保存pushId的记录或将ID存储在变量中以供以后使用?顺便问一下,需要等待18分钟才能接受答案,遗憾的是,我需要15个代表才能投票。这一行显示不兼容的类型:String keyFromPush=parentUserNode.push();抱歉,我必须在更新您的答案之前复制