I need the android code for firebase that will send a notification when a user sends a message from one android phone. eg: When I use Whats App for example if User A sends a message to User B, then a notification is sent to user B device when User B clicks on it, the page opens. How to do this via only firebase and no other server, I have searched all the Firebasse docs... In the notification only Server to device is given.. I am making a chat app and only this feature is remaining.
Asked
Active
Viewed 137 times
-2
-
There is no Firebase API to send direct device to device notifications. See http://stackoverflow.com/questions/37634046/is-it-possible-to-send-pushnotifications-using-firebase-cloud-messaging-fcm-t. I've written about one way to accomplish the use-case, but it requires a trusted process. See https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html You could also send them from Apps Script (which runs on Google's servers). See http://stackoverflow.com/questions/42174372/how-to-send-push-notification-from-firebase-using-google-apps-script/42179497#42179497 – Frank van Puffelen Feb 17 '17 at 14:28
1 Answers
0
You can try this code and customize as per your need... i also used this code to customize my chatting application
You have to add notification code inside the following method in Chat.java class
FirebaseDatabase.getInstance().getReference("messages").addListenerForSingleValueEvent();
...And if you want to receive notifications when your app is not running or close like whatsapp. You have to create an android service for notification that will run continuously in the background.

Community
- 1
- 1

Ramsha Omer
- 1,022
- 1
- 8
- 28
-
-
As u can see there are variables sender, receiver, message etc.. the class instance hold the ids of sender and receiver and also the message and status(delivered or not) of a specific conversation – Ramsha Omer Feb 17 '17 at 13:52