Android Java - 将文档添加到 Firestore 后如何获取文档 ID

时间:2021-06-03 15:28:12

标签: java android firebase

在字符串中将文档添加到 firestore 后,我需要获取文档 ID

Java android studio Firebase

        Map<String, Object> doctor = new HashMap<>();
    doctor.put("name", name);
    doctor.put("specialty", specialty);
    doctor.put("address", address);
    doctor.put("price", price);
    doctor.put("times", times);
    doctor.put("img_url", name);

    CollectionReference dbDoctor = db.collection(addString);
    dbDoctor.add(doctor).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
        @Override
        public void onSuccess(DocumentReference documentReference) {
            Toast.makeText(BookingAdd.this, "Added Done", Toast.LENGTH_LONG).show();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(BookingAdd.this, "Fail to add \n" + e, Toast.LENGTH_LONG).show();
        }
    });

0 个答案:

没有答案
相关问题