-1

I an using FCM for sending a notification in my app and all work perfectly but when my app is in background then the notification is handle by android system notification tray

i want to handle my notification from myself i am sending this payload for send the notification

$fields = array(
        'notification' => $notification,
        'to'  => '/topics/updates'
        );

this will call my onMessageReceived when my app is in forground but when my app is in background this will not call my onMessageReceived the request is handled by system itself

i want to call my onMessageReceived when my app is in background

i am also try to remove notification key and only send data key like this

$fields = array(
        'data' => $notification,
        'to'  => '/topics/updates'
        );

but when i send the request from above field onMessageReceived is not called in both the condition in forground and background

i am try this in my xiaomi redmi note 4 (oreo) , redmi 4x(android 10) and android emulator(marshmello)

i am follow this ans for solve my problem but not work for me How to handle notification when app in background in Firebase

my FCM version is 17.3.4 and my android studio version is 3.5.3

Dinesh
  • 1,410
  • 2
  • 16
  • 29
Hemant Prajapat
  • 125
  • 2
  • 14

2 Answers2

0

If the data message is not received then the payload might be wrong. Here is my payload example (.js, but the structure should be pretty much the same):

const  payload = {
            data: {
                title: finalTitle,
                body: message,
                icon: icon
            },
            topic: channel
        };

admin.messaging().send(payload)
        .then((response) => {
            return
        })
Simon
  • 1,657
  • 11
  • 16
0

sorry for post this stupid questions FCM work in background when we post only data key not notification key

my mistake is this i wrap my notification builder by this

if (remoteMessage.getNotification() != null) {
 // other code
}
Hemant Prajapat
  • 125
  • 2
  • 14