0

FCM message can be pushed from console and using api

from console (https://console.firebase.google.com)

using api (https://fcm.googleapis.com/fcm/send)

In both case when app is in foreground, message is received in service that extends FirebaseMessagingService, in onMessageReceived we can filter requests by custom param in bundle, but when app is in background and message is sent from console, receiver is not called, and the push message is somehow added.

Is possible to handle this request?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Alex
  • 8,908
  • 28
  • 103
  • 157

3 Answers3

0

When app is in background and you suppose to fire notification via console at that time notification will come in notification tray rather than going to your service.

That will mentioned in guidelines.

https://firebase.google.com/docs/cloud-messaging/android/receive

So if you want to still handle notifications then, you have to set proper payload for same. So that whenever user click on notification then it will react accordingly.

For disabling notification try following,

FirebaseInstanceId.getInstance().deleteInstanceId();
Mohit Trivedi
  • 699
  • 3
  • 13
0

Firebase Cloud Messaging support two types of messages:

  • Notification messages, sometimes thought of as "display messages." [When the app is not active], these are handled by the FCM SDK automatically.

  • Data messages, which are handled by the client app.

The Firebase console always sends notification messages, which are (when the app is not active) handled by the system. There is no way to intercept these messages in that case.

If you want to always receive the message in your application code, you should use a data message, which can only be sent using the API.

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
-1

Yes, it is possible to handle messages when app is in foreground/background. In both cases you can handle it by implementing onMessageReceived. The only difference is, You have to put data in your JSON Message. Here you can find more.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) { 
   Map<String, String> data = remoteMessage.getData();
   String myKey = data.get("myKey");
}
Hadi Mohammadi
  • 314
  • 2
  • 5
  • 20
  • When you send a message with console of fire base and app is in background, at that time onMessageReceived will not be called as per fire base guidelines. – Mohit Trivedi Mar 26 '19 at 11:41
  • @MohitTrivedi Here are documents about Receiving Notification and Sending Message From Console. None of them mentioned about Not receiving console messages in background by implementing onMessageReceived . https://firebase.google.com/docs/cloud-messaging/android/receive , https://firebase.google.com/docs/cloud-messaging/android/send-with-console – Hadi Mohammadi Mar 26 '19 at 11:57
  • Messages with both notification and data payload, when received in the background. In this case, the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity. – Mohit Trivedi Mar 26 '19 at 12:05