views:

45

answers:

1

How can I check for GPS support in-App to add a feature for those with Location services enabled?

My concern is, I know I'd have to specify the tag in the manifest to declare that the app uses location services, but I still want the app to function for those without. I just want to check and, if the service is available, use it; otherwise just ignore that one feature.

Thanks.

+3  A: 

You can check if any Location services are enabled by looking to see if any location providers are enabled. I'm using this function in my code right now:

public static boolean areProvidersEnabled(Context context) {
    ContentResolver cr = context.getContentResolver();
    String providersAllowed = Settings.Secure.getString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    return providersAllowed != null && providersAllowed.length() > 0;
}

Another neat thing is that you can send the user straight to the Location settings and ask them if they want to enable it. I'll leave it to you on how to ask the user, but the Intent to get to the settings is like this:

Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
Daniel Lew
Thanks! Sorry for the delayed accept!
Brian Lacy