Android 5.0以上版本禁止锁屏与休眠
来源:互联网 发布:Java加密解密 面试 编辑:程序博客网 时间:2024/06/08 09:42
本人以这种方式记录一些东西,免得以后再次需要时忘了。
Android 5.0以上的版本与以往的版本差别较大,禁止锁屏与休眠需要修改的也有些不同。
主要在/frameworks/base/packages/SettingsProvider/res/values/defaults.xml中修改
将def_screen_off_timeout休眠时间修改为最大值,最大值就是永不休眠
<integer name="def_screen_off_timeout">2147483647</integer>
这样仅仅只是修改了默认的休眠时间,系统开机时还是会自动锁屏休眠,这就需要修改def_lockscreen_disabled为true
<bool name="def_lockscreen_disabled">true</bool>
这时候按电源键还是会锁屏,这个功能在Android开发板中经常是不用的,修改def_screenshot_button_show为false可以屏蔽电源键锁屏功能,若是没有这个参数可以手动添加
<bool name="def_screenshot_button_show">false</bool>
但是还有一个问题,我们只是修改了默认休眠时间,当用户再次设置休眠时间了,时间又会改变,这时候我们在系统设置的源码中DisplaySettings.java修改,路径是/packages/apps/Settings/src/com/android/settings/DisplaySettings.java,在onPreferenceChange函数中把需要传入的timeoutValue 值写死成 Integer.MAX_VALUE
@Override public boolean onPreferenceChange(Preference preference, Object objValue) { final String key = preference.getKey(); if (KEY_SCREEN_TIMEOUT.equals(key)) { int value = Integer.parseInt((String) objValue); int oldvalue = Integer.parseInt(((ListPreference)preference).getValue()); if (value != oldvalue) { Log.d(TAG, "update screen timeout from "+ oldvalue + " to " + value); // timeoutValue = Integer.MAX_VALUE int timeoutValue = Integer.MAX_VALUE/*( -1 == value) ? Integer.MAX_VALUE : value*/; try { Settings.System.putInt(getContentResolver(), SCREEN_OFF_TIMEOUT, timeoutValue); updateTimeoutPreferenceDescription(value); } catch (NumberFormatException e) { Log.e(TAG, "could not persist screen timeout setting", e); } } } if (KEY_FONT_SIZE.equals(key)) { writeFontSizePreference(objValue); } if (preference == mAutoBrightnessPreference) { boolean auto = (Boolean) objValue; Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE, auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL); } if (preference == mLiftToWakePreference) { boolean value = (Boolean) objValue; Settings.Secure.putInt(getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0); } if (preference == mDozePreference) { boolean value = (Boolean) objValue; Settings.Secure.putInt(getContentResolver(), DOZE_ENABLED, value ? 1 : 0); } return true; }
0 0
- Android 5.0以上版本禁止锁屏与休眠
- android 4.2以上版本永不休眠
- android 4.2以上版本永不休眠
- android 4.2以上版本永不休眠 .
- android 4.2以上版本永不休眠
- android 4.2以上版本永不休眠
- android 4.2以上版本永不休眠
- android 4.2以上版本永不休眠
- android 禁止休眠和锁屏
- Android 禁止屏幕休眠和锁屏的方法
- Android屏幕禁止休眠和锁屏的方法
- Android 禁止屏幕休眠和锁屏的方法 .
- Android屏幕禁止休眠和锁屏的方法
- Android 禁止屏幕休眠和锁屏的方法
- Android屏幕禁止休眠和锁屏的方法
- Android 禁止屏幕休眠和锁屏的方法
- Android 禁止屏幕休眠和锁屏的方法
- Android 禁止屏幕休眠和锁屏的方法
- c:forEach
- 【解决方案】Android中Log太多太长打印不全的问题
- java内存溢出和内存泄露
- 三十行代码实现一个简单计算器
- Serializable与Parcelable
- Android 5.0以上版本禁止锁屏与休眠
- 字符编码常识及问题解析
- jsonp跨域请求
- 含有注释的SQL生成器升级
- Socket通信实例
- Spring Cache
- does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), o
- R 语言绘图条形产生随机颜色
- Android Studio 2.0 Beta 6 中配置强大的版本控制系统(Git篇)