react-native-push-notification: onNotification is not called when a remote notification is pressed on Android

Hi, onNotification is not get called when i press a notification. The doc https://github.com/zo0r/react-native-push-notification#usage says that onNotification Called when a remote or local notification is opened or received.

This callback is called twice when a notification is received: 1. {collapse_key: "XX" foreground: true google.delivered_priority: "high" google.message_id: "0:1587387492329033%3a743ff23a743ff2" google.original_priority: "high" google.sent_time: 1587387492305 google.ttl: 2419200 id: "-1393396919" issueId: "XX" notification: body: "XX" sound: "default" tag: "XX" title: "XX" userInteraction: false} 2. {foreground: true id: "-1409941121" issueId: "XX" message: "XX" title: "XX" userId: "XX" userInteraction: false}

Can anybody help me with this problem?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 94

Most upvoted comments

@Dallas62 I opened a new issue since I think the one you mentioned describes a different problem. I hope this is ok.

@Dallas62 of course, I will make it ASAP, and give the report.

@Dallas62 i guess this is an error in docs. The code below should be in android/app/build.gradle, but not in android/build.gradle

dependencies {
    ...
    implementation project(':react-native-push-notification')
    ...
 }

I’m using manual linking, so this is important.

Yes, onNotification is called when the app is active in foreground and when the notification is opened/touched in background and quit state. And notifications appear as soon as the app is not in foreground state.

Firebase worked for me as well for receiving the notifications but I was unable to detect, when they were opened which is why I switched to the above solution.

same problem onNotification does not call when I click the notification from the tray instead it reopens the app and onRegister get triggered

same problem here, the onNotification is called only on foreground or for local notifications. If i press the remote notification nothing happens, only open the app.

@anisimov74 In the example folder 😉

I’m also unable to get onNotification called when the app in a background mode or killed. PushNotification.popInitialNotification always returns null

@Dallas62 here it is

<uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

<uses-permission android:name="android.permission.WAKE_LOCK" />
    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <!-- < Only if you're using GCM or localNotificationSchedule() > -->

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

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

        <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/ic_notification"/>

        <meta-data
            android:name="com.dieam.reactnativepushnotification.notification_color"
            android:resource="@color/notification_color"/>

        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value=""/>
        <meta-data  android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value=""/>

        <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="XX" />
            </intent-filter>
        </receiver>
        <!-- < Only if you're using GCM or localNotificationSchedule() > -->

        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
        <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

        <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <!-- </ Only if you're using GCM or localNotificationSchedule() > -->

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