3

Needed a suggestion/idea. I have to send the push notification to the android app when the data is changed/updated in the server. I have got a news app, so whenever the news is being updated in the server, the user should get the push notification and when they click the notification, the app should open the link of the news in the app.

What would be the best approach to do so?

I know a bit about FCM, and have played sometime with it, learned about sending the notification from the FCM console, to all the devices using the topic.

Just wondering how can I implement it, rather than using the console, but by just updating the data in the server, and notification should be sent to all the devices which have got the app installed.

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
aevin
  • 167
  • 3
  • 16
  • write a server script to fire FCM calls once the update is complete. Should be pretty simple if you look at FCM docs. – Satya Dec 24 '18 at 04:55

1 Answers1

4

You can use your server to send FCM messages to your app without having to use the firebase console manually.

Just a simple API call from the server will push notifications (or messages) to the required devices.

For more information read the documentation on FCM Server.


There are multiple alternatives for opening activity of your choice after clicking the notification.

IMO, a good approach would be to send 'data' field from the FCM server instead of 'notification' field so that the method onMessageReceived will always get called. Inside that method, you can build your custom notification and set the intent to activity of your choice.

Another approach would be to check for extras in the launcher activity and if there is something coming from notification, open the activity of your choice and perhaps finish the launcher activity.

Nabin Bhandari
  • 15,949
  • 6
  • 45
  • 59
  • Thanks for the reply. If you don't mind I have got another query. I have seen the notifications in android that directly opens the link on the app. Would be glad if you can clarify how it is done. :) – aevin Dec 24 '18 at 04:58
  • Sure, you can ask it. – Nabin Bhandari Dec 24 '18 at 04:59
  • One can open the web-link directly from the notification, what would be the approach to do so ? – aevin Dec 24 '18 at 05:03