0

I want to retrieve and show all users from firebase authentication

I tried the code from this link https://firebase.google.com/docs/auth/admin/manage-users

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_users_information);
    //Get Firebase auth instance
   FirebaseAuth auth = FirebaseAuth.getInstance();

  // Start listing users from the beginning, 1000 at a time.
    ListUsersPage page = FirebaseAuth.getInstance().listUsers(null);
    while (page != null) {
        for (ExportedUserRecord user : page.getValues()) {
            System.out.println("User: " + user.getUid());
        }
        page = page.getNextPage();
    }
    page = FirebaseAuth.getInstance().listUsers(null);
    for (ExportedUserRecord user : page.iterateAll()) {
        System.out.println("User: " + user.getUid());
    }

}

It gives me error at listUsers... it is not identified as keyword. Also what will be the layout for this, should I use list view??

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Nimra
  • 67
  • 1
  • 1
  • 6

1 Answers1

2

The page of documentation you linked to is for the Firebase Admin SDK, not the Firebase Auth client library for Android. It's not supported to use the Firebase Admin SDK in an Android app. It's for backend use only. It also requires that you initialize it with a service account, which is something you would never want to put into a shipping Android app, as that would be a huge security hole.

If you want to list all users in your app from a client, you will need to populate a database that you can query from the client, or expose a server API that gives you what you want. Both will require some code running outside the client app.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441