【发布时间】:2019-02-16 22:38:32
【问题描述】:
上下文:
我一直在使用 Google 的 LocationUpdatesForegroundService 示例项目来了解有关服务的更多信息。
我已经通过 Github 桌面下载了该项目并在我的手机上运行它,一切都很好,该项目完成了它的预期。
我的手机是 Android 8.0.0,API 26
问题:
应用程序终止后,前台服务通知会显示在状态栏上,一旦发生,我就会听到通知声音(默认声音)。 但是,我希望通知保持静音,就像在某些基于位置的应用程序中一样(例如:Life360)
到目前为止我所做的尝试:
- 在LocationUpdatesService.java 添加
159尝试mChannel.setSound(null,null); - 在LocationUpdatesService.java
296行中将.setPriority(Notification.PRIORITY_HIGH)更改为.setPriority(Notification.PRIORITY_LOW) - 在LocationUpdatesService.java 行
158将NotificationManager.IMPORTANCE_DEFAULT更改为NotificationManager.IMPORTANCE_LOW) - 在LocationUpdatesService.java
300行添加setSound(null)
以上都没有为我工作,如果有人能对这种情况有所了解,我将不胜感激。
【问题讨论】:
-
你在 startForground(id, notification); 中调用通知吗?功能?
-
@hfarhanahmed Yes in LocationUpdatesService.java at line 226
-
我使用的代码甚至没有
builder.setDefaults(Notification.DEFAULT_ALL); -
添加 .setDefaults(Notification.DEFAULT_ALL);在 LocationUpdatesService.java 的第 298 行之后
标签: java android notifications foreground-service