Issue
I wanted to put a unique id every time when users signups into my apps. below is my code attached which is used to store data currently using vehicleNo:
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference root = db.getReference("Drivers");
DriverModel driverModel = new DriverModel(name,contact,email,licenseNo,vehicleNo,age,bloodGroup,uri.toString(),drowsinessImage,dateTime);
root.child(vehicleNo).setValue(driverModel);
Solution
If the user is signed in with Firebase Authentication, you can get their UID with:
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
Then you can save the data under their UID with:
DriverModel driverModel = new DriverModel(name,contact,email,licenseNo,vehicleNo,age,bloodGroup,uri.toString(),drowsinessImage,dateTime);
root.child(uid).setValue(driverModel);
Answered By - Frank van Puffelen
Answer Checked By - Candace Johnson (JavaFixing Volunteer)