Android Question Problem when setting targetSdkVersion=34 on background location app

vikingivesterled

Active Member
Licensed User
Longtime User
App with background location run under foreground permission as recommended
now failes on startup and gives the following error:

java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{8fce9ec 12241:mobi.moonc.anchorwatch/u0a374} 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


Works with targetSdkVersion=33

Posted as requested sample by Erel in thread 161928 post 11

We are getting close to the August 31 deadline now if one have many apps to update.
 

vikingivesterled

Active Member
Licensed User
Longtime User
Complete error message:

servicetimer3_service_start (java line: 394)
java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{8fce9ec 12241:mobi.moonc.anchorwatch/u0a374} 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:3069)
at android.os.Parcel.createException(Parcel.java:3053)
at android.os.Parcel.readException(Parcel.java:3036)
at android.os.Parcel.readException(Parcel.java:2978)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7220)
at android.app.Service.startForeground(Service.java:775)
at anywheresoftware.b4a.objects.ServiceHelper.StartForeground(ServiceHelper.java:85)
at mobi.moonc.anchorwatch.servicetimer3._service_start(servicetimer3.java:394)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at mobi.moonc.anchorwatch.servicetimer3.handleStart(servicetimer3.java:103)
at mobi.moonc.anchorwatch.servicetimer3.access$000(servicetimer3.java:8)
at mobi.moonc.anchorwatch.servicetimer3$1.run(servicetimer3.java:74)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:240)
at mobi.moonc.anchorwatch.servicetimer3.onStartCommand(servicetimer3.java:72)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5268)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2531)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8918)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2741)
at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2452)
at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1797)
at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:15880)
at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:11916)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User

see if this helps. foregroundServiceType .

Also, might want to check this out. Check the manifest. New permissions are required.
Location example
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Read https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
The Example is updated to use 34.

 
Upvote 0

vikingivesterled

Active Member
Licensed User
Longtime User
Thanks for all help.
Adding android.permission.FOREGROUND_SERVICE_LOCATION solved the error problem.
Before I had just android.permission.FOREGROUND_SERVICE
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…