2

I am inserting a data in my Request Node in Firebase database in Android using this,

public void submitRequest(View v) {
Request myUserInsertObj = "Pending";
rootReference.child("Request").child("Pending").child(firebaseuser.getUid()).setValue
(myUserInsertObj);    
}

This is my Request Class.

Public class Request{

public String request_status;

public Request(String request_status){

this.request_status = request_status;
}

Request()
}

I found in firebase documentation that I can use firebaseuser.getDisplayName to get the current logged in user's name. But where will the .getDisplayName get the user's name since I created my own login form and user registration in my app.

Question 2: If I do this, is this possible? Because I want to put a name in requesting guest node so that when I retrieve it in my HTML web admin panel the data will be easier to read.

  rootReference.child("Request")
        .child("Pending")
        .child(firebaseuser.getUid())
        .setValue(myUserInsertObj + firebaseuser.getDisplayName);

If so what should I add in my Request Class?

Question 3. How do I add timestamp I know timestamp is very important in data insertion on every system.

Theodore
  • 85
  • 1
  • 10

1 Answers1

1

I found in firebase documentation that I can use firebaseuser.getDisplayName to get the current logged in user's name.

Yes, that correct. Calling getDisplayName() on a FirebaseUser object:

Returns the main display name of this user from the Firebase project's user database.

Regarding the second part of your question:

But where will the .getDisplayName get the user's name since I created my own log in form and user registration in my app.

As explained above, getDisplayName() is getting you the name that is coming from the authentication process. If you want to get the user name from your custom user object then you should first get the user object from the database and use it where it is needed.

Because I want to put a name in the request node so that when I retrieve it in my HTML web admin panel the data will be easier to read.

If you want to add the name in your node, you should pass the display name to the child() method and not to the setValue(). Your code should look like this:

rootReference.child("Request")
    .child("Pending")
    .child(firebaseuser.getUid() + "_" + firebaseuser.getDisplayName())
    .setValue(myUserInsertObj);

This code will generate a child that might look like this:

Firebase-root
   |
   --- Request
        |
        --- Pending
              |
              --- SxbVg0...uobvk1_Theodore
                    |
                    --- //user details

DatabaseReference class has 4 overloaded setValue() methods but none of this methods allow you to pass an object along with a String as arguments.

Question 3. How do I add timestamp I know timestamp is very important in data insertion on every system.

This is how you add and get the timestamp that you were talking about.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I saw your answer on this post https://stackoverflow.com/questions/44809824/moving-or-copying-data-from-one-node-to-another-in-firebase-database If I just copy the user's name from my "User" Node when he click the submitRequest button is it possible using your answer in copying nodes to another nodes? – Theodore Nov 26 '18 at 10:15
  • Yes, what about it? – Alex Mamo Nov 26 '18 at 10:16
  • I don't get it. Is there another question or what? – Alex Mamo Nov 26 '18 at 10:22
  • I really don't know how to do this `If you want to get the user name from your custom user object then you should first get the user object from the database and use it where it is needed.` – Theodore Nov 26 '18 at 10:23
  • **[This](https://stackoverflow.com/questions/49253026/firebase-auth-and-database/49256810)** is how you can add and get a user from the database. Is it clear now? – Alex Mamo Nov 26 '18 at 10:24
  • I'll edit my user creation using that and then I'll inform you afterwards, is it okay? – Theodore Nov 26 '18 at 10:31
  • Yes, that's ok. Keep me posted. – Alex Mamo Nov 26 '18 at 10:32
  • I finished editing my user class to UserModel, now what should I do next? I added some fields like first name, last name, middle name, address and phone number. – Theodore Nov 26 '18 at 10:54
  • Your question is about a topic and you asking me now about a different topic. Let's stick to one question at a time. And you should make your own attempt given the information in the answer/answers and ask another question if something else comes up. As a hint, you should follow the steps that explained in that answer. If you have other issues, please post another fresh question, so me and other users can help you. – Alex Mamo Nov 26 '18 at 12:00
  • If you post another question add it here as a link so I can take a look at it. – Alex Mamo Nov 26 '18 at 12:06
  • the UserModel that I created from your answer on the other post is an object? Can I call it from other acitivities? – Theodore Nov 26 '18 at 12:09
  • Yes it is an object. To use in another activity you should add the object into an intent and get in the other activity. – Alex Mamo Nov 26 '18 at 12:11
  • got a new question https://stackoverflow.com/questions/53481647/how-to-query-data-in-firebase-using-userid-in-javascript. – Theodore Nov 26 '18 at 12:59
  • I'll take a look and if I'll know the answer, I'll write it to you. – Alex Mamo Nov 26 '18 at 13:09