`

GPS的开关设置

阅读更多
//modify by hyxu 2015-9-30 to support above 19 version
public void change(boolean closeOrOpen) {
if (Build.VERSION.SDK_INT <19) {
Secure.setLocationProviderEnabled(mContext.getContentResolver(),
LocationManager.GPS_PROVIDER, closeOrOpen);
}else{
if(!closeOrOpen){
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_OFF);
    }else{
    Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE, android.provider.Settings.Secure.LOCATION_MODE_BATTERY_SAVING);
    }
}
}


public boolean isOnOff() {
if (Build.VERSION.SDK_INT <19) {
LocationManager myLocationManager = (LocationManager )mContext.getSystemService(Context.LOCATION_SERVICE);
return myLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}else{
int mode = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE,
                Settings.Secure.LOCATION_MODE_OFF);
if(mode==Settings.Secure.LOCATION_MODE_OFF){
return false;
}else{
return true;
}
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics