Actually I want to show users online/offline status. I read https://firebase.google.com/docs/firestore/solutions/presence and implemented onDiscount()
to update Realtime Database that isOnline = false
on discount but the problem is this data does not update inside Firestore
when the user is discount.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Map<String, Object> user = new HashMap<>();
myRef.child(IS_ONLINE).setValue(true);
myRef.child(IS_ONLINE).onDisconnect().setValue(false);
myRef.child("isOnline").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
status = snapshot.getValue(Boolean.class);
user.put("isOnline", status);
doctRef.set(user);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}