Click here to Skip to main content
Click here to Skip to main content

Check whether location services are enabled on Android Phone

By , 1 Apr 2013
 

Introduction

Nowadays, Many applications use location services. As a developer, you have to check location services are enabled or disabled if your app uses location services. Let's look at how to check location services. 

Using the code 

First, you have to add location services permission to manifest file. 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

Second, you have to check whether location services are enabled by using some boolean function. To do this, you have to access to location manager. Location manager has some provider information. For example location services are enabled or disabled. 

 public static boolean control(){

LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);  

        if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){  
           //GPS enabled
           return true;
        }
           
        else{
           //GPS disabled
           return false;
        }
}       

 As you see, if location services are enabled, function returns true. If it isn't, function returns false.  

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Melih Mucuk
Software Developer Minor Info. Tech.
Turkey Turkey
Member
Melih Mucuk
 
Software & Mobile App Developer
 
Visit my blog: http://blog.melihmucuk.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130513.1 | Last Updated 1 Apr 2013
Article Copyright 2013 by Melih Mucuk
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid