Steve
Steve

Reputation: 43

Notification when firebase is updated?

I am making a chat application where I want the a user to get a notification when the other user sends a message. I've heard you can do it with a js script and followed the google guidelines but I'm confused where am I actually writing the script? Do I have to do the free trial for the google firebase environment?

Upvotes: 0

Views: 255

Answers (1)

VikasGoyal
VikasGoyal

Reputation: 3376

You can do like this:-

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(reference)

 FirebaseArray snapshots = new FirebaseArray(ref);

 snapshots.setOnChangedListener(new FirebaseArray.OnChangedListener() {
            @Override
            public void onChanged(EventType type, int index, int oldIndex) {
                switch (type) {
                    case Added:                       
                        break;
                    case Changed:                        
                        break;
                    case Removed:                        
                        break;
                    case Moved:                        
                        break;
                }
            }
        });

Upvotes: 1

Related Questions