In IOS, I can create a Notification Service Extension (via UNNotificationServiceExtension) to modify incoming notification messages (notifications that have title and body in their payload).
Is there something equivalent for that with Android? I currently use Firebase FCM to process background notifications, but the FCM library callback only works with data-only notifications, if I send a notification with title and body in the payload, the callback will not be called.
Looking around, it seems that NotificationCompat.Extender is what I'm looking for.
To test it I created the following implementation:
package com.tip_off.test
import androidx.core.app.NotificationCompat
internal class NotificationServiceExtension : NotificationCompat.Extender {
override fun extend(builder: NotificationCompat.Builder): NotificationCompat.Builder {
builder.setContentTitle("KOTLIN TEST")
.setContentText("KOTLIN HELLO")
return builder
}
}
And tried to register it as a service in the AndroidManifest.xml with:
<application>
...
<service android:name=".MyNotificationExtenderService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
<intent-filter>
<action android:name="com.tip_off.test.NotificationServiceExtension" />
</intent-filter>
</service>
...
</application>
What I was expecting is that any notification message would go through this service and replace the notification title with "KOTLIN TEST" and the body with "KOTLIN HELLO" but the code is never called.
How can I achieve this in Android?