iT邦幫忙

1

如何隱藏foreground services notifications

各位前輩大大好:
小弟最近使用Service做連線功能,但是發現API為2.6+時要啟動Service需要改用foreground方法來啟動,但是起動後都會發出紅框中的通知,而且不能清除,如下圖:
https://ithelp.ithome.com.tw/upload/images/20201122/20132312SiNB0IlCpE.png
小弟想要將此通知隱藏或關掉,卻找不到方法除了手動手去設定關掉才行,所以想請問各位大大有甚麼方法可以將通知隱藏或關掉,謝謝
這是小弟的啟用foreground的程式碼:
https://ithelp.ithome.com.tw/upload/images/20201122/20132312Ya0MiKENB1.png

ant1017 iT邦新手 2 級 ‧ 2020-11-23 14:21:57 檢舉
一年前研究過,記得好像關不掉...
後來直接拿來顯示相關功能用
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
Gabriel Chen
iT邦新手 5 級 ‧ 2020-11-24 08:41:45

看了一下官方文件
Foreground serveices的前幾段就開宗明義的說要有這個提示

Foreground services perform operations that are noticeable to the user.

Each foreground service must show a status bar notification that has a priority of PRIORITY_LOW or higher. That way, users are actively aware that your app is performing a task in the foreground and is consuming system resources. The notification cannot be dismissed unless the service is either stopped or removed from the foreground.

我要發表回答

立即登入回答