I'm trying to display a data message on my Android tray when the app is closed by users, i.e. when the user drags app to the side in recent app list. Althought, data messages are just being received like this:
- App is closed. Data message sent.
- Message is not received when app is closed.
- App is opened.
- After 4~5 minutes data message is received and displayed in Android tray.
To achieve that, I'm using react-native-firebase lib, following its docs.
import firebase from 'react-native-firebase';
import type { RemoteMessage } from 'react-native-firebase';
export default async (message: RemoteMessage) => {
const notifPromise = new Promise((resolve, reject) => {
let notification = new firebase.notifications.Notification();
notification.android.setPriority(firebase.notifications.Android.Priority.High);
notification.android.setChannelId("test-channel");
resolve(firebase.notifications().displayNotification(notification));
});
console.log("MESSAGE IN BACKGROUND OR APP CLOSED");
return notifPromise.resolve();
}
The code above works fine in the background, I mean when the app is just "minimized" to the secondary plan.
AndroidManifest.xml, HeadlessTask and MainApllication.java are theoretically in accordance with docs. I'm just showing blank UI in Android tray to test.
Message being sent from Postman:
{
"to": "erVxmCT6rgA:APA91bGn6q9...",
"data": {
"custom1": "custom1",
"custom2": "custom2"
}
}
Questions: What could be wrong once it works on background? Why is this behavior happening?