Reputation: 73
Well using Koltlin i'm trying to do a very simple thing, so i thought... i want to set a textview.text with the value of the "file" field i stored in firebase database. this is my database :
I get the single user related content but like this
key - enGKzLMIE0czXUWrcUeCnfKLQ7r1 value: {file=https://firebasestorage.googleapis.com/v0/b/lci9project.appspot.com/o/Avatars%2Fde4d49b5-20e7-4801-80d0-2458aafc5d23?alt=media&token=ffd9ab4f-73c7-49b5-9090-b2c5ff05e3e1, userid=Lasyyyl}
with this code:
val uidref= FirebaseAuth.getInstance().currentUser?.uid
FirebaseDatabase.getInstance().reference.child("users/$uidref")
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
}
override fun onDataChange(dataSnapshot: DataSnapshot) {
val key = dataSnapshot.getKey()
val value = dataSnapshot.getValue()
println("key - $key value: $value")
But i cant seem to get just the "file" value ...
Upvotes: 1
Views: 1417
Reputation: 10497
If you only want the file Strong there are 2 options
datasnapshot.getChild("file").getValue(String.class)
Or you can just ask for the file attribute
...reference.child("users/$uidref").child("file")
//You can also "users/$uidref/file"
Upvotes: 1
Reputation: 80914
To get the value of the file change the following:
val value = dataSnapshot.getValue()
Into this:
val value = dataSnapshot.child("file").getValue(String::class.java)
Upvotes: 1