如何只为特定用户检索Firebase数据库? [英] How to retrieve firebase database for specific user only?
问题描述
我正在将Firebase数据库用于我的android应用程序.登录功能可用.应用程序中有一个书签/收藏夹选项.按下书签按钮后,数据将分别与用户ID一起保存.正是我想要的.但是问题是当我尝试在recycleview中检索保存的数据时,它们显示的是所有用户的数据,而不是已登录的用户.请帮助我.我在recycleview中使用cardview.
I am using Firebase Database for my android application. Login feature is available. There is a bookmark/favourite option in the app. After pressing the bookmark button the data are saving with the user id separately. Exactly what I want. But the problem is when I am trying to retrieve the saved data in recycleview they are showing all user's data instead of the user logged in. Please help me. I am using cardview in recycleview.
mUserDatabase = FirebaseDatabase.getInstance().getReference("Bookmarks");
mUserDatabase.keepSynced(true);
这是我的成语短语数据库
It is my Database for Idiom Phrase
这是用户通过按书签按钮添加的数据
And it is the data added by user by pressing bookmark button
推荐答案
您需要访问用户uid,以便仅显示该用户的数据:
You need to access the user uid, so only that user's data will be shown:
FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
String userId=user.getUid();
//String.valueOf(int)
mUserDatabase = FirebaseDatabase.getInstance().getReference("Bookmarks").child(String.valueOf(10)).child(userId);
getUid()
将检索当前登录用户的ID.
getUid()
will retrieve the id of the current logged in user.
这篇关于如何只为特定用户检索Firebase数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!