Some kind of alert with Firebase

0

I developed an application where users access and can save some things (name, address etc). These settings are available for an administrator user to view and modify if applicable. I'm using firebase as persistence.

What I would like to know if it is possible, that when some user enters a new record, Firebase will check the change to give some warning or sound so that the administrator knows that there is something new for him to verify.     

asked by anonymous 27.08.2017 / 20:29

1 answer

1

It will depend a lot on the way you thought about your architecture, but if it is a situation where ADM is always with the app / page open, keep a ChildEventListener attached to your benchmark, and in the listener events you work with the new data coming in. I'll put the sample code from Google below for understanding, it's the same thing I always use in my apps. Regarding notification of new items, use the NotificationCompat itself to notify the user of the onChildAdded event:

ChildEventListener childEventListener = new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
        //Evento que vai mostrar toda child que for adicionada na Reference.
    }

    @Override
    public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
        //Evento que vai mostrar toda child que foi modificada.
    }

    @Override
    public void onChildRemoved(DataSnapshot dataSnapshot) {
        //Evento que vai mostrar toda child que for removida da Reference.
    }

    @Override
    public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
        //Evento que vai mostrar toda child que for reordenada na Reference. Particularmente nunca utilizei este evento.
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        //Evento que vai mostrar todo erro que acontecer no banco de dados.
    }
};
ref.addChildEventListener(childEventListener);
    
28.08.2017 / 13:47