Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
Set Up a Firebase Cloud Messaging Client App on Android
Add the dependency for Firebase Cloud Messaging to your module-level build.gradle file:
Now you are ready to work with the FCM in Android.
FCM clients require devices running Android 2.3 or higher that also have the Google Play Store app installed, or an emulator running Android 2.3 with Google APIs.
Edit your AndroidManifest.xml file
To receive messages, use a service that extends FirebaseMessagingService and override the onMessageReceived method.
When the app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.
This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
Here a short recap:
Notification: system tray
Data: in extras of the intent.
On initial startup of your app, the FCM SDK generates a registration token for the client app instance.
If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseInstanceIdService.
The onTokenRefresh callback fires whenever a new token is generated and you can use the method FirebaseInstanceID.getToken() to retrieve the current token.
Subscribe to a topic
Client apps can subscribe to any existing topic, or they can create a new topic. When a client app subscribes to a new topic name, a new topic of that name is created in FCM and any client can subsequently subscribe to it.
To subscribe to a topic use the subscribeToTopic() method specifying the topic name:
This code that i have implemnted in my app for pushing image,message and also link for opening in your webView
This is my FirebaseMessagingService
And this is MainActivity to open link in my WebView or other browser depand on your requirement through intents.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0