I am getting push notification from firebase but when I sent it using the "https://fcm.googleapis.com/fcm/send" on android in react native using react-native-firebase library, I do not get any notification on android. However I am able to display the message on the console using "onMessage" method. But how I can get notification in the notification bar. My message is data-only therefore I also created bgMessaging.js for handling background message and here also I am able to display message on console but not on notification.
How I can fix this issue and display the message on the notification bar with data-only messages.
Below is my code
bgMessaging.js
import firebase from 'react-native-firebase';
// Optional flow type
import type { RemoteMessage } from 'react-native-firebase';
export default async (message: RemoteMessage) => {
// handle your message
console.log("message")
console.log(message)
// senName = message.data.senderName;
// senUid = message.data.senderUid;
// const notification = new
// firebase.notifications.Notification()
// .setNotificationId('notificationId')
// .setTitle(message.data.title)
// .setBody(message.data.body)
// .android.setChannelId('channel_id_foreground')
// .android.setSmallIcon('ic_launcher');
// firebase.notifications().displayNotification(notification);
return Promise.resolve();
}
index.js(following lines added at the end)
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging); // <-- Add this line
App.js
componentDidMount() {
this.messageListener = firebase.messaging().onMessage((message: RemoteMessage) => {
//process data message
console.log(message);
});
}
AndroidManifest.xml
<service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" />
<service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<service android:name=".MyTaskService" />