Leo S :
When uploading the post, I'm trying to get the postKey and upload it to dynamiclink, but I'm getting wrong postKey (first 6 characters in the key are right then the rest are wrong). How can I get the right postKey when uploading the post?
This is my post including the right postKey:
And this is what I'm getting -LYelE9TdCU73qW1Xisc , which also is not a key for any other posts.
My code
String postKey = FirebaseDatabase.getInstance().getReference().child("posts").push().getKey();
Log.i("postkey for dynamiclink",postKey);
Very much appreciated your help!
Peter Haddad :
In your code, you are creating another postKey
by using push().getKey()
.
To retrieve the key, that is already in the database, try the following:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("posts");
reference.orderByChild("title").equalTo("test").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String keys=datas.getKey();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});