React-native-push-notification: Detect Notification interaction on Android not working?

Created on 22 Dec 2016  路  4Comments  路  Source: zo0r/react-native-push-notification

On iOS my handleNotification() get called when the app has been brought to the foreground via a click on the notification. This does not seem to happen on Android though. Should I be going another route for this instead?

The notification is getting to the device ok. It just doesn't trigger the handler when tapped.

Version 2.2.1
RN 0.35

  componentDidMount(){
    PushNotification.configure({
    onRegister: (token) => {
        console.log( 'TOKEN:', token );
        this.handlePushRegistration(token);
    },
    onNotification: (notification) =>  {
        console.log( 'NOTIFICATION:', notification );
        this.handleNotification(notification);
    },
    senderID: "xxxxx", // I have entered the ID here
    permissions: {
        alert: true,
        badge: true,
        sound: true
    },
    popInitialNotification: true,
    requestPermissions: false,
  });

  handleNotification(notification){
    // never gets called on Android but works on iOS
  }
Stale

Most helpful comment

Same behavior, when application in foreground it works as expected.
But if application in background and receive silent notification:

  • onNotification called when message received in background and after that I initiate localNotification.
  • When user tap on notification in notification center -> application launch, but onNotification not triggered.

UPD: in foreground working as expected.
UPD2: Logs from logcat when tapping on notification (app in background)

04-26 11:27:44.111 2816-3570/? I/ActivityManager: START u0 {flg=0x20000000 cmp=com.client/.MainActivity (has extras)} from uid 10169 on display 0 from pid -1
04-26 11:27:44.111 2816-3570/? W/ActivityManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { flg=0x20000000 cmp=com.client/.MainActivity (has extras) }
04-26 11:27:44.121 3054-3054/? W/StatusBar: removeFakeNotificationViews()---removeNotification for unknown pkg: com.client
04-26 11:27:44.201 25047-25047/com.client W/unknown:React: Packager connection already open, nooping.
04-26 11:27:44.201 25047-25047/com.client W/unknown:React: Inspector connection already open, nooping.
04-26 11:27:44.251 25047-25653/com.client I/OpenGLRenderer: Initialized EGL, version 1.4
04-26 11:27:44.341 25047-25110/com.client I/ReactNativeJS: Running application "client" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
04-26 11:27:44.351 2816-2911/? I/ActivityManager: Displayed com.client/.MainActivity: +239ms
04-26 11:27:44.371 25047-25111/com.client W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextShadowNode
04-26 11:27:54.221 25047-25083/com.client I/System.out: url:https://e.crashlytics.com/spi/v2/events
04-26 11:27:54.221 25047-25083/com.client I/NetworkManagementSocketTagger: untagSocket(35)
04-26 11:27:54.781 25047-25083/com.client I/NetworkManagementSocketTagger: untagSocket(35)
04-26 11:28:41.861 25047-25047/com.client W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
04-26 11:28:41.871 25047-25047/com.client W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
04-26 11:28:41.871 25047-25047/com.client W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
04-26 11:28:41.881 25047-25047/com.client W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
04-26 11:28:41.881 25047-25047/com.client W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection

@mikelambert @zo0r @npomfret

All 4 comments

Same behavior, when application in foreground it works as expected.
But if application in background and receive silent notification:

  • onNotification called when message received in background and after that I initiate localNotification.
  • When user tap on notification in notification center -> application launch, but onNotification not triggered.

UPD: in foreground working as expected.
UPD2: Logs from logcat when tapping on notification (app in background)

04-26 11:27:44.111 2816-3570/? I/ActivityManager: START u0 {flg=0x20000000 cmp=com.client/.MainActivity (has extras)} from uid 10169 on display 0 from pid -1
04-26 11:27:44.111 2816-3570/? W/ActivityManager: startActivity called from non-Activity context; forcing Intent.FLAG_ACTIVITY_NEW_TASK for: Intent { flg=0x20000000 cmp=com.client/.MainActivity (has extras) }
04-26 11:27:44.121 3054-3054/? W/StatusBar: removeFakeNotificationViews()---removeNotification for unknown pkg: com.client
04-26 11:27:44.201 25047-25047/com.client W/unknown:React: Packager connection already open, nooping.
04-26 11:27:44.201 25047-25047/com.client W/unknown:React: Inspector connection already open, nooping.
04-26 11:27:44.251 25047-25653/com.client I/OpenGLRenderer: Initialized EGL, version 1.4
04-26 11:27:44.341 25047-25110/com.client I/ReactNativeJS: Running application "client" with appParams: {"initialProps":{},"rootTag":1}. __DEV__ === false, development-level warning are OFF, performance optimizations are ON
04-26 11:27:44.351 2816-2911/? I/ActivityManager: Displayed com.client/.MainActivity: +239ms
04-26 11:27:44.371 25047-25111/com.client W/unknown:ViewManagerPropertyUpdater: Could not find generated setter for class com.facebook.react.views.text.ReactVirtualTextShadowNode
04-26 11:27:54.221 25047-25083/com.client I/System.out: url:https://e.crashlytics.com/spi/v2/events
04-26 11:27:54.221 25047-25083/com.client I/NetworkManagementSocketTagger: untagSocket(35)
04-26 11:27:54.781 25047-25083/com.client I/NetworkManagementSocketTagger: untagSocket(35)
04-26 11:28:41.861 25047-25047/com.client W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
04-26 11:28:41.871 25047-25047/com.client W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
04-26 11:28:41.871 25047-25047/com.client W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
04-26 11:28:41.881 25047-25047/com.client W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection
04-26 11:28:41.881 25047-25047/com.client W/IInputConnectionWrapper: getExtractedText on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
04-26 11:28:41.891 25047-25047/com.client W/IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection

@mikelambert @zo0r @npomfret

the problem occurs due to the variable
hasPoppedInitialNotification is set to true after the app is initialized.
so when android go into background and opened through notification click again,
the popInitialNotification function will not be called

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings