2017-07-31 123 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,則只有那些當前啓用的提供者返回。

因此,您的第一個檢查僅返回啓用的提供程序。您的第二張支票將返回全部供應商,無論它們是否已啓用。由於這兩個提供程序都啓用,它們出現在兩個列表中。