thudugala / Plugin.LocalNotification

The local notification plugin provides a way to show local notifications from .Net MAUI and Xamarin Forms apps .
MIT License
411 stars 67 forks source link

Action buttons has no effect if app is closed #423

Open Bindslev opened 1 year ago

Bindslev commented 1 year ago

Describe the bug If I receive a notification either with the app open or closed, if I then close the application, the action button presses I make are ignored and the notification will simply just stay in the notification tray with no action taken.

If the app is then opened, the notification will now work and clicking the action button will dismiss the notification and run the code that it should.

To Reproduce Steps to reproduce the behavior:

  1. Trigger a notification in Android with an action button
  2. Release it in "Release" mode so that the application can be fully closed
  3. Click the action button and notice how nothing happens
  4. Open back up the app to confirm that it does indeed work as long as the app is not closed

Expected behavior I was expecting the action buttons to behave equally when the app is open vs closed

Screenshots I'll gladly do if my description don't suffice

Platform (please complete the following information):

Smartphone (please complete the following information):

Additional context I have minimum code to generate the notification and action buttons, and I have scheduled the notifications if that makes any difference. Also, no intentflags were set, as I'm unsure of what exactly those does (maybe related?)

thudugala commented 1 year ago

@Bindslev Can you please attach a sample project?

Bindslev commented 1 year ago

I can try and look into it. I couldn't get the sample app to work previously, but I'll give in another try and see if I can replicate it there. Is the issue clear besides that?

Bindslev commented 1 year ago

Issue423.zip

Here's a sample project @thudugala I couldn't get the sample project in this repo to build, so I built a little one from the MAUI template. How to run it: Just start it in Release mode. After the app is booted up, it should automatically send you a notification with two action buttons. Before clicking the action buttons, please close the app on your device, and then try and click one of the two action buttons. On my two devices, nothing happens and I would expect the notification actions to trigger + the notification should be dismissed from the notification tray.

Thanks for looking into it

thudugala commented 1 year ago

@Bindslev do you see the same results in the emulator?

Bindslev commented 1 year ago

@thudugala I haven't actually run any, my computer is not very happy about running emulators (Extremely slow) so I tend to only test on my devices. Are you able to replicate using the attached sample?

thudugala commented 1 year ago

@Bindslev

try setting LaunchAppWhenTapped to true

image

Bindslev commented 1 year ago

Unfortunately that didn't work. Although the behavior changed; the app will now open when I click the action buttons, but the action themselves are not triggered, and I wouldn't expect the app to open when using the action buttons. Does this work for you? Could there be other settings that need to be set?

thudugala commented 1 year ago

@Bindslev Can you also try setting the IconName?

image

thudugala commented 1 year ago

untitled

Bindslev commented 1 year ago

Hmm yeah that's weird. It doesn't seem to work for me on any of my devices. I also tried adding a DisplayAlert after clicking the action button, but it only gets triggered if the app is already open. If the app has been closed (as in your demonstration) it simply opens up the app and doesn't trigger the code that is normally executed when clicking the action buttons, even when adding the iconName. Could it be anything else you think? Have you tested on a physical device?

Bindslev commented 1 year ago

Any news @thudugala? And is there no way to use action buttons while the app is closed without them opening up the app? Normally when using action buttons, the idea is the app doesn't need to open up, so I'm a bit curious to know whether this is possible at all? Because otherwise my users might as well just click on the notification without use of action buttons, thanks!

thudugala commented 1 year ago

@Bindslev try setting LaunchAppWhenTapped to false

Bindslev commented 1 year ago

@thudugala Does not work. Same issue, nothing happens when clicking the action buttons. Again - does it work for you on a device, without the action button opening up the app?

thudugala commented 1 year ago

@Bindslev Yes, in the example, the close action button closes the notification without opening the app.

Bindslev commented 1 year ago

@thudugala Very interesting. I know it's much asking this, but could you modify my sample project I attached here to make it work? I tried all your suggestions, but when closing the app, the action buttons are completely unresponsive for me and does not trigger any action button code. I was therefore wondering if anything else in your sample project may contribute to this working for you? I tried on two devices but still no luck

Bindslev commented 1 year ago

For the record, I just tested the same thing on iPhone and it works the exact same way as I reported on Android. Could I have missed something in the setup that allows notification actions to work when the app has been closed? Action buttons work on iPhone when the app has not been closed, but when the app has been closed and I click the button, the notification will actually disappear as it is supposed to, but the code that should be run according to the action clicked, is not run at all unfortunately.

Bindslev commented 1 year ago

Any news @thudugala? I still don't have a working example and it's both Android and iOS so might want to add that label. Are you sure this is a configuration issue? I feel like I have tried most things by now but with the same results on both OS.

joshayoung commented 2 months ago

I am still seeing this issue in Maui with .NET 8. Thanks!