2017-07-31 118 views
0

我有一台运行Android 7.1.1的Google Pixel C平板电脑,没有通过WiFi连接到互联网的SIM卡。我已经设置以下权限在我的Android清单:支持的GPS提供商列表与禁用的GPS提供商列表相同

<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" /> 

,我请求允许由用户提供:

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

当我列出了启用和禁用GPS提供商,该列表是相同的:

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); 

启用GPS提供商:

  • 被动
  • 网络

禁用GPS提供商:

  • 被动
  • 网络

这是一个Android的bug,还是我在这里做什么了吗?

+1

getProviders docs + [enabled is all subset of all](https://en.wikipedia.org/wiki/Set_theory) – Selvin

回答

1

引用the documentation for getProviders(),参数为:

布尔:如果为true,则只有那些当前启用的提供者返回。

因此,您的第一个检查仅返回启用的提供程序。您的第二张支票将返回全部供应商,无论它们是否已启用。由于这两个提供程序都启用,它们出现在两个列表中。