2

Firebase Realtime database has a function goOffline, goOnline which can manage the connection manually. But, Firestore doesn't have these methods.

Does Firestore return exception something like NETWORK_ERROR when device lost connection with server? If it doesn't, how can I manage Firestore connection manually when device can't connect to internet and reconnected. (e.g. Airplane mode, Bad wifi)

In my case, I don't use persistence mode.

KENdi
  • 7,576
  • 2
  • 16
  • 31
wonsuc
  • 3,498
  • 1
  • 27
  • 30

1 Answers1

0

Does Firestore return exception something like NETWORK_ERROR when device lost connection with server?

You have use addOnFailureListener which uses OnFailureListener that can just gives you an Exception object to find the cause or message behind the exception via getCause or getMessage and further can apply String checks like contains etc to verify the cause but currently there is no standard way provided by FirebaseFirestore.

how can I manage Firestore connection manually when device can't connect to internet and reconnected. (e.g. Airplane mode, Bad wifi)

You can check the connectivity yourself also at desired places before executing firebase code

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • Thanks for detail answer. So you mean `Firestore` changed `onCancelled`'s behavior [which didn't support on `Realtime database`](https://stackoverflow.com/q/39021378/4729203)? – wonsuc Oct 17 '17 at 15:49
  • 1
    And actually there is no `onCancelled` method in `Firestore`. Where can I find this callback? – wonsuc Oct 17 '17 at 15:53
  • @wonsuc you have two situations, first, no network (you can check the connectivity yourself , check the link in second part) and in case of network error refter the first part – Pavneet_Singh Oct 17 '17 at 15:54
  • you want to check the network error for firebaseStorage? if yes then let me check it – Pavneet_Singh Oct 17 '17 at 15:56
  • Sorry, I'm asking about [Firestore](https://firebase.google.com/docs/firestore/). – wonsuc Oct 17 '17 at 15:58
  • @wonsuc could you add some code to explain it more about what you are trying to achieve here – Pavneet_Singh Oct 17 '17 at 16:01
  • I will add more detail example code to my question later. Thanks for attention. – wonsuc Oct 17 '17 at 16:27
  • @wonsuc welcome, if you have `onevent` with `firebasefirestoneexception` you can verify the error using [FirebaseFirestoreException.Code enum values](https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/FirebaseFirestoreException.Code) although there is no direct network error but others can be helpful – Pavneet_Singh Oct 17 '17 at 16:31