Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPS is not enabled but isProviderEnabled() is returning true

Tags:

android

I can check if GPS is on or not using isProviderEnabled(). If it is not on, I am launching intent so that user can enable GPS. At the end I am again checking if GPS is enabled by user or not. If user does not enable GPS and come out, still isProviderEnabled() is returning NULL. What could be the issue ? Please guide me.

    String provider = LocationManager.GPS_PROVIDER;
    // Check if GPS is enabled
    boolean enabled = myLocationManager.isProviderEnabled(provider);

    if (!enabled) {
                    // GPS not enabled
        Log.d("", "Provider " + provider + " is not enabled");
        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivity(intent);
                    // Consider the case when user does not enable GPS and come out. 
    } else {
        Log.d("", "Provider is enabled");

    }       

            // Re-check if user has enabled or not. (Note: case: user has not enabled GPS)
    enabled = myLocationManager.isProviderEnabled(provider);
    if(!enabled)
    {

        Log.d("","provider not enabled");
    }
            else
            {
                    // Control is coming here though user has not enabled GPS in settings
                    Log.d("","GPS is enabled");
            }

Thanks, Biplab

like image 873
Biplab Kundu Avatar asked Apr 12 '12 04:04

Biplab Kundu


1 Answers

Check GPS enable using this code and let me know what happen,

private void CheckEnableGPS(){
    String provider = Settings.Secure.getString(getContentResolver(),
      Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
       if(!provider.equals("")){
           //GPS Enabled
        Toast.makeText(AndroidEnableGPS.this, "GPS Enabled: " + provider,
          Toast.LENGTH_LONG).show();
       }else{
        Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
           startActivity(intent);
       }   
   }
like image 109
user370305 Avatar answered Oct 06 '22 00:10

user370305