Some kind of alert with Firebase

Asked

Viewed 119 times

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 am using firebase as persistence.

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

1 answer

1

It will depend a lot on how you thought your architecture, but if it’s a situation where ADM is always with the app/page open, keep a Childeventlistener attached to your database reference, and at the events of the Software you work with the new data that comes. I’ll put the code snippet of the Google sample below for understanding, it’s the same that I always use in my apps. Regarding notification of new items, use Notificationcompat itself to notify the user in 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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.