I'm trying to save a document on a collection, following the documentation on cloud firestore. I can read a collection/document that I manually created on the firebase console but trying to store from my Android app is not working.
Console/Logcat is not showing any error and the app is not crashing. Neither of the listeners are getting called. Am I missing something?
class UserActivity : AppCompatActivity() {
private val db = FirebaseFirestore.getInstance()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profile)
save_button.setOnClickListener { storeUser() }
}
private fun storeUser(){
val user = HashMap<String,Any>()
user.put("first", "Ada")
user.put("last", "Lovelace")
user.put("born", 1815)
db.collection("users")
.add(user)
.addOnSuccessListener(OnSuccessListener<DocumentReference> { documentReference -> Log.d("Storing User", "DocumentSnapshot added with ID: " + documentReference.id) })
.addOnFailureListener(OnFailureListener { e -> Log.w("Storing User", "Error adding document", e) })
}
}
EDIT:
As an update trying to read a document throws the following exception
com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.