-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android: Handling received push notifications (in app's foreground/background state) #1801
Comments
Hi @robertgreso This question has already been answered in the last ten issues. Regards, |
Hi @Dallas62, I checked all the issues before creating this one and also double checked now but couldnt find the answer how to make it work to get onNotification called on Android once user taps on notification, when in foreground/background. I just found as you pointed someone else to troubleshooting page where it says "Tapping the alert in the notification centre will start or bring the app to the foreground and onNotification will be called.", so I guess onNotification should be called in the case I described but it is not working for me. |
Hi @Dallas62 ! #1592 #868 I wasnt able to find any info in this issue that would help me to fix the issue I am having. Do you have any idea what could be the root of the issue? I would really appreciate your help. |
@Dallas62 any idea what could be wrong? Would appreciate any help thanks! |
Hi @robertgreso
I'm a not sure what's the problem, there is many cases listed (
The |
Hi @Dallas62, unfortunately I am not sure if I can share with you here AndroidManifest or whole project as this is a project that whole company is based on and already in stores for many years so some info there is confidential but here is part of AndroidManifest that could be relevant to this issue:
And here is example of the notification payload:
About that What I would love to achieve here is to get Thank you for all your help! |
The problem is that I can't hep without at least a minimal reproduction case. Did you try with the exemple project ? If you don't have the notification triggered on user pressed, it's because you have something which intercept the Android Intent. (SplashScreen, SplashActivity, Activity before the React Activity). There is a full issue about it which is not listed in the current issue: Regards, |
@Dallas62 I'm helping @robertgreso look into this. We're using a service called Batch to manage our push campaigns in app. It looks like the push notifications that Batch sends are non-standard or differ from what When a push is received, Where the confusion was happening was this: we include the Batch SDK in order to send user preferences and subscription settings to Batch so that notifications can be customized using their targeting tools. This was also creating a notification, so it wasn't clear that the standard This is also why Any tips on how to handle this case with a Push notification provider? Is it possible for us to trigger the |
Hi @cayleyh
For the first one, if it's triggering onNotification(notification) {
if(!notification.userInteraction) {
return;
}
} If Batch SDK doesn't provide a way to the "initial notification" you can:
To be able to handle the initial notification, you need to "fix" this function: They should have put data inside the Extra of the Intent, using AndroidStudio with the debugger, you should be able to find the right key, then you can post the result here for a futur fix. Regards, |
Hey @Dallas62 Yes we get the notification created correctly if I disable the I went down the same path you've outlined on how to fix this. The solution I came up with was to add some extensible hooks to customize the new intent & bundle parsing behaviours generically: #1819. Then in our code I have the stuff that is specific to our app / Batch. In our MainActivity
In the PR I added the hooks as class statics because it was the simplest way to show how this approach would work. Happy for any input on what you think of including this type fo customization approach in general, and the details of the implementation. |
I should also add: it might be possible to the intent parsing stuff solely in my activity and then have RNPushNotification work correctly based on that, but I'm not very familiar with how the order of intent handling happens with |
Great thanks @Dallas62! |
According to docs,
onNotification
is "Called when a remote is received or opened". I would like to ask, if its possible to somehow get the behaviour that onNotification would be on Android called once push notification is opened, not just once its received (when Android app is in foreground/background)?When implemented on iOS, onNotification is always called just when I click on received push notification, not immediately once its received. I would like to get the same behaviour on Android as well but it behaves differently there.
On Android, if the app is in the foreground/background
onNotification
is called immediately once the remote notification is received, not when user actually clicks on received notification.Is it possible to get the same behaviour as described above on iOS also for Android, ie to be able to handle received push notification on Android while the app is in foreground/background just when user opens received push notification, not just when the notification is received?
Thanks for any suggestions!
The text was updated successfully, but these errors were encountered: