【问题标题】:Android O: Service.stopForeground equivalentAndroid O:Service.stopForeground 等价物
【发布时间】:2018-05-08 18:45:20
【问题描述】:

我目前正在尝试制作某种音乐播放器应用。对于播放,我创建了一个单独的服务。因为我想让它一直播放,所以我调用了 Service.startForeground()。在为 Android O(SDK 级别 27)编译时,由于 Android 的“新”后台执行限制,我必须使用 Context.startForegroundService()。

这很好用,但是当用户暂停播放时,我希望通知可以关闭。过去,我可以调用 stopForeground(),但这对 Android O 没有影响。是否有任何其他方式可以在后台和前台服务之间切换或任何其他机会来实现此行为? Google Play Music 等应用正是使用这种通知模式,但它们是如何做到的呢?

【问题讨论】:

  • stopForeground() 传入哪个标志?
  • 我的错。我正在使用stopForeground(boolean: removeNotification)。使用标志STOP_FOREGROUND_DETACH 它确实有效。谢谢!
  • 我正要推荐它。很高兴知道你想通了
  • 你应该把它作为答案,而不是更新问题。

标签: android android-notifications android-8.0-oreo foreground-service


【解决方案1】:

这是因为我使用了错误的方法。您必须使用stopForeground(STOP_FOREGROUND_DETACH) 而不是stopForeground(true)

【讨论】:

    猜你喜欢
    • 2012-03-17
    • 2014-07-28
    • 2011-12-08
    • 2018-05-18
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多