0

I want to get the id from Firebase, I am build android app using Java

Kneelon
  • 239
  • 3
  • 12

1 Answers1

2

Putting suggestion by Sir Frank van Puffelen in action -

You can get key value from documentSnapShot -

@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
    String docuementKey = documentSnapshot.getReference().getId();

    //toast message 
    Toast.makeText(getApplicationContext(), docuementKey, Toast.LENGTH_SHORT).show();
}

then you can save it in your Upload POJO.

Happy Coding !

Nikhil Sharma
  • 897
  • 1
  • 4
  • 18
  • thanks for the answer Nikhil Sharma but the issue is I need to get key from database not on Firestore :( – Kneelon Aug 09 '20 at 23:15
  • `Toast.makeText(getApplicationContext(), docuementKey, Toast.LENGTH_SHORT).show()` will give you the key value you have marked red on your question image, and if Firebase Firestore is not your database then which database you are referring to ? – Nikhil Sharma Aug 10 '20 at 02:56
  • I want to get the key from My Firebase Database, not from Firestore, yes my companyName and imageUrl is from Firestore, but I need to get the KEY from FIREBASE DATABASE, thanks for your Response Nikhil Sharma I really appreciate it, Thank you, Still waiting for the response Sir Nikhil – Kneelon Aug 10 '20 at 06:41
  • could you post a screen shot distinguishing FIREBASE DATABASE KEY and FIRESTORE KEY, according to your understanding of both and are you referring to [Realtime Database](https://firebase.google.com/docs/database/rtdb-vs-firestore) – Nikhil Sharma Aug 10 '20 at 06:57
  • Yes I'm referring to Firebase Realtime database. thank you Nikhil, thumbs up to you, I need to get the key of my Realtime database – Kneelon Aug 10 '20 at 10:24
  • `FirebaseDatabase.getInstance().getReference("your_document_path").getId()` .. have you try that ? – Nikhil Sharma Aug 10 '20 at 10:31
  • check [this](https://stackoverflow.com/questions/38232140/how-to-get-the-key-from-the-value-in-firebase) thread as well... – Nikhil Sharma Aug 10 '20 at 10:39