Skip to content

Instantly share code, notes, and snippets.

@danikx
Created September 5, 2017 10:23
Show Gist options
  • Save danikx/e59221c5b8034fddce112eae09eeb0fd to your computer and use it in GitHub Desktop.
Save danikx/e59221c5b8034fddce112eae09eeb0fd to your computer and use it in GitHub Desktop.
android isLocationEnabled
public static boolean isLocationEnabled(Context context) {
int locationMode = 0;
String locationProviders;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
}else{
locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment