katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

keep notification shade open upon clicking action button? #1534

Closed m52go closed 6 years ago

m52go commented 6 years ago

notification clicked --> notification shade closes and app opens --> good. action button clicked --> notification shade closes --> not always good?

especially if the action results in the related notification still showing.

Your Environment

this.localNotifications.on( 'switch-book', function( note, event ) {
    that.localNotifications.update({
        id: note.id,
        title: "Loading next book.",
        text: "Just a second...",
        ongoing: true,
        priority: -2,
        sound: null,
        color: null,
        led: null,
        smallIcon: 'res://ic_stat_notify.png',
        icon: null
    });
});

Expected Behavior

notification drawer should stay open if action does not result in clearing its notification.

Actual Behavior

notification drawer is closed no matter what: on notification click, action click, etc.

Steps to Reproduce

create new notification with action button. have action button do anything (or nothing), and notification shade will close every time whenever an action button is clicked.

Context

one of my action buttons updates the notification it's attached to. it's confusing for the user if the 'update' action button results in the whole notification shade closing, when they were just looking for the notification to update.

example: android's default sms app ('messages') provides a 'mark as read' action for new text messages. upon clicking that action, the message is marked as read, and the notification shade remains open.

katzer commented 6 years ago

I cannot reproduce - also please use sticky:true. ongoing is deprecated.

m52go commented 6 years ago

hi @katzer, thanks for quick turnaround & your ongoing work on this plugin.

were you getting this behavior? i recorded a quick screen grab.

for me, the notification shade closes in every one of these cases:

code running in video above is here: example code. it's literally just a blank project with the plugin added. it uses ionic but i'm not sure that matters.

i've messed around with some native code, compared it to other code to figure out the differences (e.g., red moon has buttons that work both ways), but haven't been able to get to the root of the issue (assuming it is an issue).

m52go commented 6 years ago

for the record, it looks like this happens because getActivity is designed to close the notification shade whereas getService and getBroadcast aren't (source). indeed, i tested, and the shade doesn't close when getActivity is changed to either one (getService or getBroadcast) in getPendingIntentForAction in Builder.java.

but of course that screws up the receivers so the events themselves never fire :)

so i'll close this for now. but if this is ever an issue in the future...maybe this could help.

katzer commented 6 years ago

@m52go See c008cc6

m52go commented 6 years ago

@katzer omg it's perfect! you made my WEEK sir!! sending you an email at contact at appplant.