android - 引发 PRIORITY_MAX 通知后隐藏前台服务的状态栏通知图标

标签 android android-notifications android-notification-bar

首先,执行此操作(在运行 4.4.2 的 Nexus 5 上测试):

  • 将 PRIORITY_LOW 通知传递给 Service.startForeground()。
  • 注意状态栏中未显示通知。
  • 使用相同的通知 ID 发出 PRIORITY_MAX 通知。
  • 观察状态栏中显示的通知。

现在,有什么方法可以从状态栏中删除该图标(除了 Service.stopForeground() 之外)吗?

我尝试调用NotificationManager.cancel()和NotificationManager.cancelAll()。还尝试提出相同的原始 PRIORITY_LOW 通知。但它们都在状态栏中留下了通知图标。

最佳答案

这在 Android 4.3 中进行了更改,以始终显示前台服务的通知。

这样做有一个很好的理由,即当系统需要更多资源时,前台服务不能被终止。如果没有通知,普通用户就无法知道有什么东西仍在运行并耗尽电池。

如果您不需要通知,请考虑使用后台服务。如果确实需要前台服务,用户有知情权。

了解更多关于 http://commonsware.com/blog/2013/07/30/notifications-foreground-services-android-4p3.html

关于android - 引发 PRIORITY_MAX 通知后隐藏前台服务的状态栏通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21524672/

相关文章:

android - 如何检查我的应用是否允许显示通知

java - 您是否可以删除系统栏(返回、主页、最近使用的应用程序)而不将应用程序全屏显示,以便仍然可以访问通知栏? (4.x)

android - 选择内部存储和外部存储

android - 检索项目 : No resource found that matches the given name 'android:Theme.Material.Light' 的父项时出错

安卓 2.2 : Turning of screen under certain times of the day by code

android - 自定义通知未在 Android 中显示

android - 提醒功能

android - 如何禁用Android应用程序的通知栏?

Android:如何从状态栏通知创建的 PendingIntent 访问 AsyncTask?

android - 从选项卡 Activity 中打开另一个 Activity