android check location services enabled with play services location api

后端 未结 4 472
囚心锁ツ
囚心锁ツ 2021-01-01 11:01

You can determine if any providers are available with LocationManager, but can it be done with the google play services location api?

When nothing is enabled, in fac

4条回答
  •  北海茫月
    2021-01-01 11:50

    There is now a reliable way to detect if location updates are available since Google Play Services 7.3.0:

    Implement and register a LocationCallback and override onLocationAvailability() or call LocationServices.FusedLocationApi.getLocationAvailability() to retrieve the availability status. If it's false, then you known the location updates aren't going to be delivered unless something changes in the device configuration.

    This method is actually quite smart: for example it is able to determine that no location updates are going to be delivered on a WiFi-only device if WiFi is disabled or device is in airplane mode, even if the Network location provider is always enabled.

提交回复
热议问题