我正在尝试迁移到Android 14,我的应用程序有一个功能,即使你重新启动设备,它也会作为前台服务继续运行(它是一个工具,因此需要此功能),应用程序向用户显示通知(带有停止按钮)。要启动服务,用户需要点击应用程序中的按钮,但是现在,在我将compileSdk从33更改为34之后,当我试图在BOOT_COMPLETED
BroadcastReceiver上的服务onCreate
中调用startForeground(1, notification, FOREGROUND_SERVICE_TYPE_LOCATION)
时,我会得到一个错误:
Unable to create service MainService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{ef58f87 3065:com.xxx/u0a196} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission
字符串
我已经在清单文件中添加了所需的所有内容,包括android.permission.FOREGROUND_SERVICE_LOCATION
权限和为服务声明android:foregroundServiceType="location"
。
有人知道我缺少什么吗?我需要在运行时请求FOREGROUND_SERVICE_LOCATION
权限吗?我已经在运行时请求ACCESS_FINE_LOCATION
权限了。
谢谢你,谢谢
1条答案
按热度按时间zf2sa74q1#
它只需要
ACCESS_BACKGROUND_LOCATION
许可,现在工作正常。感谢Jigar Rangani!