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

后端 未结 6 1343
伪装坚强ぢ
伪装坚强ぢ 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:56

    this code works for me:

    this.stopForeground(false);
    mNotificationManager.cancel(NOTIFY_ID);
    

    and you should set your return value of onStartCommand, STRAT_STICKY will restart your service.

提交回复
热议问题