Not able to get current user particular value

firebase get current user
firebase update current user
firebase get user data by uid
firebase current user: null
firebase get user info
firebase get user password
firebase check if user is logged in android
how to delete user from firebase

I am trying to get the value of channel_id from Firebase of the current user logged in. Below is the Image of the database:

I am getting null value from it from the code given below.

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference dbref = 
    FirebaseDatabase.getInstance().getReference("Users/Clients");
  dbref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                String val =String.valueOf(dataSnapshot.getValue());
                Toast.makeText(getBaseContext(),""+val,Toast.LENGTH_LONG).show();
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });

To get the current user information, try the following:

FirebaseDatabase database = FirebaseDatabase.getInstance();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userId=user.getUid();
DatabaseReference dbref = FirebaseDatabase.getInstance().getReference("Users/Clients").child(userId);
 dbref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        String names=dataSnapshot.child("name").getValue().toString();
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
});

Here you retrieve the current user id, then you add it to the path and retrieve the data.

FR: please add function Auth.getCurrentUser() as a promise that will , getCurrentUser() as a promise that will return current user or null FR: please add Given that the recommended approach to get current user relies on I can't see a lot of value in a synchronous version of getCurrentUser . Then in your DI object that needs the user you just inject IPrincipal to get the current user. The most important thing here is if you're doing unit tests you don't need to send in an HttpContext, but only need to mock something that represents IPrincipal which can just be ClaimsPrincipal. One extra important thing that I'm not 100% sure about.

Try this answer

 FirebaseDatabase database = FirebaseDatabase.getInstance();
 FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
 String userId=user.getUid();
 DatabaseReference dbref = 
 FirebaseDatabase.getInstance().getReference("Users/Clients").child(userId);
 dbref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            String channel_Id=dataSnapshot.child("channel_id").getValue().toString();

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

Case-Based Reasoning Research and Development: 20th International , a user unconcerned about the appearance of a cell phone might choose not to and demonstrated that when the user's ability to answer particular questions to the question, given the current user classification (if any), and the value of the treats all users uniformly, demonstrating its benefits when users have different​  Newbie trying to get a hang of DAX. I have a table with a one to many relationship with another table, I use relatedtable function to get all the values related to the current row. But I can't figure out how to extract the value of a specific column in that returned table. So for example if a customer has multiple orders.

@Peter Haddad's answer will work great, there's also an alternative which is to attach the listener directly to the name property with:

FirebaseDatabase database = FirebaseDatabase.getInstance();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userId=user.getUid();
DatabaseReference dbref = FirebaseDatabase.getInstance().getReference("Users/Clients/"+userId+"/name");
 dbref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        String names=dataSnapshot.getValue(String.class);
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
});

This last example has the advantage that it only retrieves the name property and nothing else, even if you later add more child properties under userId. This method will save you bandwidth.

How to get current authenticated user · Issue #569 · strongloop , In requeest I have valid access token so user available in beforeRemote as part of ctx user) return next(new Error('could not find a valid user with the given token')); app. Coming from 2.x + current context I am not able to port this implementation to the The options value contain the same token as set by LoopBack 2.x. how to retreive data from database of a particular user after login hi I m developing a project on hospital management and I m not able to retrieve the user information.. now their is a login and registration page for newuser. after the user has filled the form he should go to the welcome page where he could see the information he has filled in the form and various other links..

Manage Users in Firebase, If no user is signed in, getCurrentUser returns null: Do NOT use this value to Get a user's provider-specific profile information It is also possible to pass state via a continue URL to redirect back to the app when sending a  I want to print value from a Windows environment variable, say, path or errorlevel, I've tried this but it doesn't work. Output this in my console: (without consider spaces/tabs which it outputs):

Get current user email and add to collection, I want to collect a logged in user's email address so that I can sync to Wix CRM I can see the user ID in the collection the form is linked to but not the email. I am puzzled because I have been able to add the user's login email to one of In the middle of the page, they can edit individual entries by paging  As some of the previous answers are very right, I just want to make sure from none of you fall in such this problem. If you set the values to the ArrayList using String.format, you MUST get the position of the value using the same string structure String.format.

wp_get_current_user() | Function, Retrieve the current user object. logged-in person. If no user is logged-in, then it will set the current user to 0, which is invalid and won't have any permissions. None - Does not wait for anything except the target UI element to exist before executing the action. For example, you can use this option if you want to retrieve just text from a web page or click a particular button, without having to wait for all UI elements to load.

Comments
  • @K132133SyedArsalanHussain check my answer
  • Worked but if I want to fetch name with channel_id will this work @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String channel_Id=dataSnapshot.child("channel_id").getValue().toString(); String name = dataSnapshot.child("name").getValue().toString(); Toast.makeText(getBaseContext(),""+val,Toast.LENGTH_LONG).show(); }
  • what are you getting instead?
  • remove this toast Toast.makeText(getBaseContext(),""+val,Toast.LENGTH_LONG).show(); there is no val variable in the code
  • close of application while debugging without an error
  • error in line 2 of your code .getCurrentUser() is giving error
  • when I am hovering over it it says cannot resolve method getCurrentUser()
  • Worked but if I want to fetch name with channel_id will this work @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String channel_Id=dataSnapshot.child("channel_id").getValue().toString(); String name = dataSnapshot.child("name").getValue().toString(); Toast.makeText(getBaseContext(),""+val,Toast.LENGTH_LONG).show(); }
  • He doesn't want that though, because in the comments he told me that he wants to retrieve the channel_id also not only the name property
  • @PeterHaddad In this case only your answer will work but the OP didn't mention that he wants to retrieve also the channel_id in his question. Cheers!