如何从Firstore获取用户名?

时间:2019-10-19 03:21:27

标签: android firebase kotlin google-cloud-firestore

enter image description here我想将我的用户名导入FireStore,但无法导入。我该如何获取?记录日志时,该日志具有很高的价值,但是当您构建应用程序时,您只会收到一封电子邮件,并且您的用户名不可用。为什么要这样做? AccountFragment.kt

class AccountFragment : Fragment() {

    var user : FirebaseUser? = null
    var firestore: FirebaseFirestore? = null
    var fragmentView: View? = null


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        fragmentView = inflater.inflate(R.layout.account_fragment, container, false)

        firestore = FirebaseFirestore.getInstance()
        user = FirebaseAuth.getInstance().currentUser



        return fragmentView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)


        val docRef = firestore!!.collection ( "user" ). document (user!!.uid)
        val source = Source.CACHE

        docRef.get(source).addOnCompleteListener { task ->
            if(task.isSuccessful){
                val document = task.result
                user_email.text = user?.email
                user_name.text = UserModel().userName
            }else{

            }
        }
  }

UserModel.kt

class UserModel {
    var userEmail: String? = null
    var userName: String? = null
    var uid: String? = null
    var password: String? = null
    var timestamp: Long? = null
    var content: String? = null
    var profileImageUrl: String? = null
    var pushToken: String? = null
}

0 个答案:

没有答案