问题
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.
回答1:
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);
来源:https://stackoverflow.com/questions/2899621/how-can-i-check-for-gps-support-in-app-to-add-a-feature-for-those-with-location