Firebase Cloud Messaging(FCM)向我的应用程序发送推送消息。当应用程序关闭时,这些消息会显示在系统托盘中。
任务是:当用户点击托盘中的推送通知时,打开应用程序并执行某些操作(例如打开另一个片段)。
问题在于,我不知道如何重写用户单击推送通知时的默认行为。是否有某种回调、广播接收器等?
我的FirebaseMessagingService:
任务是:当用户点击托盘中的推送通知时,打开应用程序并执行某些操作(例如打开另一个片段)。
问题在于,我不知道如何重写用户单击推送通知时的默认行为。是否有某种回调、广播接收器等?
我的FirebaseMessagingService:
class FCMHandlerService : FirebaseMessagingService() {
private val intercomPushClient = IntercomPushClient()
override fun onMessageReceived(remoteMessage: RemoteMessage) {
logd("onMessageReceived $remoteMessage")
val notification = remoteMessage.notification ?: return
logd("Remote message body${notification.body} channel id${notification.channelId} message id${remoteMessage.messageId}")
//you can create here your custom notification when the app receives push being foreground
}
override fun onNewToken(token: String) {
super.onNewToken(token)
logd("onNewToken $token")
instance.sendFirebasePushRegistrationToken(token)
}
}
清单中的服务
<service
android:name=".old.push.FCMHandlerService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>