Android Question Background Location/Tracking and Android 10+

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello community,

In this (https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content) thread, @Erel talks about the new implementation of GPS background tracking and Android 10+, which requires the line SetServiceAttribute(Tracker, android:foregroundServiceType, "location") in Manifest to request to the user to choose if allows or not background tracking. This woks fine if I use target SDK 28 and Android 10, but doesn't work if I use <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/> (sdk 29, as required by Google).
See the screens:
First Image: Target sdk 29 + Android 10 Second Image: Target SDK 28 + Android 10 - same Manifest .
Screenshot_2020-10-11-15-50-04-742_com.google.android.permissioncontroller.jpg
Screenshot_2020-10-11-15-53-13-939_com.google.android.permissioncontroller.jpg

The SetServiceAttribute(Tracker, android:foregroundServiceType, "location") was added in manifest editor in both cases. I really don't know how to request to user the GPS background authorization in SDK 29 + Android 10 and even didn't find it in the forum.
Does anybody know what am I doing wrong?

Thanks!
 

Attachments

  • Screenshot_2020-10-11-15-50-04-742_com.google.android.permissioncontroller.jpg
    Screenshot_2020-10-11-15-50-04-742_com.google.android.permissioncontroller.jpg
    180 KB · Views: 338

MbedAndroid

Active Member
Licensed User
Longtime User
a good idea is to post your manifest. But i got 2 devices (sony/samung) with android 10 which has problems which doesnt show up with sdk28. Unfortunally i cannot check/test it as i dont have those phones in hands. For the moment i stay on sdk28
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
a good idea is to post your manifest. But i got 2 devices (sony/samung) with android 10 which has problems which doesnt show up with sdk28. Unfortunally i cannot check/test it as i dont have those phones in hands. For the moment i stay on sdk28
Google Play required to me the upgrade to TargetSdk29... then, I have no choice.

By the way... the Manifest:
Manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

SetServiceAttribute(Tracker, android:foregroundServiceType, "location")
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
try these too:
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_BACKGROUND_LOCATION)
I'm trying ... one minute...

Didn't work. Same result (only permit while using app or deny - two choices) - by the way, I'm using B4A 10.2. This looks to be some privacy "new requirement" from Google no?
 
Upvote 0

MbedAndroid

Active Member
Licensed User
Longtime User
b4a 10.2. No issues on other phones, at least not reported yet. On Sony gps background stops when device goes to sleep. On Samsung a51 BT cant find the device. Both solved with sdk28.
May be some other forum member has a solution. The problem is when you dont got those phones in hands, it's hard to solve it.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
b4a 10.2. No issues on other phones, at least not reported yet. On Sony gps background stops when device goes to sleep. On Samsung a51 BT cant find the device. Both solved with sdk28.
May be some other forum member has a solution. The problem is when you dont got those phones in hands, it's hard to solve it.
Let's wait to know if anybody in the community has the answer. For me: Android 10 + target SDK 28 - Ok / Android 10 + target SDK 29 - no background authorization... considering that everybody will need to migrate to target sdk 29 sometime, this question is a issue to keep on focus and find the solution as it is a problem to real time tracking apps...
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test:


 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
You can only request access permissions to the location with the consent of the user.

This does not prevent the user from disabling the GPS whenever they want.

If your application requires GPS to always be enabled and if it is not enabled, you can request to enable GPS.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
You can only request access permissions to the location with the consent of the user.

This does not prevent the user from disabling the GPS whenever they want.

If your application requires GPS to always be enabled and if it is not enabled, you can request to enable GPS.
Ok, but before to be able to do background tracking the app needs to request it... And I'm saying that if you use target sdk 29 in Android 10 the background permission request isn't being showed to the user . At least using the standard procedure that worked using target sdk 28.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Ok, but before to be able to do background tracking the app needs to request it... And I'm saying that if you use target sdk 29 in Android 10 the background permission request isn't being showed to the user . At least using the standard procedure that worked using target sdk 28.
With target 28 you won't be able to put your app into Google Play Store.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Yes! Then the background location must to work with target 29.
Even with 29 you won't be able to put your app into Google Play Store - read #10. It's prohibited by Google Play Store policy. You can ask for location by clicking on the button in your app but you can't get location from background service. You can run a timer in background but not GPS.

https://support.google.com/googleplay/android-developer/answer/9888170#location_permissions

Apps are allowed to access location using foreground service (when the app only has foreground access e.g.: "while in use") permission if the use:

  • has been initiated as a continuation of an in-app user-initiated action, and
  • is terminated immediately after the intended use case of the user-initiated action is completed by the application.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Ok.
Even with 29 you won't be able to put your app into Google Play Store - read #10. It's prohibited by Google Play Store policy. You can ask for location by clicking on the button in your app but you can't get location from background service. You can run a timer in background but not GPS.

https://support.google.com/googleplay/android-developer/answer/9888170#location_permissions

Apps are allowed to access location using foreground service (when the app only has foreground access e.g.: "while in use") permission if the use:

  • has been initiated as a continuation of an in-app user-initiated action, and
  • is terminated immediately after the intended use case of the user-initiated action is completed by the application.
Ok. But how can an app track the user in background... Like waze, google maps or geo barrier app? Isn't it possible anymore ? I don't think so. Google doesn't say that the apps will not be allowed to access location in background. Google says that background location must to be justified and allowed by the user.
But, now we are back to the question : how can we request background location as it isn't showed anymore if is used target sdk 29 ?
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Ok.

Ok. But how can an app track the user in background... Like waze, google maps or geo barrier app? Isn't it possible anymore ? I don't think so. Google doesn't say that the apps will not be allowed to access location in background. Google says that background location must to be justified and allowed by the user.
But, now we are back to the question : how can we request background location as it isn't showed anymore if is used target sdk 29 ?
After November,1 - no way. Like waze, google maps - What is permissible for Jupiter may not permissible for a bull

If a user knows that he is tracible, you can send him an app via Dropbox (but something tells me that Google might issue an update for Android that will kill it once and forever).
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
After November,1 - no way. Like waze, google maps - What is permissible for Jupiter may not permissible for a bull

If a user knows that he is tracible, you can send him an app via Dropbox (but something tells me that Google might issue an update for Android that will kill it once and forever).
Simply security and permission policies.

The user will have control of the permissions of the location of their device.

The location can be done in the background.

Only the device will notify the user that there is a background app that they have given permission to.
 
Upvote 0
Top