I’m using foreground service type as location to fetch location through the service. it will fetch every 2 mins interval. service get start and stopped, after 2 mins again it will get start and stopped and it continues both in background and foreground.
So now, in here I have given all the permission before start,
<code> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</code>
<code> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</code>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
So now app in background and gps location turned off, I got the crash in next foreground service location update start.
<code>Fatal Exception: java.lang.RuntimeException
Unable to create service com.lystloc.utils.services.tracking.LocationUpdateService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{c137f46 23529:com.lystloc/u0a332} 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
</code>
<code>Fatal Exception: java.lang.RuntimeException
Unable to create service com.lystloc.utils.services.tracking.LocationUpdateService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{c137f46 23529:com.lystloc/u0a332} 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
</code>
Fatal Exception: java.lang.RuntimeException
Unable to create service com.lystloc.utils.services.tracking.LocationUpdateService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{c137f46 23529:com.lystloc/u0a332} 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
Thanks in advance
5