Search code examples
androidfirebaseserverfirebase-cloud-messagingandroid-push-notification

Send Push Notification to Android app upon the data update in the server, and open custom Activity


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.


Solution

  • 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.