private LocationManager lm;
lm = (LocationManager) getSystemService(LOCATION_SERVICE);
boolean ok = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (ok) {//开了定位服务
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// 没有权限,申请权限。
Toast.makeText(this, "没有权限", Toast.LENGTH_SHORT).show();
} else {
// 有权限了,去放肆吧。
Toast.makeText(this, "有权限", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "系统检测到未开启GPS定位服务", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivityForResult(intent, 1315);
}