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)){
return true;
}
else{
return false;
}
}
As you see, if location services are enabled, function returns true. If it isn't, function returns false.