Android Question Can't use FusedLocationProvider with GPS-Only device mode?

JohnC

Expert
Licensed User
Longtime User
I just did a bunch of trial-and-error research with the various location libs (FLP, LM, GPS) and I came across an issue with the Fused Location Provider as used in this example app:


Some background....Basically, the location setting on a user's device can be put into one of three modes:

1) GPS - In this mode it uses *just* the built-in GPS receiver in the device to determine the devices location. Apparently this method uses a significant amount of power.
2) Network - In this mode it uses WiFi, Bluetooth and the cellular networks to determine the devices location. This mode uses less power then the GPS mode.
3) High Accuracy - In this mode, it will use both modes 1 and 2 to determine the devices location.

Mode's 2 and 3 use google services, and as such, it will require the user to agree to allow google to track their device 24/7 even when there are no location apps running on the device. If the user does not agree with these terms, the mode is set back to mode 1 (GPS only).

The problem I am running into is that if my device is set to "GPS only" (mode 1), then it seems I can't use the FLP library. I say this because when I click "START" in the above demo app, it will first ask for location permission - easy enough to understand why and I grant it. The example app then asks me for "Resolution Required" permission, which has a drop down arrow that expands and explains that this second permission will allow google to track my device 24/7 even if I don't run any location apps. If I say "No Thanks", it will stop and display "Not Enabled" and wont display my location as if the lib can't run this way. NOTE: Answering "OK" to this second prompt will *permanently* change the user's device location setting to mode 3 - and I don't know if the user will correctly realize this change will effect ALL apps DEVICE-WIDE and not just for your app.

So, it appears, unless the user is willing to let google track them full-time, your app can not use this FLP lib to determine the devices location if it is in "GPS Only" mode.

I was hoping that this lib would still be able to work on devices in mode 1, but would just only use the GPS to determine location and wont use networks.

In an attempt to see if I could get this FLP lib to work in GPS only mode, I tried all different combinations of having Coarse and Fine permissions in the manifest and trying the different priority settings in the LocationRequest:

B4X:
Private Sub CreateLocationRequest As LocationRequest
    Dim lr As LocationRequest
    lr.Initialize
    lr.SetInterval(0)
    'lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
    'lr.SetPriority(lr.Priority.PRIORITY_BALANCED_POWER_ACCURACY)
    Return lr
End Sub

Am I missing something that will allow this lib to be used even if the device is in mode 1?

If this FLP lib is designed to only work in mode 2 or 3, then this means that your app will also need to include one of the other location libs (LM,GPS) for the situations that the user's device is in GPS only mode 1 so that the user is not forced to give up their privacy in order to use your app.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Some background....Basically, the location setting on a user's device can be put into one of three modes:

1) GPS - In this mode it uses *just* the built-in GPS receiver in the device to determine the devices location. Apparently this method uses a significant amount of power.
2) Network - In this mode it uses WiFi, Bluetooth and the cellular networks to determine the devices location. This mode uses less power then the GPS mode.
3) High Accuracy - In this mode, it will use both modes 1 and 2 to determine the devices location.
Where is this setting?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Where is this setting?
Its the typical "Location" settings in a phone - its usually in the "security/privacy" section of the settings.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is what I see:

1585208412355.png


Anyway, I don't think that there is any relevant setting in FLP. It wraps this API: https://developers.google.com/andro...android/gms/location/FusedLocationProviderApi
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I'm pretty confident this is a standard setting on android phones because it appears on two different phones, a Samsung S4 running android 5.0.1 and a Nexus 5X running android 8.1:

Nexus-81.png
S4-5.png


Maybe if you click on the "Google Location Accuracy" on your screen, it will show a dialog similar to what I see on my phones.

Anyway, as a general rule, our app needs to respect the settings a user setup on their device and not force the user to change a device-wide setting just to work with our app.

So, if the user sets up their device for "GPS Only", our app needs to respect that. And the main reason for this thread was that I was unable to get this FLP to work when a device is set to GPS only mode.

I'm confident that you will be able to find out how to set your device to be in GPS only mode, and then you will be able to confirm this issue and hopefully figure out a way to get it to work in GPS only mode (maybe by figuring out a special way to configure the locationrequest)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'm pretty confident this is a standard setting on android phones because it appears on two different phones, a Samsung S4 running android 5.0.1 and a Nexus 5X running android 8.1
i can not find it in my device. Note 10, running Android 10. I only can see/find the same as @Erel in #4
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, according to this post, on android 10 devices, if you turn "off" "Google Location Accuracy", then it will put your phone in GPS Only mode:

 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, the problem appears to be with flp.CheckLocationSettings(f.Build) method. It appears this method checks to see if the device's Location Setting is sufficient to perform the desired LocationRequest:

B4X:
Sub CheckLocationSettingStatus As ResumableSub
    Dim f As LocationSettingsRequestBuilder
    f.Initialize
    f.AddLocationRequest(CreateLocationRequest)
    flp.CheckLocationSettings(f.Build)
    Wait For flp_LocationSettingsChecked(LocationSettingsResult1 As LocationSettingsResult)
    Return LocationSettingsResult1
End Sub

The example in post #8 does not use this function and that is why it works without a problem even when the device is in GPS Only mode.

However, the example in the OP does use this method, and it seems there is a bug in this method that is basically saying "The device's Location Setting is not correct for the LocationRequest".

So, I modified the LocationRequest to make sure it's requesting high accuracy which is compatible with GPS Only mode:
B4X:
Private Sub CreateLocationRequest As LocationRequest
    Dim lr As LocationRequest
    lr.Initialize
    lr.SetInterval(0)
    lr.SetPriority(lr.Priority.PRIORITY_HIGH_ACCURACY)
    Return lr
End Sub

But, it appears the CheckLocationSettings method still doesn't think "GPS Only" mode is sufficient to complete a "High_Accuracy" LocationRequest. This is an error because if I ignore this check/method, the example in the OP works fine in GPS Only mode:
B4X:
Sub btnStart_Click
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Starter.flp.IsConnected = False Then
        SetState("Location provider not available")
    End If
    If Result Then
'        Dim rs As ResumableSub = CallSub(Starter, "CheckLocationSettingStatus")
'        Wait For (rs) Complete (SettingsResult As LocationSettingsResult)
'        Dim sc As StatusCodes
'        Select SettingsResult.GetLocationSettingsStatus.GetStatusCode
'            Case sc.SUCCESS
                SettingsAreGood
'            Case sc.RESOLUTION_REQUIRED
'                SetState("RESOLUTION_REQUIRED")
'                SettingsResult.GetLocationSettingsStatus.StartResolutionDialog("srd")
'                Wait For srd_ResolutionDialogDismissed(LocationSettingsUpdated As Boolean)
'                If LocationSettingsUpdated Then
'                    SettingsAreGood
'                Else
'                    SetState("Not enabled")
'                End If
'            Case Else
'                SetState("Not available")
'        End Select
    Else
        SetState("No permission")
    End If
End Sub
 
Last edited:
Upvote 0
Top