I've been trying to remove a persistent Notification set by a Service using:
startForeground(1337, notification);
The code I'm using to cancel it:
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.cancel(1337); // cancel existing service notification, doesn't take effect
nManager.cancelAll(); //surpluous, but also doesn't take effect
To clarify why I am doing this: the Service starts with a default persistent Notification. When my app runs, it needs to replace this Notification with another. Using notify()
on the existing Notification works perfectly, however, I need it to show the ticker text for the new Notification as well. This is why I decided to remove the existing Notification (using the code above), create a new one, and then I call startForeground()
again and pass the new Notification to it, so my Service persists.
Start an App that can send notifications, and it will be stored in the notification center and the "Notifications & actions". For example, start Outlook or MS Mail and send an email to your account, check the "Notifications & actions" after the notification.
There is no debug problem. Works well on Android version 6.0 smartphone. (The Notification screen appears.) Does not work on Android version 9 smartphones. (Notification screen does not appear.) Why? Hardware Information: Check the application notification settings [Android] I can't find a solution. 'Notification pop up' is required
Locate the registry entry: 2. Delete the AppDB entry and you will notice the notification center is initialized. 3. Start an App that can send notifications, and it will be stored in the notification center and the "Notifications & actions".
The problem is that you're issuing the Notification in an indirect way by using startForeground()
. You can't just cancel that Notification for the same reason the system insists on you providing a Notification when starting a foreground Service. As long as your foreground Service is running, that Notification will be there.
In most cases, Services really shouldn't be in the foreground. If you can use a normal priority for your Service, then you can start and stop your Notification normally.
If you're actually doing something that truly does require a foreground Service, and if you really want to show the user a ticker text, I believe your only option is to issue another Notification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With