-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Where does gcm.n.link
handling take place?
#6703
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
Hi @ColtonIdle, thank you for reaching out. Please note, firebase-android-sdk/firebase-messaging/src/main/java/com/google/firebase/messaging/Constants.java Line 214 in e125fb7
As per our documentation for data message,
In Android, if the Lines 399 to 424 in e125fb7
I tried reproducing the behavior from the Stack Overflow post you shared, and I was able to confirm that using the I believe this is a bug. I'll raise this to our engineers and see what we can do here. Thanks a lot! |
@lehcar09 thanks for the thorough response. So my issue right now is that my backend is sending programatic firebase cloud messages. we want them to be of type Notification so that the android fcm library does all of the heavy lifting of posting the notification. but we can't get deep links to work unless we send gcm.n.link. then everything works. are you saying we should not do that? nothing else seems to work, so please let me know if not. there are a bunch of 5-10 year old stack overflow questions on this topic and the only ones that people claims to work is gcm.n.link |
@lehcar09 to be clear. please dont remove gcm.n.link support from HTTP v1 API 😅 |
Data payload should be set with your custom key-value pairs. Reserved keys or prefixes should not be used in the data bundle. I have raised this issue to our engineers for clarification and ask if there's a way to set the deep link URI for notification. Alternatively, we can file a feature request to support the |
Thanks! In the meantime... we'll continue to use gcm.n.link. I hope it doesn't get removed since that would break functionality for us (+ a bunch of others on stackoverflow that had the same issue of "How do i send a deep link in android using fcm?") Edit: I'll also grab some server code to paste in here to show what we tried exactly. |
Just following up with a small snippet of what we've tried As per https://firebase.google.com/docs/cloud-messaging/send-message we use the java sdk
and this didn't work. we also tried
and we tried a bunch more different combinations in the putData field. Bonus question: As a sanity check (maybe im going crazy) How does the sdk decide whether this is a notification message or a data message? Does doing |
Notification messages contain a predefined set of user-visible keys. Data messages, by contrast, contain only your user-defined custom key-value pairs. firebase-android-sdk/firebase-messaging/src/main/java/com/google/firebase/messaging/Constants.java Lines 120 to 138 in 95bbf92
FCM allows users to send notification messages that contain an optional payload of custom key-value pairs. However, please note that app behavior depends on whether the app is in the background or the foreground. You can check this documentation for more details. |
Yep. I'm aware of the difference of background vs foreground behavior for data vs notification messages. i once hit a wild issue regarding that like 3 years ago that made me go way deeper into FCM than I would have liked 😂
SO am i understanding correctly that once you add an optional payload of custom key/value pairs then the message is a "data" message? or if i omit any notification properties and only have custom key/value then that considers it a data message? |
we're still investigating issues at our org. some of the android devs are convinced that "click_action" is the way forward... but click_action seems to not be for deep links, but instead for the name of which activity to launch. at least from what i understand from https://firebase.google.com/docs/cloud-messaging/migrate-v1 can anyone chime in on that? Or i guess a better question is... is there not some property that we're "supposed" to use for deep links from FCM notification messages? |
"gcm.n.link" (and "gcm.n.link_android") is not officially supported and uses a reserved key, so "click_action" would be recommended. Line 404 in 1e8c218
"click_action" sets the action of the Intent sent to your app to open an Activity when the notification is clicked. To use this for deep linking, you can set the click_action to an action that your deep link Activity handles and include whatever deep link data you want in the FCM message data. Then in the deep link Activity, you can extract the deep link data from the FCM data payload in the Activity's Intent, if it exists (because it was started from an FCM notification click). |
@gsakakihara thanks for the response! Unfortunately it looks like that's not compatible with navigation-compose's deep linking support though (which we have been using since compose is recommended by Android team since 2022) https://developer.android.com/develop/ui/compose/navigation#deeplinks Would definitely be nice to have first class support for actual deep links for notification messages that is compatible with native android ui toolkit and native navigation-compose library. |
I'm not sure whether it would work, but NavDeepLink.Builder has setAction() or https://developer.android.com/reference/kotlin/androidx/navigation/NavDeepLinkDslBuilder#action() that should allow registering for a deep link based on action? |
We're using fcm's built in mechanism for displaying notifications when the app is in the background. This works well, but we stumbled upon a feature that I can't find a trace of. According to https://stackoverflow.com/questions/63378233/how-to-send-firebase-notifications-with-uris-to-implement-deep-linking you can send
gcm.n.link
in order to send a deeplink that's triggered when you click a notification. Though we I search this codebase I don't see any trace of it pulling that key in order to get the value to set for the deep link. If it's not doing that... then how is it setting up the deep link properly?The text was updated successfully, but these errors were encountered: