0

From Google documentation:

Handle notification messages in a backgrounded app

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

But I need to handle tap and forward to my specific activity on my app (when app in background).

class CustomFirebaseMessagingService : FirebaseMessagingService() {


    /*-
        Call this method only when app is foreground.
     
    */
    override fun onMessageReceived(remoteMessage: RemoteMessage?) {

Method onMessageReceived called only when app is in foreground.

a_subscriber
  • 8,977
  • 15
  • 60
  • 141

1 Answers1

1

Firebase Cloud Messages supports two types of messages: notification messages and data messages.

Notification messages get handled by the OS when your app is backgrounded. There is nothing you can change about that.

What you can do is send a data message, which is delivered to your application's onMessage handler no matter whether the app is active or not. Since this onMessage can be called even when the app is not active, it is in a FirebaseMessagingService class and not in an Activity.

Also see the Firebase documentation on handling messages on Android.

Frank van Puffelen
  • 418,229
  • 62
  • 649
  • 645
  • Is it possible to send data message from Firebase console? – a_subscriber Jul 02 '20 at 18:56
  • 1
    No. The Firebase console can only send Notification messages. But it's quite easy to do in code or from a command line: https://stackoverflow.com/questions/37371990/how-can-i-send-a-firebase-cloud-messaging-notification-without-use-the-firebase (the sample there sends a notification, but you can change the data) – Frank van Puffelen Jul 02 '20 at 19:48