神器androidx.work:work-runtime(2.8.0-2.9.0)SystemForegroundService不适配android14

问题描述 投票:0回答:1

当我根据

documentation
调用 setExpedited() 来声明
WorkRequest
应使用加急作业尽快运行时,文档要求加急作业运行的任何
ListenableWorker
都必须实现
getForegroundInfo
方法。我正在使用
CoroutineWorker
,文档要求我在
ForegroundInfo
内将
setForeground()
传递到
doWork()

此时问题来了,如果我在

ForegroundInfo
中指定froegroundServiceType,就会抛出
java.lang.IllegalArgumentException: foregroundServiceType 0x00000001 is not a subset of foregroundServiceType attribute 0x00000000 in service element of manifest file
异常;如果我不指定 froegroundServiceType,
android.app.InvalidForegroundServiceTypeException: Starting FGS with type none callerApp=ProcessRecord{7014511 11425:com.tuya.smartlife/u0a282} targetSDK=34
已被抛出到我的应用程序上。

现在

SystemForegroundService
在工作运行时组件的清单文件中声明。我是否需要在应用程序中重新声明
SystemForegroundService
并指定 foregroundServiceType 以合并到最后一个清单文件中?

android-workmanager
1个回答
0
投票

我是否需要在应用程序中重新声明 SystemForegroundService 并指定 foregroundServiceType 以合并到最后一个清单文件中?

这样做对我的情况有帮助,尽管我无法在文档中找到应该这样做。

<service
  android:name="androidx.work.impl.foreground.SystemForegroundService"
  android:foregroundServiceType="dataSync"
  tools:node="merge" />

请注意,

foregroundServiceType
在您的情况下可能会有所不同。我也不确定如果工作经理用于多种目的该怎么办,也许
specialUse
最适合。

© www.soinside.com 2019 - 2024. All rights reserved.