-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Multiple features android #172
Multiple features android #172
Conversation
…ns, register notification actions, configure repetition in notifications
Great work! Could you document how one may add notification actions? Saw that the method is exposed but no instructions of how to use it. |
I would have added the instructions once it was reviewed. Here is how I have added notification actions This is how the action handlers are registered. This can be called in the app componentWillMount/constructor or other appropriate method
This is how the notification is scheduled
This will cause the above notification to have the |
… in Android when contentAvailable property in the notification is set to true
…e app gradle file instead
Would it be possible for someone to review the changes in this PR. It contains a ton of features mainly for android that I have been using in my app. To list the newly added features again:
I am happy to discuss/explain the changes and make any necessary edits. Currently, the branch is not up to date with the master and I have checked that all the new commits are non-conflicting and I should be able to take care of it along with any code review comments. Thanks! |
I'll take a look, maybe over the weekend. Sorry, didn't realise I was a contributor until just now. Could you first resolve the conflicts though? |
@npomfret Done |
Looking to merge this now but having difficulty. Can you help? I'm trying to get the Restore local notifications on reboot to work, what do I need to do? Obviously I've tried rebooting the phone but they don't reappear. Also tried cancelling a notification but it remained in the notification centre. I did see this in the logs:
It doesn't look like non-scheduled notifications are saved to the SharedPreferences? I don't know why but I've added that in. Even after this change though it looks like the SharedPreferences is always empty when it gets reloaded. Not sure why yet. |
Can you add below lines to
This is required to invoke the package boot event receiver. A little note on the implementation details for this feature: In order to restore local notifications after reboot, we need to store the notifications in a persistent storage so that they can be read again on reboot and rescheduled. In order to store the notifications, we need to convert it to serializable form. Here I am using |
I've made that change but it looks like the persistence isn't working. saving the notification seems fine, and if I query the persistence immediately after saving I can see the item in there. however, when calling the cancel method for that notification, it seems that the persistence is empty and so nothing gets cancelled. |
Ok, found the issue. So I added regular notifications to the storage so that they can be cancelled and reloaded on boot up in the same way as scheduled notifications. BUT, I failed to notice this code in the helper in
Its removing the notifications immediately after my new code puts them in! Aaaargh!! been looking at this for hours. I think we need to remove data from the sharedPreferences when its removed from the notification centre, no? Why is this code in the |
Ok, I think i finally understand what you've done. I've had to change it in a few places, and done some clean up. You didn't quite fix 'cancel all local notifications'. You made it possible to cancel scheduled notifications only. I've changed the code so it does in fact cancel all notifications. There's a code block in "Restore local notifications on reboot" - I've updated my manifest, deleted the app completely and reinstalled. I can see the logging from the Why did you decided to only persisting scheduled notifications? "Notifications actions" - what is this? I can't see any code relating to it or how to test it. Can you please advise? "Play custom sound for notification" - this didn't work in the way I expected it to, or at least the docs weren't clear on how it should work. I've changed it so that it loads a sound from a resources folder and updated the docs for both Android and iOS. The idea is to make the iOS and android javascript interfaces the same, where possible. |
@npomfret Thanks for spending time to review the changes and making some changes of your own. The reason I am persisting only scheduled notifications is because I as far as I understood, the other type of notification will be shown immediately to the user, so I thought there is no point in storing it. Please let me know if I am incorrect in that assumption. Same applies for I will add comments in the I also noted that you have remote the Please refer to an earlier comment in the PR which explains how to configure notification actions for notifications. #151 explains the notification actions in general. I am not sure what exactly didn't work for you while playing the custom sound but I saw your changes and they are fine. Could you take a look at the Small note: I think you have some |
@npomfret Forgot to mention, I will update the README soon with the all these changes. |
I'll add the missing method back in. Sorry, was working on this for hours and didn't mean to remove it exactly - it had the wrong name. I was getting confused between I understood that support for using eclipse for Android dev was dropped years ago. Android Studio is very much the industry standard and all formatting really should follow it. Its free, I don't see any reason not to use it. The custom sound change, well all I can say was that your implementation didn't play a custom sound. It might have worked if you'd provided a URL to the resource I suppose. Did you test it? It needed to have the same interface as the iOS implementation which is to supply the name of a resource in the native project file. Which is what I implemented. |
It seems unclear from the RN docs whether or not If not, there's no way to cancel a single scheduled notification. But if it should, then what is |
I've committed another change. I hope one that's in agreement with the documented RN behaviour in iOS. Would you be able to take a look please? |
@npomfret I think there is still some confusion regarding the naming of methods to cancel/clear notifications. The The other method I reviewed your changes and I think you have now merged the If you want, I can submit a fresh PR with these changes as I don't want you to overload with work. Regarding the formatting changes, maybe I misunderstood. When I was reviewing your changes, there were a lot of formatting changes and I thought maybe some configuration in your |
@npomfret Regarding the custom, yes I am using that feature daily at least a dozen times as I am still in the process of implementing my app and the notifications are a centerpiece in my app. I set the sound using
which plays the |
@varungupta85 thanks for your reply - will get to the bottom of this soon I'm sure! After testing the difference between
So - I'm going to change the behaviour once again to agree with the observed iOS behaviour, which is not what is documented. Although its confusing it important that the Android and iOS behaviour is as similar as possible. I'll raise a question about the confusing wording in RN about this and if it becomes more clear in the future we'll adapt if necessary. Does that sound ok to you? What I would like from you if possible, is a PR with a comment about the bit of code in Many thanks for your efforts. |
@varungupta85 I've updated the code again after reading though the iOS implementation. I think However, my current implementation of |
@varungupta85 ok, i went ahead and made the change. If I've read the iOS code properly the current implementation of both Please can you review ? |
@npomfret I am travelling for a few days and will be back on the weekend. I will review your changes and submit the PR then. I appreciate your efforts in getting it right. Thanks! |
@zo0r I thin this could be pushed to npm now. Had a couple of people do some extra testing and so far it seems ok. Needs a bit more documentation but I thing @varungupta85 can provide that soon. |
@varungupta85 still waiting on some docs from you regarding this PR. |
@npomfret I am sorry for the delay. Will get them in as soon as possible. |
* upstream-master: (89 commits) Split out the JS delivery functionality, so it can be used by ListenerService as well as the RNPushNotification base code (ie the Activity and JS library). fixed scheduleLocalNotification to work on iOS Fixed typo in README.md Allow popInitialNotification to be set on secondary calls to configure(). Start the JS thread to handle any incoming remote notifications we receive on the background listener service. Update README.md Update package.json docs docs docs docs ok, i think / hope we have feature parity with the cancel methods between iOS and Android. You can now specify a dictionary that describes which notifications you want to cancel. See https://github.com/facebook/react-native/blob/master/Libraries/PushNotificationIOS/RCTPushNotificationManager.m#L294 updated again to behave a bit more like iOS - still not quite right though. cancelLocalNotifications has different behaviour docs - fix typo docs attempt to make the interface for the 2 cancel methods agree with the RN iOS docs updated docs fixed PR zo0r#172 Undo remote Activity change from onActivityResult method Removing the activity parameter from onActivityResult as it requires react-native >= 0.33 ... # Conflicts: # android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
Restore local notifications on reboot
Fix cancel all local notifications
Cancel a specific local notification
Notifications actions
Play custom sound for notification