android14在获取摄像头权限时报错:
java.lang.RuntimeException: Unable to create service com.text.chat.CallService: java.lang.SecurityException: Starting FGS with type location
callerApp=ProcessRecord{4dee26 7256:com.text.chat/u0a313} 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
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4884)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2422)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at android.app.ActivityThread.main(ActivityThread.java:8592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{4dee26
7256:com.com.text.chat/u0a313} 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
at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
at android.os.Parcel.createException(Parcel.java:3041)
at android.os.Parcel.readException(Parcel.java:3024)
at android.os.Parcel.readException(Parcel.java:2966)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7270)
at android.app.Service.startForeground(Service.java:775)
at com.text.chat.CallService.onCreate(CallService.java:78)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4871)
at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2422)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at android.app.ActivityThread.main(ActivityThread.java:8592)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2735)
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2446)
at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1737)
at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:14001)
at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:12717)
在android14中服务获取摄像头权限需要配置服务类型foregroundServiceType="camera"
完整配置如下:
<service
android:name="com.text.chat.CallService"
android:foregroundServiceType="camera" />
注意:本文归作者所有,未经作者允许,不得转载