I am writing a messenger app that uses Firebase Firestore, Storage and Authentication. At first, opening it requests user data and if user with the number that the user entered exists then the application is getting his name and nickname from Firestore. But in this moment the app is stopping, responding and printing this message in logcat:
W/Firestore: (21.4.1) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
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.
I am testing app on real device with Android 10 and this error appears only when application trying to get user data from firestore. Function that getting data from firestore:
fun getUserFromFirestoreAndInsertItInDB(number: String): MessengerUser = runBlocking(Dispatchers.IO) {
val user = Firebase.firestore.collection("Users").document(number).get()
.await().toMessengerUser()
database.messengerUserDao.insert(user)
user
}
toMessengerUser() function:
fun DocumentSnapshot.toMessengerUser(): MessengerUser {
val name = data!!["name"] as String
val nickname = data!!["nickname"] as String
val number = data!!["phoneNumber"] as String
val lastOnline =
(data!!["lastOnline"] as Long) + Calendar.getInstance().timeZone.rawOffset
lateinit var stream: InputStream
Firebase.storage.getReference("UsersPictures/$number")
.child(number).stream
.addOnSuccessListener {
stream = it.stream
}
.addOnFailureListener {
FirebaseCrashlytics.getInstance().recordException(it.cause!!)
}
val picture = Drawable.createFromStream(stream, null)
return MessengerUser(picture, name, nickname, number, lastOnline)
}