[android]判断位置服务是否打开

public boolean isLocationEnabled() {
int locationMode = 0;
String locationProviders;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
try {
locationMode = Settings.Secure.getInt(getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);

} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}

return locationMode != Settings.Secure.LOCATION_MODE_OFF;

}else{
locationProviders = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders);
}


}
posted @ 2016-12-19 16:07  丁个人  阅读(2028)  评论(0)    收藏  举报