Android打开或者关闭GPS

来源:互联网 发布:java session工作原理 编辑:程序博客网 时间:2024/06/01 09:35

打开和关闭gps

//打开或者关闭gpspublic 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;         }     } }
0 0
原创粉丝点击