为什么检查GPS_PROVIDER isProviderEnabled总是“假”?

时间:2016-07-14 09:42:41

标签: android gps

我无法确定是GPS打开还是关闭,isProviderEnabled始终为“false”但GPS已打开。

public abstract class BaseGPSActivity extends AppCompatActivity{

  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Log.v(TAG, " GPS is enabled: "+isGPSEnabled()))
 public boolean isGPSEnabled(){
        String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if(provider != null)
            Log.v(TAG, " Location providers: "+provider);
        return mLocationManager!=null && mLocationManager.isProviderEnabled( LocationManager.GPS_PROVIDER );
    }

输出是:

V/BaseGPSActivity:  Location providers: network

V/BaseGPSActivity:  GPS is enabled:  false

1 个答案:

答案 0 :(得分:8)

那是因为需要检查"高精度"在设备的设置中。该GPS提供商将启用。 enter image description here