0

Firebase database's status state is always not connected, for a Samsung Galaxy A3, while the internet connection is valid.

On the other hand, same app installed on a Samsung Galaxy S5 works as expected.

I've already reinstalled the app, restarted the phone, restarted the phone and reinstalled the app altogether. I've left out of ideas on how to fix this!

Code that used to detect connection as in the tutorial:

DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot snapshot) {
        boolean connected = snapshot.getValue(Boolean.class);
        if (connected) {
            Log.d(TAG, "connected");
        } else {
            Log.d(TAG, "not connected");
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError error) {
        Log.w(TAG, "Listener was cancelled");
    }
});
Themelis
  • 4,048
  • 2
  • 21
  • 45
  • Is the phone able to read any data from the database? And can you [enable debug logging](https://firebase.google.com/docs/reference/android/com/google/firebase/database/FirebaseDatabase.html#setLogLevel(com.google.firebase.database.Logger.Level)) and check the output for relevant logging? – Frank van Puffelen Mar 07 '19 at 00:43
  • It was not able to read data @FrankvanPuffelen. In a minute I will tell you about the debug logging. – Themelis Mar 07 '19 at 00:45
  • @FrankvanPuffelen I had no idea about the debug logging but it works now. Let me tell you what I've done: 1. `firebaseDatabase.setPersistenceEnabled(true);` 2. `firebaseDatabase.setLogLever(Logger.Level.DEBUG);` 3. Use this instance globally. May I ask a) **why now it's working?** b) **should I leave the code like this?** – Themelis Mar 07 '19 at 01:13
  • Setting the log-level should make no difference. Disable it and the behavior should remain unchanged. After that also remove the `setPersistenceEnabled` again, and uninstall and reinstall the app (to ensure the disk cache is gone). I'd be surprised if it caused the problem, so would like to have confirmation first. – Frank van Puffelen Mar 07 '19 at 04:56

0 Answers0