Android Question Location Tracking with SDK34 (again)

Gavin

Member
Licensed User
Longtime User
Hi everyone
Like many other members, I have been trying to update an older app to run with Android 14 and SDK34.

I have studied this post, https://www.b4x.com/android/forum/threads/background-location-tracking.99873/ with interest.

I downloaded the example and ran it on my "New to me" Galaxy Tab A9+, Android 14 and SDK34, with no problems.
I then proceeded to make the necessary changes to my Application.

I included the necessary lines in the Manifest and triple checked.
I included the necessary Process Globals in my Starter Service.
My Tracker Service was working perfectly under SDK33, so all I did was wrap everything that was in GPS_LocationChange in an If statment.

GPS_LocationChange:
Sub GPS_LocationChanged (Location1 As Location)
    
    If DateTime.Now > LastUpdateTime + 10 * DateTime.TicksPerSecond Then

        'extisting code here

        LastUpdateTime = DateTime.Now
    End If
    
End Sub

I added the StartAtBootReceiver module from the example to my project.

Now, everything under Activity_Resume in the example, I have places in a Sub "StartTheTracker", which I call from Activity_Resume.
Originally, I called StartTheTracker with the single command "StartTheTracker".
Program execution would pass to StartTheTracker and all seemed to be fine , but with the latest update, when the Return command was reached in CheckAndRequestNotificationPermission,
program execution would pass back to Actrvity_Resume, instead of StartTheTracker.

Using CallSubDelayed(Me, StartTheTracker) seemed to solve this problem, with program execution now returning to StartTheTracker and continuing on from, If HasPermission = False Then.
(Note, while drafting this Question, I notice that while debugging my previous application, using "StartTheTracker", instead of CallSubDelayed(Me, StartTheTracker), program execution appeared to return to Actrvity_Resume, instead of StartTheTracker. Something for another discussion, maybe.)

When trying to run the application now, Android 14, SDK34, the app fails at the "Return notification" command in the Sub CreateNotification, in the Tracker Service Module.
The following log is presented.

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
*** Service (tracker) Create ***
** Service (tracker) Start **
Error occurred on line: 183 (Tracker)
java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{186b726 23974:b4a.CheckList/u0a255} 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:7234)
at android.app.Service.startForeground(Service.java:775)
at anywheresoftware.b4a.objects.ServiceHelper.StartForeground(ServiceHelper.java:85)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at b4a.CheckList.tracker.handleStart(tracker.java:103)
at b4a.CheckList.tracker.access$000(tracker.java:8)
at b4a.CheckList.tracker$1.run(tracker.java:74)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:240)
at b4a.CheckList.tracker.onStartCommand(tracker.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:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
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:15948)
at android.app.IActivityManager$Stub.onTransact$setServiceForeground$(IActivityManager.java:11974)

I have been working on this problem for three days trying to figure out what is wrong and I can not see it.
I have carefully checked all modifications with the updated example and all looks fine to me.
It appears I am missing Permissions, but where.
My gut tells me it could be the way I am calling some of the Subs, but I am not sure.
Any guidance welcome.
Additional code, or the entire code can be posted if necessary.

Thank you
Gavin
 
Top