打开和关闭gps
//打开或者关闭gps
public void openGPS(boolean open) {
if (Build.VERSION.SDK_INT <19) {
Secure.setLocationProviderEnabled(context.getContentResolver(),
LocationManager.GPS_PROVIDER, open);
}else{
if(!open){
Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF);
}else{
Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
}
}
}
//判断gps是否处于打开状态
public boolean isOpen() {
if (Build.VERSION.SDK_INT <19) {
LocationManager myLocationManager = (LocationManager )mContext.getSystemService(Context.LOCATION_SERVICE);
return myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}else{
int state = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
if(state==Settings.Secure.LOCATION_MODE_OFF){
return false;
}else{
return true;
}
}
}