1

I've recently updated one of my devices to Android 6.0 (API 23) and since doing so I've been unable to get location information in my application.

Quite simply, the issue is this:

locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
for (String providerName : locationManager.getProviders(false)) {
    if (locationManager.isProviderEnabled(providerName)) {
        activeProviders.add(providerName);
        try {
            locationManager.requestLocationUpdates(providerName, LOCATION_UPDATE_DELAY_MS, LOCATION_THRESHOLD_METERS, this);
        } catch (SecurityException e) {
            // TODO: Service not available, Handle This..
            Toast.makeText(context, "Location Disabled", Toast.LENGTH_SHORT).show();
        }
    } 
}

The application does request location permissions as it always has as well.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

This works without any problem on android 4.4 KitKat (Galaxy Nexus), but returns an empty provider array on android 6.0 Marshmallow (Nexus 5). It also previously worked on this same Nexus 5 device running Lollipop 5.1.1.

Am I missing something obvious?

Marlon
  • 1,839
  • 2
  • 19
  • 42
Ryan
  • 121
  • 1
  • 8
  • Are you asking the user for those permissions at runtime? Also, what is your `targetSdkVersion`? – CommonsWare Oct 15 '15 at 15:02
  • I'm not, I did see some changes in android 23 in relation to this but I assumed it would be largely handled under the hood. IE: if an application attempts to use it, android intercepts, prompts user etc. Hence the security exception (that never gets thrown). Am I required to do more than request the permission in the manifest now? Compile and target are both 23. – Ryan Oct 15 '15 at 15:03
  • If your `targetSdkVersion` is 23 or higher, yes. I haven't experimented with `isProviderEnabled()` specifically, and I would have expected a `SecurityException` if your `targetSdkVersion` was 23 or higher and you were running on Android 6.0+. However, perhaps they are handling it more gracefully than I expect. – CommonsWare Oct 15 '15 at 15:05
  • I actually (on android 6.0) can't get to the isProviderEnabled() call (basically the same as getProviders(true) would be) because getProviders() returns an empty array (nothing enabled). I'll take a look at this link. – Ryan Oct 15 '15 at 15:07

0 Answers0