我一直在使用fusedlocation -provider玩耍,我发现,如果您的手机的位置模式设置为"仅设备"(在设置中更改 - 这意味着仅启用了GPS。网络和单元塔不使用来提高准确性(,然后我找不到fusedlocation -provider为您提供位置的方法,而无需要求用户将其更改为高精度(OnresolutionRequired始终被调用(。
>所有四个位置重点都没有工作:
- Priority_high_accuracy-要求切换到位置模式"高准确性"
- Priority_balenced_power_accuracy-与上述相同
- Priority_low_power-与上述相同
- Priority_no_power-只是不起作用
如果设备处于此模式,是否可以通过FusedLocation Provider获得位置?我很确定您可以通过android.location.location manager获得它。如果要在上面更好地抽象,那似乎是一个巨大的设计缺陷。
您确实需要使用locationmanager来检测这一点,我同意这确实很愚蠢。使用以下代码:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
requestLocationUpdates();
} else {
//Location request code
}
这是我制作的一个示例项目,它包含了此技术:
https://github.com/gavingt/basic_location_impreved