Reputation: 127
I am implementing an android application with a service that is returning the location so , i have set the attribute foregroundServiceType to "location". Here is my service in the manifest file :
<service
android:name=".Services.PositionService"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
android:foregroundServiceType="location"
/>
and here are the permissions declared in my manifest :
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
But when my app tries to launch , it suddenly crash and gives me the error :
java.lang.RuntimeException: Unable to start service com.mhealthcs.Services.PositionService@12db7c9 with Intent { cmp=com.mhealth/com.mhealthcs.Services.PositionService }: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{ea33e0e 3543:com.mhealth/u0a251} 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
How could i solve it
Upvotes: 3
Views: 3652
Reputation: 31
It appears that the issue you're encountering is related to foreground service permissions on Android 14. Starting from Android 12, foreground services that request location updates must have both foreground service permission (FOREGROUND_SERVICE) and location permissions (ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION). Additionally, if your app targets API level 34 (Android 14), it must also request the FOREGROUND_SERVICE_LOCATION permission explicitly.
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
Upvotes: 1