How to cancel a foreground service from using the notification (swipe dismiss) or clear all notifications?

后端 未结 6 1335
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 05:23

I\'m currently creating a foreground service with a notification that appears in the notification bar when the service starts. If the service stops, the notification dismiss

6条回答
  •  失恋的感觉
    2020-12-05 05:58

    My question is, is there a way to stop the service when "clear all notifications" or a dismiss of the notification (swipe) occurs?

    Assuming that your Notification is set up to allow it to be cleared, the deleteIntent should be invoked when it is cleared. You could set this to a getBroadcast() PendingIntent, pointing to a manifest-registered BroadcastReceiver that calls stopService().

提交回复
热议问题