3

I have an app that tracks the location of the device. In the past I used the Android framework location APIs. Worked as intended – so no real need to change that. But now I want to evaluate the Location Services from the Google Play Services that Google recommends to use, so I changed my app accordingly. There are some options that might come handy in the future.

For this I am following https://developer.android.com/training/location/change-location-settings.html I after resolving the quite complex dependencies and requirements I now have a working configuration. But there are issues:

Part 1

There seems to be no option to use the mode „Device only“ (meaning that only GPS is to be used for the location service and not WiFi etc. …

If I request location updates with PRIORITY_HIGH_ACCURACY, interval 10000 and smallest displacement of 20 the pending LocationSettingsResult always returns with status RESOLUTION_REQUIRED if the device is set to location mode „Device Only“. The resolution is to activate mode „High Accuracy“ which also enables WiFi etc. But in this mode location data is sent to Google which might be a privacy problem for some of my users.

I consider this a bug as the mode „Device only“ should be sufficient to fulfil the request. Where to file a bug for Google Play Services? Unfortunately those problems are out of scope for AOSP Bug Tracker and I don't know any official place to file such bugs.

Another problem arises when the location request is to be started from a service. If now the status is RESOLUTION_REQUIRED how to resolve the situation? The solution Google offers needs an activity for the resolution. But in a service there is no activity that could be used for this. The status object of the LocationSettingsResult gives access to a LocationSettingsStates object – but how to extract the cause for the problem and the possible resolution?

Sqrt-1764
  • 321
  • 1
  • 17
  • I am facing the same problem, in addition in the `onActivityResult` when enabling location results into `Device Only` the `resultCode` is being returned as `RESULT_CANCELED=0` and there is no way to distinguish to which mode location resolved (either High Accuracy or Device Only) By the way did you manage to find a solution for this ? – Mehdi Karamosly Nov 13 '18 at 17:57
  • 1
    @Mehdi Karamosly: Old topic ;-) Back then I went back to the very old APIs to get my location updates and that currently still works (tested until Android 8.1) – Sqrt-1764 Nov 14 '18 at 11:20

2 Answers2

1

I faced exactly the same issue - the FusedLocationProvider was not responding with location data when the phone (Moto G4) was set to "Device Only" mode. After a bit of experimentation, it turned out to be due to the cell phone cover which was blocking the GPS signals! Using an app like GPS Status and Toolbox really helps in finding out the signal strength of satellites, whether fix is received etc.,

  • 2
    Unfortunately the fused location provider is something different than the location-provider provided by the Google Play Services. If you carefully read my question, you will notice, that the problem is not due to hardware or due to bad reception of the GPS-Signals. It is caused directly by software - from Google. They request that the situation has to be resolved and the resolution intent that is provided leads to also activating the network-option. – Sqrt-1764 Feb 23 '17 at 16:15
0

Regarding the second issue of activity for launching the result resolution: LocationSettingsResult is a Parcelable object. So you can bundle it with an Intent using PutExtra and broadcast it to an activity for launching the corrective action. The code snippet below illustrates unpacking of the intent and resolving the status.

Status status = intent.getParcelableExtra(Constants.EXTRA_SETTINGS_UPDATE_REQD);
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    // All location settings are satisfied. The client can
                    // initialize location requests here.
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    // Location settings are not satisfied, but this can be fixed
                    // by showing the user a dialog.

                    try {
                        // Show the dialog by calling startResolutionForResult(),
                        // and check the result in onActivityResult().
                        status.startResolutionForResult(getActivity(),
                                Constants.REQ_CODE_CHECK_SYSTEM_SETTINGS_LOC);
                    } catch (IntentSender.SendIntentException e) {
                        // Ignore the error.
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    // Location settings are not satisfied. However, we have no way
                    // to fix the settings so we won't show the dialog.

                    break;
            }
  • I already handled that intent. And the resolution from that intent is to activate the network option. Activiating GPS-only does not work. – Sqrt-1764 Feb 23 '17 at 16:19