【问题标题】:Querying firebase database查询firebase数据库
【发布时间】:2020-12-21 16:50:10
【问题描述】:

如果我想使用addChildEventListener 获得EBpIvNpyXzYzog6BHcG9bJLgSGH2Ghv13dLwkuR52HneS1nXmi2OznL2,我的查询应该在java 中是什么?

这不起作用:

FirebaseDatabase.getInstance().getReference().child("users").addChildEventListener(object :ChildEventListener{
            override fun onChildAdded(snapshot: DataSnapshot, previousChildName: String?) {
                val email= snapshot.child("email").value as String
                emails.add(email)
                snapshot.key?.let { keys?.add(it) }
                Log.i("abcd", snapshot.key.toString())
                adapter.notifyDataSetChanged()
            }

【问题讨论】:

  • 请编辑问题以显示您尝试的代码无法按您预期的方式工作。您可以使用文档了解如何查询实时数据库。 firebase.google.com/docs/database/android/read-and-write
  • 我编辑了问题
  • 这行Log.i("abcd", snapshot.key.toString()) 是否在 logcat 中打印一些内容?请回复@AlexMamo
  • @AlexMamo 不,我需要代码来获取 uuid(随机数和整数字符串)
  • 您是否也尝试在onCancelled() 中记录错误Log.d("TAG", databaseError.getMessage())?那边有什么打印出来的吗?

标签: android firebase kotlin firebase-realtime-database


【解决方案1】:
String user_id = FirebaseAuth.getInstance().getCurrentUser().getUid();   
FirebaseDatabase.getInstance().getReference("users").child(user_id).child("email");

这将检索当前登录用户的"email"

【讨论】:

  • 我要的是 uuid 而不是电子邮件
  • 然后获取它的值并将其转换为字符串
  • 我的意思是,我想要来自数据库的EBpIvNpyXzYzog6BHcG9bJLgSGH2
猜你喜欢
  • 1970-01-01
  • 2017-11-24
  • 2019-07-28
  • 2020-10-16
  • 2017-04-25
  • 2017-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多