Skip to content
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

Help for PR research: ways to cancel specific notifications when removing an app from Android's task list #2457

Open
leaf-node opened this issue Nov 13, 2024 · 5 comments

Comments

@leaf-node
Copy link

I'm creating an issue to continue the discussion linked here, because I'm interested in making a PR to implement this behavior: #207 (comment)

The guidance there is helpful, but I see that Shared Preferences aren't used on the Dart side any more. Do you suggest querying all of the active alert data in Java via a method channel, when onTaskRemoved() is called, or would it make more sense to store the data in shared preferences on the Java side, as alerts are created one-by-one?

With the latter approach, Shared Preferences may need to be updated when old notifications are closed and replaced by new ones, sometimes with the same ID number.

If you have any pointers or opinions, I'd love to hear them. Thanks : )

@Levi-Lesches
Copy link
Contributor

From the comment you linked:

https://developer.android.com/reference/android/app/NotificationManager#getActiveNotifications() is only supported in API level 23 onwards. This plugin is using the NotificationManagerCompat class to provide backwards compatibility and a similar method isn't available

There is now such a method available

@leaf-node
Copy link
Author

Thanks for the pointer. : )

I think that in this case, Flutter Local Notifications is probably not passing all metadata it has to the Java compat library, so while it's possible to fetch all notifications that way, the compat library probably doesn't provide the info needed to know which to close.

I could be wrong, since there's a lot of code, and I haven't found everything I might need yet.

@Levi-Lesches
Copy link
Contributor

Wouldn't the ID be enough?

@leaf-node
Copy link
Author

I think what's needed is some kind of mapping between notification IDs and whether they were created with a parameter that marked them as needing cleanup on app termination. That's because any specific notifications may or may not have this setting. If we remove all of the notifications, that doesn't fit the original suggestion.

I like the idea in the comment we linked to, which is to set an attribute on notifications that need this behavior. And I suspect that info is not passed to the compatibility library, so the map has to come from somewhere, perhaps over a Method Channel from Dart to Java, or it gets stored by the Java part of Flutter Local Notifications while alerts are created and removed.

I'm not super clear on the code yet, but this is my sense of how it works and could work.

@Levi-Lesches
Copy link
Contributor

Okay, got it, I was thinking that all notifications will be dismissed when the app closes. You're suggesting doing it on a per-notification basis, so yeah I'm not sure if getting all the IDs is actually useful.

Since these notifications are only alive so long as the app is, we can use ephemeral memory instead of persistent storage, right? Shared preferences would imply we want these values to survive after app termination, but we don't.

Does the Java/kotlin side have an object that is alive the whole time? If so, can we just store the notification IDs in a list there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants