判断是否开定位权限,没开并跳转权限界面
private LocationManager lm;//【位置管理】
lm = (LocationManager) getActivity().getSystemService(getActivity().LOCATION_SERVICE);
boolean enable = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (enable) {//开了定位服务
if (ContextCompat.checkSelfPermission(getActivity(),Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 没有权限,申请权限。
// Toast.makeText(getActivity(), "没有权限", Toast.LENGTH_SHORT).show();
} else {
// 有权限 do something
// Toast.makeText(getActivity(), "有权限", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), "系统检测到未开启GPS定位服务", Toast.LENGTH_SHORT).show();
// 跳转到开启页面
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 200);
}