当我尝试从Android应用程序收听Cloud Firestore集合时出现错误

时间:2019-01-02 07:54:23

标签: android firebase google-cloud-firestore

我正在使用Android应用程序中的Cloud Firestore尝试POC。我已遵循Firebase文档并添加了以下方法:

private void initializeFirestoreAndListenToUserUpdates() {
    final FirebaseFirestore db = FirebaseFirestore.getInstance();
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
            .setPersistenceEnabled(true)
            .build();
    db.setFirestoreSettings(settings);

    // Listen for users born before 1900.
    // You will get a first snapshot with the initial results and a new
    // snapshot each time there is a change in the results.
    db.collection("users")
            .whereLessThan("born", 1900)
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot snapshots,
                                    @Nullable FirebaseFirestoreException e) {

                    if (e != null) {
                        Log.w(LOG_TAG, "Listen failed.", e);
                        return;
                    }

                    Log.d(LOG_TAG, "Current users born before 1900: " + snapshots.getDocuments());
                    List<DocumentSnapshot> documents = snapshots.getDocuments();
                    if (documents != null) {
                        for (DocumentSnapshot doc : documents) {
                            Log.d(LOG_TAG, doc.toString());
                        }
                    }
                }
            });
}

但是在运行时,我在logcat中看到以下错误:

01-02 12:09:47.705 12977-13061/com.disha.quickride W/Firestore: (0.6.6-dev) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: Status{code=FAILED_PRECONDITION, description=The Cloud Firestore API is not available for Cloud Datastore projects., cause=null}
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

从Firebase控制台,我可以确认已禁用Cloud Datastore,并且仅在纯模式下启用Cloud Firestore。另外,我的android设备上的互联网连接正常。我该如何纠正该错误?

0 个答案:

没有答案