You must send a data payload in your FCM message. The data payload is accepted in the messaging method, regardless of whether your application is in the foreground or in the background. Process action there. Like notification of impressions, always reading the data payload, or if you want to show a warning dialog when your application is open or in the foreground.
here is an example payload:
{ "to": "registration_id_or_topic", "data": { "message": "This is a Firebase Cloud Messaging Topic Message!", "youtubeURL": "https://youtu.be/A1SDBIViRtE" } }
Then in your onMessageReceived:
public void onMessageReceived(RemoteMessage remoteMessage) { if (remoteMessage.getData().size() > 0) { Log.d(TAG, "Message data payload: " + remoteMessage.getData()); Map<String, String> receivedMap = remoteMessage.getData(); String youtubeURL = receivedMap.get("youtubeURL"); showNotificationWithURLAction(youtubeURL); } ..... }
you can easily implement the showNotificationWithURLAction (...) method by doing it. One sample here
source share