TMH
TMH

Reputation: 6246

Android detect location settings

I'm using the new Location API in my app and I'm wondering how to detect if I the user has location access enabled on there phone.

I'm setting up a LocationClient and running a LocationRequest. How would I run a check before doing this to see if I can actually get the users location?

Upvotes: 0

Views: 1419

Answers (1)

fasteque
fasteque

Reputation: 4339

In your onConnected you could call a method like these:

private boolean checkLocationProviders()
{
    if(mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
    {
        return true;
    }
    else
    {
        if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            return true;
        else
            return false;
    }
}

If false is returned, you can open the Settings screen in this way:

startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));

Upvotes: 2

Related Questions