FCM Background Notification Deeplinking not working for android

Viewed 667

I have tried to setup FCM notifications to work with deeplinks. If the app is in foreground, then we have the handling of notifiations by using FirebaseMessaginService and then everything works properly. The problem comes when the app is killed and there is this background service from Firebase that shows the notifications. And I just can't find a way to make the deeplinks work out of the box. The current solution is put the deeplink in extras and check the intent when app starts. But would be nicer to skip this and just let the notification propagate the proper deeplinks.

So here is the manifest for activity. Deeplinks are up by <nav-graph .... />

        <activity
        android:name="com.*****.******.view.main.MainActivity"
        android:exported="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait">
        <nav-graph android:value="@navigation/services_graph" />
        <nav-graph android:value="@navigation/infobox_graph" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

And of course setup of the service

        <service
        android:name=".usecase.notifications.OscaPushService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>

This should all be enough for FCM setup right ? (of course the keys are also set)

Now I try to send the deeplink using this payload:

                "androidNotification":{
                "click_action": "example://infobox/"
            },

Then on click on notification nothing will happen. ActivityTaskManager will print following message and that's it:

I/ActivityTaskManager: START u0 {act=example://infobox/ flg=0x14000000 pkg=com.*****.*****.** (has extras)} from uid 10374 (replaced pkg with stars)

Which is different from launching a deeplink using adb shell commands.

adb shell am start -d example://infobox/   

Would print

I/ActivityTaskManager: START u0 {dat=citykey://infobox/ flg=0x10000000 cmp=com.****/com.******} from uid 2000

Launching the deeplink in this way will actually work. Any idea why it happens ?

1 Answers

Judging by the logs, there is a main difference. The one that works has "data", which is the one that you start with adb. The one that doesn't work has an "action", which is different than "data". You need to pass the "data" instead of "click_action" in the "androidNotification". Basically, "click_action" is for Intent.setAction() whereas the adb command you specified does Intent.setData(). Those two are different.

You should probably use a data notification for these anyway, which will trigger your service even if your app is in foreground or if it was killed. Then you can create your notification properly from the app directly.

Related