如何在settings里的休眠模式里添加永不休眠
Posted muhuacat猫窝
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在settings里的休眠模式里添加永不休眠相关的知识,希望对你有一定的参考价值。
最近项目需求里需要在设置菜单的休眠模式里添加一项永不休眠选择项。针对MTK平台的修改方式有如下几步骤。(其他平台和android原生系统的修改方式类似,只是android原生系统修改永不休眠需要通过设置较长的时间实现)
1.由于代码不同,在Jelly Bean(android4.2)之前,如下
在alps\frameworks\base\packages\SettingsProvider\res\values\defaults.xml中设置def_screen_off_timeout为-1,即
-1
同时请注意,经由下面的操作,setting里面休眠时间的Never菜单才会出来:
修改alps\packages\apps\Settings\res\values\arrays.xml:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!-- Display settings. The delay in inactivity before the screen is turned off. These are shown ain a list dialog. -->
<string-array name="screen_timeout_entries">
<item>15 seconds</item>
<item>30 seconds</item>
<item>1 minute</item>
<item>2 minutes</item>
<item>10 minutes</item>
<item>30 minutes</item>
<item>never</item>
</string-array>
<!-- Do not translate. -->
<string-array name="screen_timeout_values" translatable="false">
<!-- Do not translate. -->
<item>15000</item>
<!-- Do not translate. -->
<item>30000</item>
<!-- Do not translate. -->
<item>60000</item>
<!-- Do not translate. -->
<item>120000</item>
<!-- Do not translate. -->
<item>600000</item>
<!-- Do not translate. -->
<item>1800000</item>
<item>-1</item>
</string-array>
修改对比语言value文件夹下的arrays.xml,修改screen_timeout_entries对应的翻译。不用管那个msgid,只是google用来表示是他自己的资源而已,直接添加"不灭"即可,请知悉。
2,若是android4.2的code,请在前面的修改基础上再修改下面的代码:
PowerManagerService.java
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private void updateUserActivitySummaryLocked(long now, int dirty) {
.....
//change code here ==============
Slog.d(TAG,"mScreenOffTimeoutSetting ="+mScreenOffTimeoutSetting);
//if (mUserActivitySummary != 0 ) {
if (mUserActivitySummary != 0 && mScreenOffTimeoutSetting > 0) {
//change code here end ==============
Message msg = mHandler.obtainMessage(MSG_USER_ACTIVITY_TIMEOUT);
msg.setAsynchronous(true);
mHandler.sendMessageAtTime(msg, nextTimeout);
}
3.最后对packages/apps/Settings/src/com/android/settings下的DisplaySettings.java文件进行修改,修改如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private void updateTimeoutPreferenceDescription(long currentTimeout) {
String summary;
//code here
//if (currentTimeout < 0) {
// Unsupported value
//summary = "";
// } else {
final CharSequence[] entries = preference.getEntries();
final CharSequence[] values = preference.getEntryValues();
//code end
....................................
if (entries.length != 0) {
//code here
if(best == 7){
summary = "无操作 永不灭";
}else{
summary = preference.getContext().getString(
R.string.screen_timeout_summary, entries[best]);
Log.i("zfc","summary="+summary+",best="+best);
}
//code end
} else {
summary = "";
}
以上是关于如何在settings里的休眠模式里添加永不休眠的主要内容,如果未能解决你的问题,请参考以下文章