为什么检查GPS_PROVIDER isProviderEnabled总是"假"?

Nic*_*hek 3 gps android

我无法确定是GPS打开还是关闭,isProviderEnabled总是"假"但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()))
Run Code Online (Sandbox Code Playgroud)
 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 );
    }
Run Code Online (Sandbox Code Playgroud)

输出是:

V/BaseGPSActivity:  Location providers: network

V/BaseGPSActivity:  GPS is enabled:  false
Run Code Online (Sandbox Code Playgroud)

Nic*_*hek 9

那是因为需要在设备的设置中检查"高精度".该GPS提供商将启用. 在此输入图像描述