Mehdi Meshkatian
Mehdi Meshkatian

Reputation: 318

react-native-push-notification foreground notification

I am developing an app via react native.
I need send some data with push notifications but in android when I receive notification its show in the screen.
I configured notifications like below:

PushNotification.configure({

    onRegister: function(token) {
        Fetcher("userSetNotifToken",{notifToken:token.token},true);

    },
    onNotification: function(notification) {
        console.log(notification);
        if(platform  == 'ios') {
            if (notification.alert.extra !== undefined && notification.alert.extra.type == 'trip') {
                alert("sad");
            }
            notification.finish(PushNotificationIOS.FetchResult.NoData);
        }else{
            if (notification.data !== undefined && notification.data.type == 'trip') {
                Actions.reset("home", {trip: notification.data.trip});
            }
        }
    },
    senderID: "----",
    permissions: {alert: true, badge: true, sound: true},
    popInitialNotification: false,
    requestPermissions: true,
});

Is there any way to disable this option ?

Upvotes: 0

Views: 2994

Answers (2)

Avijit
Avijit

Reputation: 1313

Updated as per version 6.1.3 Add this inside application in AndroidManifest.xml. https://github.com/zo0r/react-native-push-notification/blob/master/example/android/app/src/main/AndroidManifest.xml

  <service
      android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
      android:exported="false" >
      <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
  </service>

  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
              android:value="false"/>
  <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
              android:resource="@android:color/white"/>
</application>

Upvotes: 0

Mehdi Meshkatian
Mehdi Meshkatian

Reputation: 318

i found the solution in node_modules folder under the react-native-push-notification folder :

java/com/dieam/reactnativepushnotification/modules/RNPushNotificationListenerService.java

i changed this :

pushNotificationHelper.sendToNotificationCentre(bundle);

to this :

if (!isForeground) {
pushNotificationHelper.sendToNotificationCentre(bundle);
}

Upvotes: 1

Related Questions