Wednesday, 12 January 2022

FCM Background Notification Deeplinking not working for android

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 ?



from FCM Background Notification Deeplinking not working for android

No comments:

Post a Comment