我没有从addOnSuccessListeneraddOnFailureListeneraddOnCompleteListener之类的接口收到任何回调。

依存关系:

        classpath 'com.google.gms:google-services:3.2.1'

        implementation 'com.google.firebase:firebase-firestore:16.0.0'
       // }
        apply plugin: 'com.google.gms.google-services'


码:

 firestore = FirebaseFirestore.getInstance(); // required for first time
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
            .setTimestampsInSnapshotsEnabled(true)
            .build();
    firestore.setFirestoreSettings(settings);

    final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Map<String, Object> user = new HashMap<>();
            user.put("Title", "Ada");
            user.put("category", "Lovelace");
            user.put("id", "123");

            firestore = FirebaseFirestore.getInstance();
            firestore.collection("quotes")
                    .add(user)
                    .addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
                        @Override
                        public void onSuccess(DocumentReference documentReference) {
                            Log.d("quotes", "DocumentSnapshot added with ID: " + documentReference.getId());
                            Snackbar.make(fab, "DocumentSnapshot added with ID: " + documentReference.getId(), Snackbar.LENGTH_INDEFINITE).show();
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.w("quotes", "Error adding document", e);
                            Snackbar.make(fab, "OnFailureListener: " + e, Snackbar.LENGTH_INDEFINITE).show();
                        }
                    })
                    .addOnCompleteListener(new OnCompleteListener<DocumentReference>() {
                        @Override
                        public void onComplete(@NonNull Task<DocumentReference> task) {
                            Snackbar.make(fab, "OnCompleteListener: " + task.isSuccessful(), Snackbar.LENGTH_INDEFINITE).show();

                        }
                    });

        }
    });





LOGCAT




E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER

最佳答案

如果您最近更改了google-services.json文件,则只需从android项目中删除build文件夹,然后重新构建您的项目即可。

08-26 20:56
查看更多