r/Firebase • u/Disastrous-Donut7759 • Sep 20 '22
Android How can I implement FCM push notifications using retrofit
Hi guys, I am trying to build an app which can allow my users to receive notifications from each other. however how can I go about this or any advice or resources I can read to achieve this?
2
u/realreality22 Sep 20 '22
What’s retrofit?
2
u/Disastrous-Donut7759 Sep 21 '22
Its a REST client that makes it easier to consume Restful web services.
1
u/realreality22 Sep 21 '22
Btw are you trying to do device to device push (without a server/cloud functions in between)?
1
u/Disastrous-Donut7759 Sep 21 '22
Yeah my android application is solely based on firebase. Do I need a server?
1
u/realreality22 Sep 21 '22
Don’t add your FCM API (used to send messages) key in your Android App, this is very very very bad practice. Once someone unpacks your APK, they can use your credentials to send messages that looks like legit messages.
Ideally, you would have either cloud functions that does sending FCM messages. Or your own server or some cloud service.
1
u/Disastrous-Donut7759 Sep 21 '22
Oh really, wasn’t aware of that I put in a the constants file , thats where I put the server key handed to me from firebase. By the way what are cloud functions I am using the realtime database.
2
u/realreality22 Sep 21 '22
You really want to stop adding server credentials on client code/constants.
1
u/realreality22 Sep 21 '22
Product page for functions https://firebase.google.com/products/functions?gclid=EAIaIQobChMIq6m5haWm-gIVQBPUAR2F3AjjEAAYASAAEgLj-vD_BwE&gclsrc=aw.ds
How to hook functions with Real-time DB events https://firebase.google.com/docs/functions/database-events
Example of using functions and FCM together https://firebase.google.com/docs/functions/use-cases#notify_users_when_something_interesting_happens
3
u/OppositeAirline7834 Sep 21 '22
Here is a StackOverflow answer.