Created
January 2, 2017 01:31
-
-
Save berkedel/c5f2a0ba3d7e73ae6d4f92a1c78464f9 to your computer and use it in GitHub Desktop.
How to check Firebase connectivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected"); | |
connectedRef.addValueEventListener(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot snapshot) { | |
boolean connected = snapshot.getValue(Boolean.class); | |
if (connected) { | |
System.out.println("connected"); | |
} else { | |
System.out.println("not connected"); | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError error) { | |
System.err.println("Listener was cancelled"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment