80524

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

Question:

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.

Answer1:

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

Recommend

  • How to reduce the time delay to reach run method of Runnable class using ExecutorService Java
  • Date format change angular 2
  • Ignore some files from SVN commit
  • C++ std::set comparator
  • Prolog Query - Trying to understand how this result happens
  • Angular2 emit event up to the DOM tree
  • Does the failbit effect the call ignore on cin?
  • Initialization section of the package
  • calling a fragment from fragment
  • to implement a spinner in angular2+
  • Running jasmine tests for a component with NgZone dependency
  • MVC - @Html.CheckBoxFor
  • Why are YouTube videos using 'youtube.com/v' not loading
  • Salesforce Different WSDL files and when to use
  • Intel-64 and ia32 atomic operations acquire-release semantics and GCC 5+
  • Zoom in and out of jPanel
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • Firefox Extension - Monitor refresh and change of tab
  • Specifying Castle WCF Integration Facility Endpoint Behavior per Endpoint
  • System.InvalidCastException: Specified cast is not valid
  • Saving Changes After In-App Purchase Has Been Purchased
  • How can I extract results of aggregate queries in slick?
  • OOP Javascript - Is “get property” method necessary?
  • Is calc() supported in html email?
  • PHP - How to update data to MySQL when click a radio button
  • req.body is undefined - nodejs
  • Is there a amazon webstore API for customers?
  • Symfony2: How to get request parameter
  • To display the title for the current loaction in map in iphone
  • Akka Routing: Reply's send to router ends up as dead letters
  • Circular dependency while pushing http interceptor
  • Is there a mandatory requirement to switch app.yaml?
  • Angular 2 constructor injection vs direct access
  • Bitwise OR returns boolean when one of operands is nil
  • reshape alternating columns in less time and using less memory
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?