Open rimzici opened 7 years ago
pasting the debug results here: would appreciate if the team can suggest what Iam doing wrong. ON PRESSING CUSTOM NOTIFICATION:
08-23 22:56:14.547 25764-25764/com.testsample D/ActivityThread: BDC-Calling onReceive: intent=Intent { flg=0x10 cmp=com.testsample/io.neson.react.notification.NotificationEventReceiver (has extras) }, receiver=io.neson.react.notification.NotificationEventReceiver@77a82b3 08-23 22:56:14.548 25764-25764/com.testsample I/ReactSystemNotification: NotificationEventReceiver: Recived: DEFAULT, Notification ID: 1337, payload: {"number":1,"what":true,"someAnswer":"42"} 08-23 22:56:14.553 25764-25764/com.testsample I/ReactSystemNotification: NotificationEventReceiver: launchIntent: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x14000000 pkg=com.testsample cmp=com.testsample/.MainActivity (has extras) } 08-23 22:56:14.554 25764-25764/com.testsample I/ReactSystemNotification: NotificationEventReceiver: context: android.app.ReceiverRestrictedContext@1c640a30 08-23 22:56:14.578 25764-25764/com.testsample I/ReactSystemNotification: NotificationEventReceiver: Launching: com.testsample 08-23 22:56:14.579 25764-25764/com.testsample D/ActivityThread: BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { flg=0x10 cmp=com.testsample/io.neson.react.notification.NotificationEventReceiver (has extras) } packageName=com.testsample resultCode=0 resultData=null resultExtras=null} 08-23 22:56:14.581 25764-25790/com.testsample D/OpenGLRenderer: Flushing caches (mode 0) 08-23 22:56:14.581 25764-25790/com.testsample D/OpenGLRenderer: Flushing caches (mode 0) 08-23 22:56:14.587 25764-25764/com.testsample D/ActivityThread: ACT-NEW_INTENT handled : 0 / NewIntentData{intents=[Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x14400000 pkg=com.testsample cmp=com.testsample/.MainActivity (has extras) }] token=android.os.BinderProxy@3965242e} 08-23 22:56:14.587 25764-25764/com.testsample V/ActivityThread: Performing resume of ActivityRecord{22d326a9 token=android.os.BinderProxy@3965242e {com.testsample/com.testsample.MainActivity}} 08-23 22:56:14.604 25764-25764/com.testsample D/ActivityThread: ACT-AM_ON_RESUME_CALLED ActivityRecord{22d326a9 token=android.os.BinderProxy@3965242e {com.testsample/com.testsample.MainActivity}} 08-23 22:56:14.604 25764-25764/com.testsample V/ActivityThread: Resume ActivityRecord{22d326a9 token=android.os.BinderProxy@3965242e {com.testsample/com.testsample.MainActivity}} started activity: false, hideForNow: false, finished: false 08-23 22:56:14.604 25764-25764/com.testsample V/ActivityThread: Resuming ActivityRecord{22d326a9 token=android.os.BinderProxy@3965242e {com.testsample/com.testsample.MainActivity}} with isForward=true 08-23 22:56:14.604 25764-25764/com.testsample V/PhoneWindow: DecorView setVisiblity: visibility = 0 ,Parent =ViewRoot{339b80ea com.testsample/com.testsample.MainActivity,ident = 0}, this =com.android.internal.policy.impl.PhoneWindow$DecorView{2701db1d V.E..... R.....ID 0,0-1080,1920} 08-23 22:56:14.604 25764-25764/com.testsample V/ActivityThread: Scheduling idle handler for ActivityRecord{22d326a9 token=android.os.BinderProxy@3965242e {com.testsample/com.testsample.MainActivity}} 08-23 22:56:14.605 25764-25764/com.testsample D/ActivityThread: ACT-RESUME_ACTIVITY handled : 1 / android.os.BinderProxy@3965242e 08-23 22:56:14.621 25764-25790/com.testsample D/OpenGLRenderer: CanvasContext() 0xaaf50d08 initialize 0xab0a2f48 08-23 22:56:14.621 25764-25790/com.testsample D/Surface: Surface::connect(this=0xab0a2f40,api=1) 08-23 22:56:14.622 25764-25764/com.testsample V/InputMethodManager: onWindowFocus: null softInputMode=288 first=true flags=#81810100 08-23 22:56:14.622 25764-25790/com.testsample D/mali_winsys: new_window_surface returns 0x3000 08-23 22:56:14.622 25764-25764/com.testsample V/InputMethodManager: START INPUT: com.android.internal.policy.impl.PhoneWindow$DecorView{2701db1d V.E..... R.....ID 0,0-1080,1920} ic=null tba=android.view.inputmethod.EditorInfo@c6e6070 controlFlags=#104 08-23 22:56:14.622 25764-25790/com.testsample D/Surface: Surface::allocateBuffers(this=0xab0a2f40) 08-23 22:56:14.632 25764-25790/com.testsample D/Surface: Surface::setBuffersDimensions(this=0xab0a2f40,w=1080,h=1920) 08-23 22:56:14.633 25764-25790/com.testsample D/GraphicBuffer: register, handle(0xab0bd778) (w:1080 h:1920 s:1088 f:0x1 u:0x000b00)
Thanks In Advance
Where are you registering your press event listening function?
In the index page inside componentWillMount() { Notification.addListener('press', function(e) { console.log(e); }); }
alse tried with DeviceEventEmitter none works finally i found what could be causing the issue, Not sure yet. I am using SplashScreen for my android app. Suspecting that SplashScreen Activity, one which takes place before my MainAcivity blocking the data? Thanks @andy9775
Hmm. Can you try registering in the constructor? I had a similar issue where it wasn't getting called and that solved it for me.
You could also be right about the splash screen activity I haven't experienced this type of scenario so I can't really comment on it though.
I have used react-native-gcm-android and react-native-system-notification.
Aftre research, the root cause could be: After react native v0.29, all native modules are migrated from MainActivity to MainApplication. Click notificaiton will send intent that contains notification info to launch App. We need to get this intent in app to get its notification info. But GcmModule is loaded before MainActivity launched because of migration of all native modules. So if we get this intent in MainApplication, that could be nothing. We need to get this intent in MainActivity and figure out way to send it into JavaScript side
If my thought is wrong, please point out.
@rimzici
i am using react-native-fcm, react-native-system-notification and need to generate push notification on background and foreground.
Problem is i am using RN 0.32 and react-native-fcm that provide local-notification on RN > 0.33
So i tried to generate local notification by react-native-system-notification, now i am able to do that on fcm notification event writing react-native-system-notification oncreate event.
componentDidMount() { FCM.on('notification', (notif) => { console.log('notif on foregournd', notif, FCM); Notification.create({ subject: 'Hey', message: 'Yo! Hello world.' }); });
but when click on it, it does not work.
I have registered react-native-system-notification in willmount like this.
componentWillMount() { this.setState({loadSpinner: true}, () => { // FCM.getFCMToken().then(token => { // this.props.dispatch(postPushNotificationDetails(token, DeviceInfo.getUniqueID())); // }); this.props.dispatch(fetchNewOrders(this.state.currentPage)); }); Notification.addListener('press', function(e) { console.log('Notification.addListener(press)'); }); }
The problem here is the following: The module here has two states only, if in foreground to the user, in which case there is no problem. And if the app is not in foreground (background, dead, service-only), in which the notification works only if the app is dead (completely or service-only). If the app is not foreground (from this module's point of view) then an intent to launch the application is sent along with the notification info. This would work only when the app is dead because of this line of code: https://github.com/neson/react-native-system-notification/blob/master/index.android.js#L67 The initial notification is checked when you add a listener to the press/click event only. Which means if the app is coming from the background, and the listener is already hooked, this piece of code won't run! Im trying to find the best solution for this problem as i write this comment. Will do a pull request once im done. But a viable temporary solution would be the following: listen to AppState changes, remove the listener when going to background and re-add it when you transition back to foreground.
componentDidMount() {
Notification.addListener('press', this.notificationPress);
AppState.addEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange(currentAppState) {
if (currentAppState === 'background') {
Notification.removeAllListeners('press');
} else {
Notification.addListener('press', this.notificationPress);
}
},
@Sh3rawi I've tried your solution with RN 0.39 but I still don't get any events when the notification is clicked when the app is in the background
@freakinruben, that worked for us at that time. Currently though, we do not use this library anymore. We switched to fcm from gcm, and react-native-fcm has built-in support for local notifications that covers our needs.
node modules versions: "react": "^15.2.1", "react-native": "^0.31.0", "react-native-system-notification": "^0.2.0", "react-native-fcm": "^1.0.16",
tried with "react-native": "^0.29.0", also. have made all config changes told in react-native-system-notification docs.added android:launchMode="singleTask" in manifest file. and issue of app loading every time , even when launching from background got solved, now it resumes. So after that the event listener is not working. Notification.addListener('press', function(e) { console.log(e); }); the listener works when app is running in the foreground. But in the background app launches on clicking notification but event listener not triggered. Any Suggestions ? Thanks in advance.