How to programmatically get the list of registered users in Firebase
You can't
The explanation is here How do I return a list of users if I use the Firebase simple username & password authentication
You can instead set the user's uid to users
node in your database, I use that node to store other user's information. then you can get the number of childs under that node.
How to access in android the users registered in Firebase Authentication
Since you indicate not wanting to use Cloud Functions, the solution would be to have each user write their own user data to the database when they register/sign-in.
You can then refer to that information in the database when you need it.
This has been covered quite a few times before already, so I recommend checking out:
- How do I return a list of users if I use the Firebase simple username & password authentication
- How to programmatically get the list of registered users in Firebase
- And more from these search results
How to list the registered users names in Android (Firebase)?
To display those names, please use this code:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference usersdRef = rootRef.child("users");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String name = ds.child("name").getValue(String.class);
Log.d("TAG", name);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
usersdRef.addListenerForSingleValueEvent(eventListener);
And the output will be in this case all your user names.
How do I return a list of users if I use the Firebase simple username & password authentication
When using email / password authentication in Firebase Authentication (previously known as Firebase SimpleLogin), your user's email and password combination is securely stored separately from the data actually stored in your Firebase.
This barrier between the data in your Firebase and your users' email / password hash combinations is by design: we want to make it easier for you to (1) develop your application, (2) prevent any accidental user credential leaks, and (3) still give you total flexibility with how to store your user data in Firebase.
That means that we only store the email address / password hash combination and nothing else, so it is up to you to decide how to store actual user data in your Firebase. As you suggested, you should be taking the user id and storing that data in your Firebase in a location such as /users/$id, and using the Firebase Security Rules Language to determine read / write access to that data. Your user's unique id
and email
are already in the auth
variable you'll use when writing rules.
Related Topics
How to Check If "Android.Permission.Package_Usage_Stats" Permission Is Given
Android:Windowsoftinputmode="Adjustresize" Doesn't Make Any Difference
Android Studio Fails to Build New Project, Timed Out While Wating for Slave Aapt Process
How to Change the Led Intensity of an Android Device
How to Set Text to View from Drawer Header Layout in Navigation Drawer Without Inflating View
How to Check If Facebook Is Installed Android
Using Adb Logcat with a Real Phone (And Not the Emulator)
Rotate an Yuv Byte Array on Android
How to Write a Custom Filter for Listview with Arrayadapter
Broadcastreceiver for Location
What Is a Full Android Database Helper Class for an Existing SQLite Database
How to Show and Hide Actionbar with Appcompat V.7