Skip to content

Instantly share code, notes, and snippets.

@feloy
Created January 19, 2019 09:53
Show Gist options
  • Save feloy/337d2f1c304890a0495b603834779711 to your computer and use it in GitHub Desktop.
Save feloy/337d2f1c304890a0495b603834779711 to your computer and use it in GitHub Desktop.
Send a score from Android app
[...]
Map<String, Object> doc = new HashMap<>();
doc.put("uid", currentUser.getUid());
doc.put("name", name);
doc.put("points", score.getTotalScore());
doc.put("details", score.getDetailsToSave());
doc.put("country", countryCode);
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("Score")
.add(doc)
.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Log.d("MyGame", "Score added to firestore");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("MyGame", "Failed to write score to firestore");
}
});
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment