i'm creating chat app on android using firebase database , java. whenever user first registered, stores username database under nodes "user", userid, "profile", "username". username stored using user class. username value stored. when try
mdatabase.child("users").child(userid).child("profile").child("username").tostring();
this gives me path username not username itself. know how value of username itself?
edit: gives me error when run
datasnapshot.child("users").child(muserid).child("profile").child("username").getvalue().tostring();
here firebase database shows under userid.
you aren't getting value properly. need attach listener child , updates. this:
// reference user final firebasedatabase database = firebasedatabase.getinstance(); databasereference ref = database.getreference("server/path/to/profile"); // attach listener read data @ profile reference ref.addvalueeventlistener(new valueeventlistener() { @override public void ondatachange(datasnapshot datasnapshot) { profile profile = datasnapshot.getvalue(profile.class); system.out.println(profile.getusername()); } @override public void oncancelled(databaseerror databaseerror) { system.out.println("the read failed: " + databaseerror.getcode()); } });
you can find more information , examples on firebase website. keep in mind don't make requests data firebase. attach listeners children , data listener. example assumes have profile
model, method username. return profile
object , enable whatever data need off of object.
Comments
Post a Comment