Android Question Problem with GPS location in API 29

walterfn2

Member
Licensed User
Longtime User
Hello,

My application worked fine with API 26 all time. However now with API 29 it stops getting GPS location while phone is locked.

B4A version is 10.0
SDK is android-29

My manifest contains:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="29"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>


Also on app start I'm requesting PERMISSION_ACCESS_FINE_LOCATION via RuntimePermissions library. However it allows to get location only while application is activate. I can not use ACCESS_BACKGROUND_LOCATION via RuntimePermissions. Then I go manually to App info/Permissions/Location and set "Allow all the time". However it still does not get location while phone it locked.

For getting location I'm using Foreground service with ESLocation2 library.

Any ideas?

Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

walterfn2

Member
Licensed User
Longtime User
Mistake. Use FusedLocationProvider or GPS libraries.

See the note here about Android 10 and background tracking: https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content

Thank you for response.

I changed code to GPS libs instead of ESLocation2 as per MyLocation example also I added:
SetServiceAttribute(MY_SERVICE_NAME, android:foregroundServiceType, "location")

My application takes location every 10 seconds and uploads via HTTP POST, but afters 1-2 minutes when phone is locked GPS looses location and uploads data without valid location as there are no satellites available... As soon I unlock phone, GPS gets location again.

That happens only if compiled with API 29.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
See:


Many devices will turn off GPS and the CPU while they are "sleeping" even though the app acquires the partial wake lock.

Read:



Read sections about android 10 API Level 29
 
Upvote 0
Top