首页 > 解决方案 > Android Java - 如何在将文档添加到 Firestore 后获取文档 ID

问题描述

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

Java 安卓工作室 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();
        }
    });

标签: javaandroidfirebase

解决方案


推荐阅读