I am not receiving any callback from interfaces such as addOnSuccessListener
, addOnFailureListener
,addOnCompleteListener
.
Dependencies:
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'
Code:
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
If you have recently change your google-services.json
file then just delete build
folder from android project and re-build your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With