Reputation: 369
I'm having a problem with one specific device (my main device which is galaxy s7)
as described here : Firebase addValueEventListener not being triggered
the addvalueeventlistener won't trigger and as suggested i checked if i have connection using this :
https://firebase.google.com/docs/database/android/offline-capabilities#section-connection-state
and i'm actually not connected
the problem is that one the developing device it's working great and on other it's not.
what am i missing here ?
this is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
localCountryDB = ((GlobalState) this.getApplication()).getCountry();
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
myRef = mFirebaseDatabase.getReference().child(localCountryDB);
FirebaseUser user = mAuth.getCurrentUser();
if (mAuth.getCurrentUser()!=null)
userID = user.getUid();
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");
}
});
valueEventListener = myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
getUserData(dataSnapshot);
}
@Override
public void onCancelled(DatabaseError databaseError) {
String Hello;
Hello="a";
}
});
Upvotes: 2
Views: 4403
Reputation: 369
I found the problem
The problem is that :
mAuth.getCurrentUser()
actually returned a user, an old user which was already deleted from the authentication data so i had to
mAuth.signout()
once i did it the connection was "connected" again and the ValueEventListener triggers
The problem is that i don't know how to catch this bug since trigger doesn't fire.
Upvotes: 3
Reputation: 2148
Try this
Add the internet permission to the manifest
Set the firebase database security rules read to true
Upvotes: 2