2

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";
}
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user2396640
  • 359
  • 4
  • 24

2 Answers2

3

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.

user2396640
  • 359
  • 4
  • 24
2

Try this

  • Add the internet permission to the manifest

  • Set the firebase database security rules read to true

Martin De Simone
  • 2,108
  • 3
  • 16
  • 30