判断位置开关是否打开
正常判断Gps定位或者网络定位是否开启,可以直接使用
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
当然,这是正常情况。再vivo上,他不正常,还是8.1.0的系统
所以,推荐使用下面的方式去判断,直接判断开关按钮,粗暴高效
try {
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
return false;
}
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
尝试了一下
华为10.0
小米9.0
vivo8.1
oppo6.0
是可以的