4

I can't determinate is GPS Turned ON or OFF, isProviderEnabled is always "false" but GPS is Turned ON.

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

Output is :

V/BaseGPSActivity:  Location providers: network

V/BaseGPSActivity:  GPS is enabled:  false
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138

1 Answers1

9

That was because need to check "High accuracy" in Settings of the device. That GPS Provider will be enabled. enter image description here

NickUnuchek
  • 11,794
  • 12
  • 98
  • 138