This simple code checks whether GPS in enabled in your android device or not.
If the GPS is not enabled the user is redirected to the settings page.

  LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
        boolean enabled = service.isProviderEnabled(LocationManager.GPS_PROVIDER); 

        // Check if enabled and if not send user to the GPS settings
        if (!enabled) {
        	Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);

Turn off the GPS on your device and running it will display this screen.

Please test GPS on the device because emulators don’t have GPS. But anyway you can simulate Longitude and Latitude which I will show in the coming posts.



Leave a Reply

Your email address will not be published. Required fields are marked *




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.