Search code examples
androidlocationandroid-gps

List of enabled GPS providers same as list of disabled GPS providers


I have a Google Pixel C tablet running Android 7.1.1 with no SIM card connected to the internet with WiFi. I've set the following permissions in my Android Manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.location.gps" />

and I am requesting permission from the user with:

ActivityCompat.requestPermissions(this, new String[]  {Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_FINE_LOCATION);

when I list the enabled and disabled GPS providers, the list is identical:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

List<String> providersEnabled = locationManager.getProviders(true);
LogHelper.d("location", "Enabled GPS providers:");
for (String providerEnabled:providersEnabled)
    Log.d("location", providerEnabled);

List<String> providersDisabled = locationManager.getProviders(false);
Log.d("location", "Disabled GPS providers:");
for (String providerDisabled:providersDisabled)
    Log.d("location", providerDisabled);

Enabled GPS providers:

  • passive
  • network

Disabled GPS providers:

  • passive
  • network

Is this an Android bug, or am I doing something wrong here?


Solution

  • Quoting the documentation for getProviders(), the parameter is:

    boolean: if true then only the providers which are currently enabled are returned.

    So, your first check returns only the enabled providers. Your second check returns all providers, regardless of whether they are enabled or not. Since both providers are enabled, they appear in both lists.