settings.system.putint
时间: 2023-04-20 17:00:43 浏览: 347
settings.system.putint是一个Android系统中的方法,用于将整数值存储到系统设置中。它需要两个参数:第一个参数是一个字符串,表示要存储的设置的名称;第二个参数是一个整数值,表示要存储的设置的值。例如,可以使用以下代码将一个名为“example_setting”的整数设置为123:
Settings.System.putInt(getContentResolver(), "example_setting", 123);
相关问题
if (isRotaionEnabled) {final IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));if (wm != null) {wm.freezeRotation(Surface.ROTATION_0);}Settings.System.putInt(context.getContentResolver(),Settings.System.ACCELEROMETER_ROTATION, 0);Settings.System.putInt(context.getContentResolver(),MtkSettingsExt.System.ACCELEROMETER_ROTATION_RESTORE, 1);}
这段代码的作用是控制屏幕自动旋转的开关。首先判断是否开启了自动旋转,如果开启了,则通过IWindowManager接口获取WindowManager服务,并调用其freezeRotation方法来锁定屏幕的方向为竖屏(Surface.ROTATION_0)。然后通过Settings.System.putInt方法将自动旋转的开关设置为关闭状态(0),并将一个MtkSettingsExt.System.ACCELEROMETER_ROTATION_RESTORE的值设为1,用于在后续恢复自动旋转时使用。如果自动旋转没有开启,则不执行任何操作。
Android Settings.System设置系统时间
要设置Android系统的时间,可以通过以下代码:
```java
long timeMillis = System.currentTimeMillis();
Settings.System.putInt(getContentResolver(), Settings.System.AUTO_TIME,0);
Settings.System.putIntContentResolver(), Settings.System.AUTO_TIME_ZONE, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_TIME, 0);
Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_TIME_ZONE, 0);
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeMillis);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hour);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long when = calendar.getTimeInMillis();
if (when / 1000 < Integer.MAX_VALUE) {
SystemClock.setCurrentTimeMillis(when);
}
```
其中,`year`是要设置的年份,`month`是要设置的月份(从0开始,0代表1月),`day`是要设置的日份,`hour`是要设置的小时数,`minute`是要设置的分钟数。
需要注意的是,这个操作需要`android.permission.SET_TIME`权限。另外,`AUTO_TIME`和`AUTO_TIME_ZONE`设置为0表示关闭自动更新时间和时区的功能。为了避免安全问题,这两个设置在Android 6.0及以上版本需要在系统设置中手动开启。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)