2

I know this is quite simple question for all you but I want some different. The scenario is :

I am implementing chat application using Firebase. I have almost implemented it but i want to implement push notification for it same as WhatsApp.

For that I have set up my project and other necessary thing for push notification to Firebase server and in my java code too. I am able to send notification from firebase server and successfully able to get notification from it to the device in which the app is installed.

Question:

So when we are chatting with each other, and someone send us message which needs to be displayed in notification manager, do I need to again call MyFirebaseMessagingService so I can get message which sender sent me from the application?

Also do I need to set up a FCM server for cloud messaging to communicate with client app?

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
  • 1
    you can find information from http://stackoverflow.com/a/37599206/942224 – Sanket Kachhela Sep 01 '16 at 05:51
  • So do i need to set up server for that or simply can i use API ? –  Sep 01 '16 at 05:52
  • 3
    You can listen changes in the database and just show a local notification. If you don't want to do it this way, you can send notifications just making request to FCM http API. You don't need to setup any server. Just request to https://fcm.googleapis.com/fcm/send/ – Héctor Sep 01 '16 at 05:53
  • Okay thanks ! Let me try and will back to you !! –  Sep 01 '16 at 05:54
  • @bigdestroyer As a header should i pass both ? API key and Content-Type? –  Sep 01 '16 at 06:01
  • 1
    @PiyushGupta yes, you can find all the info here -> https://firebase.google.com/docs/cloud-messaging/server – Héctor Sep 01 '16 at 06:05
  • 1
    @bigdestroyer Ok my final question is that do i need to call that API while sending message while chatting (means in my MainActivity) or should i in RegistrationService class of FCM ? –  Sep 01 '16 at 06:07
  • 1
    Well, you need to send a push (call the API) when you send a new message so you should do it in that moment. However, I'd recommend you to use Firebase child listeners. That way, you just save the new message in Firebase Database and the receiver will be notified (observer pattern, not android notification) and show a local notification, if applicable (e.g. app is in background). – Héctor Sep 01 '16 at 06:15
  • Yes ! I am saving the new message to database and push to firebase database ! –  Sep 01 '16 at 06:17
  • @bigdestroyer I have a one issue with that ! –  Sep 01 '16 at 07:25
  • I am getting this after using that code _{"multicast_id":9007804498118366038,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1472715616029303%38f8d1f3f9fd7ecd"}]}_ @bigdestroyer –  Sep 01 '16 at 07:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122370/discussion-between-bigdestroyer-and-piyush-gupta). – Héctor Sep 01 '16 at 08:07

0 Answers0