0

so I've been trying to do this app but for some reason, after I can't seem to be able to detect notification from the firebase consol when the app is closed (not in the background or frontground those work fine).

so here are some of the relevant files.

componentDidMount() {
            this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
                    // Process your notification as required
                    // ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
            });
            this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
                    // Process your notification as required
                    notification.android.setChannelId('test-channel')
                    console.log("I'm called haha", notification);
                    firebase.notifications().displayNotification(notification)
            });
            this.messageListener = firebase.messaging().onMessage((message) => {
                    bgMessaging(message)
            })
    }

    componentWillUnmount() {
            this.notificationDisplayedListener();
            this.notificationListener();
    }

android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.mobalib">
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="false"
        android:theme="@style/AppTheme">

      <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
        <intent-filter>
              <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
        <receiver android:name="io.invertase.firebase.notifications.RNFirebaseBackgroundNotificationActionReceiver"
                              android:exported="true">
              <intent-filter>
                <action android:name="io.invertase.firebase.notifications.BackgroundAction"/>
              </intent-filter>
        </receiver>
      </service>
      <service
              android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"
              android:enabled="true"
              android:exported="true">
        <intent-filter>
              <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
      </service>
      <activity
              android:launchMode="singleTop"
              android:name=".MainActivity"
              android:label="@string/app_name"
              android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
              android:windowSoftInputMode="adjustResize">
        <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
  </application>
</manifest>

index.js:

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging);

and finaly bgMesseging.js:

xport default (message: RemoteMessage) => {
    // handle your message
    const title = message.get
    const notification = new firebase.notifications.Notification()
              .setNotificationId('notificationId')
              .setTitle('My notification title')
              .setBody('My notification body')
              .setData({
                      key1: 'value1',
                      key2: 'value2',
              });
    notification
            .android.setChannelId('test-channel')
    firebase.notifications().displayNotification(notification)
    console.log(message);
    return Promise.resolve();

}

julia
  • 139
  • 3
  • 11

1 Answers1

-1

the TL/dr is that depending on what brand your phone is the notification can only be detected.

so Android not that great when it comes to this part of notification but it is so customisable on other thing that i do like it

julia
  • 139
  • 3
  • 11