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

Cancel notification when when app is killed by swiping (force kill app) on android #207

Closed
dokhanhvu opened this issue Apr 10, 2019 · 7 comments

Comments

@dokhanhvu
Copy link

dokhanhvu commented Apr 10, 2019

Hi MaikuB, thank for your great work,
Can u add an option to create a Service for canceling notification when the app is killed on multitask panel? When I create an ongoing notification with autoCancel is false, there is no way to cancel it when force kills the app.

@MaikuB
Copy link
Owner

MaikuB commented May 2, 2019

there are few things that need to be considered here

as a result what i'm thinking is

  • add an cancelOnAppTermination flag to the AndroidNotificationDetails class. this flag indicates that the notification should be cancelled when the app has been killed and is used for any Android notification, not just ongoing ones. it helps indicate to the plugin the state it needs to track via shared preferences
  • service class will go through the shared preferences to see if there are notifications it should cancel when onTaskRemoved() is fired

how does that sound? feel free to make suggestions on how to make it better. happy to take a PR that implements this as well. the only concern here is ensuring the service keeps running

@carlosbz
Copy link

Hi MaikuB, thanks for this amazing flutter plugin.

I really need this functionality. I was trying to add a cancelOnAppTermination flag without success.

I have add it as a boolean var like this

bool cancelOnAppTermination;

Also add it to the function and the map in the AndroidNotificationDetails.

Could you be more specific about how to do this? Thanks.

@MaikuB
Copy link
Owner

MaikuB commented Oct 1, 2019

I don't have much more specifics to provide as it's not something I've gotten to look into much besides what I posted above. Generally idea is either the app or plugin needs to know when it's being killed. For plugins, I believe you can register to get callbacks for various activity lifecycle events. Some of the official/first-party plugins do this (e.g. see here). If you do get this working then I'd be happy to look at PR for this

@carlosbz
Copy link

carlosbz commented Oct 1, 2019

I will update in case I manage to get this done. Thanks MaikuB.

@MaikuB
Copy link
Owner

MaikuB commented Dec 27, 2019

Closing this as I don't see myself getting to implement this. PRs from the community are welcome should someone come up with a solution that they want to contribute

@MaikuB MaikuB closed this as completed Dec 27, 2019
@meet30997
Copy link

meet30997 commented Oct 13, 2021

Try this to cancel all the notifications or pass the ID to cancel a specific one.

class MainActivity : FlutterActivity() { override fun onDestroy() { val mNotificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager mNotificationManager.cancelAll() super.onDestroy() } }

@Jc-hx
Copy link

Jc-hx commented Jul 14, 2022

I'm late but my workaround is to use timeoutAfter: 2500, in the notification settings and a 2s timer with the .show command inside, the notification disappear only when the app is swiped from the overview...

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

5 participants