作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
虽然这里似乎有一些关于 Android 12 服务限制的问题,但我还没有看到一个特定于这个用例的问题。
背景:我正在启动一个前台服务来处理一个运行时间很长的后台媒体播放器(Exoplayer)。由于应用程序的设置,我无法使用 exoplayer 的内置通知管理器。但是,我看到 Crashlytics 的奇怪行为。我收到 ForegroundServiceStartNotAllowedException
而应用程序无疑处于前台。根据日志,很容易看到用户在 startForeground
的一秒钟内浏览应用程序。称呼。
我也在听
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event)
以确保应用程序处于前台状态。
<service
android:name=".service.SoundPlayerService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaPlayback"
android:stopWithTask="false">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
if (!audioFocusTakenBackground && Application.instance.isAppInForeground) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(
ONGOING_NOTIFICATION_ID,
builder.build(),
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
)
} else {
startForeground(
ONGOING_NOTIFICATION_ID,
builder.build()
)
}
}
编辑:@Arlind 建议的设备状态选项卡
最佳答案
Application.instance.isAppInForeground
这个变量有正确的值吗?也许这个变量得到了错误的值。你能检查一下吗?
关于Android 12 ForegroundServiceStartNotAllowedException 在前台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70711950/
Android 12 增加了对从某些后台任务启动的 ForegroundService 的限制。我有一个使用多个 ForegroundServices 的应用程序,其中一些不在异常(exception
虽然这里似乎有一些关于 Android 12 服务限制的问题,但我还没有看到一个特定于这个用例的问题。 背景:我正在启动一个前台服务来处理一个运行时间很长的后台媒体播放器(Exoplayer)。由于应
我是一名优秀的程序员,十分优秀!