-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Android: 'onNotification' not executing when app is closed and clicked to notification #72
Comments
I'm having this same issue. I'm using node-gcm to send the notification to the app. |
Same here. Some help on how to overcome this issue would be great. |
UPDATE: It seems that onNotification is called after all when opening the app from the notification, but for some reason the YellowBox was not appearing when calling |
@eduardb even when your application is completely closed? |
Completely, as in swiped away from the recents screen, yes. |
Awesome, i couldn't achieve that. Would you be so kind to share some On Wed, May 25, 2016 at 1:43 PM, Eduard Bolos [email protected]
|
Have a look over this PR: novoda/spikes#57 |
@eduardb how exactly do you have the Alert firing? I have an alert on the first line in onNotification, and it's working fine when the app is closed for iOS, but for Android it's not triggering. |
After some debugging it looks like the @zo0r : any ideas on this? iOS working fine with clicking on notifications. |
if revert this commit, It work? |
I don't know if its related but I never get |
@npomfret https://github.com/rskull/react-native-push-notification |
Sending a notification with only the "data" field set (remove the "notification" field) works. Clicking on a notification triggers |
Hey all, When the app is closed (swiped from recent on android and swiped up in iOS) and I receive a notification, it is displayed properly by the OS but when I click it the In iOS I receive: In Android I receive: Other then that everything seems to work perfectly! Any idea what is going on? Thanks, |
I'm facing the same issue, the approach of @eduardb is not working for me, nothing is triggered when the app is entirely closed, I tried using the @florindobre Could you please provide a simple example snippet of you test?
How can we solve this? |
@frangeris This pull request was supposed to resolve this issue 137 Not sure @zo0r published a new version yet but you can checkout this version and see if that works for you |
@kfiroo Thanks for the info. Not sure if I'm correct, Am I missing something? module.exports = React.createClass({
componentWillMount() {
PushNotification.configure({
popInitialNotification: (notification) => {
// when app is entirely closed and click on push notification
console.log('received', notification)
},
onNotification: (notification) => {
// ...
}
})
// ...
}
}) |
@frangeris Looks like you might have misread the docs When calling Hope that makes sense to you :) |
@kfiroo Thanks for the aclaration, about the value of the property as function instead of boolean, I was just testing a different approach, because neither of both is working for me, but ok using true (default) still not working. Thanks |
@frangeris I think we need more information to be able to help you, like:
|
Thanks |
@frangeris @kfiroo when the app is entirely closed (Android) the callback |
@zo0r then how do we trigger the notification message when the app is closed, or is this not possible? |
Thanks @zo0r, valuable information! What would you suggest for approach this? |
@frangeris @amrdraz its not possible for now (2.0.1), I think a way to capture and execute the callback is re-open the activity in background (open and moveTaskToBack?) (if dead) and then execute As its not an user-intended behavior, (I think) sending the Note that forcesReactNativeDelivery thing is not implemented yet, just a suggestion. |
@zo0r @amrdraz @frangeris Actually my PR made it possible, I'm using it in my app on production. If I understand it correctly, this is the case in every Android app, the app is closed so you cannot handle the initial notification right away. In RNPushNotificationHelper.java#L213 we create a What do you think? |
@kfiroo you're right, but as I understand what @frangeris want is the @frangeris Am I right? |
Not exactly that case, this is the perfect scenario:
If I could get That's what I can't get @kfiroo, could you provide an example snippet please? |
@frangeris When I think about it I had some trouble finding the right structure of the notification I send from my server, that might be your problem! my GCM payload looks like this: JSON.stringify({
data: {
message: 'some message text',
sound: 'default',
// custom data goes here
data: JSON.stringify({
key: 'value'
})
}
}) |
@kfiroo I confirm that when I sent myself a push notification with the correct format it worked |
so the problem is that I test push notifications using this script curl -X POST -H "Authorization: key=MYAPIKEY" -H "Content-Type: application/json" -d '
{
"data": {
"Title": "Hello there",
"Breif": "I got this"
},
"to" : "REGISTRATIONID"
}' 'https://gcm-http.googleapis.com/gcm/send' changed it to curl -X POST -H "Authorization: key=MYAPIKEY" -H "Content-Type: application/json" -d '
{
"data": {
"title": "Hello there",
"message": "some message text",
"data": {
"Title": "Hello there",
"Breif": "I got this"
}
},
"to" : "REGISTRATIONID"
}' 'https://gcm-http.googleapis.com/gcm/send' @kfiroo @zo0r and the second question is what are the available options? do I get to pass all the other otpions available to me in the localNotification method? Either way this is enough for now thank you for your time |
@amrdraz I'm using Firebase Cloud Messaging, so checking docs... Thanks @kfiroo |
@amrdraz Great to hear that! Currently, as I can see from the code, the only restrictions are that the top level object will have a Here we look for the data field on the root object - RNPushNotificationListenerService.java#L18 - not sure it's mandatory. |
Hey @kfiroo @amrdraz I've no idea why now is working :| This is what I did, I was using firebase endpoint (not working), then I changed to test using the code of @amrdraz (using GCM endpoint), start working, rollback and test again with firebase endpoint, works... :/ Is possible that switching between endpoint could fix something behind scenes? Another note is that curl -X POST -H "Authorization: key=<MY_KEY>" -H "Content-Type: application/json" -d '
{
"data": {
"title": "Hello there",
"message": "some message text",
},
"to" : "<DEVICE_TOKEN>"
}' 'https://fcm.googleapis.com/fcm/send' And from React native: module.exports = React.createClass({
componentWillMount() {
PushNotification.configure({
// popInitialNotification: true,
onNotification: (notification) => {
console.log(notification)
}
})
}
}) Thank's guys for the help! |
@frangeris Great to hear :) |
@zo0r I think we can close this |
Yep, go ahead... |
shouldnt some of this be in the documentation ? it ended up working for me but its fairly non trivial to understand that you need a specific message format to get a notification displayed and clicked with the app closed to trigger onNotification |
If you are overriding onNewIntent in This could happen if you were to, say, use react-native-branch-deep-linking and follow their setup instructions you would override onNewIntent like this @Override
public void onNewIntent(Intent intent) {
setIntent(intent);
} A possible fix to get onNotification to fire is to add super.onNewIntent(intent): @Override
public void onNewIntent(Intent intent) {
setIntent(intent);
super.onNewIntent(intent)
} |
[android]
Hello, when I put app in the background and I get push notification then
onNotification
is executed as I expect. But when I close app (using android back button) and I get push notification thenonNotification
is not executed.I know
onNotification
is fired from Java inonNewIntent
method. But I really need to pass some data from notification into JavaScript when application was closed before and I click on notification.How to do it?
The text was updated successfully, but these errors were encountered: