简体   繁体   中英

Prevent screen sleeping

Android v4.2.2. I'm trying to stop the screen from going to sleep. I've tried a few things like changing the relevant settings in the db:

adb shell "sqlite3 /data/data/com.android.providers.settings/databases/settings.db  \"update system set value='-1' where name='screen_off_timeout'\";"

But that didn't work - screen just went to sleep almost immediately. If I go to the settings app there isn't an option to disable it. Instead, it ranges from 15s to 30m.

I have also tried to set the KEEP_SCREEN_ON FLAG in the application but that stops working when I switch to a new activity.

Is there anything else I can try. I was hoping a db setting would do the job. Here is my system db as it stands. Perhaps a setting I am missing and can insert?

1|volume_music|11
2|volume_ring|5
3|volume_system|7
4|volume_voice|4
5|volume_alarm|6
6|volume_notification|5
7|volume_bluetooth_sco|7
8|mode_ringer_streams_affected|174
9|mute_streams_affected|46
10|vibrate_when_ringing|0
11|dim_screen|0
13|dtmf_tone_type|0
14|hearing_aid|0
15|tty_mode|0
16|screen_brightness|102
17|screen_brightness_mode|0
18|window_animation_scale|1.0
19|transition_animation_scale|1.0
20|accelerometer_rotation|1
21|haptic_feedback_enabled|1
22|notification_light_pulse|1
23|dtmf_tone|1
24|sound_effects_enabled|1
26|lockscreen_sounds_enabled|1
27|pointer_speed|0
28|next_alarm_formatted|
29|alarm_alert|content://media/internal/audio/media/5
30|notification_sound|content://media/internal/audio/media/7
31|ringtone|content://media/internal/audio/media/9
32|volume_music_headset|10
33|volume_music_last_audible_headset|10
34|volume_music_headphone|10
35|volume_music_last_audible_headphone|10
36|time_12_24|24
37|date_format|dd-MM-yyyy
39|stay_on_while_plugged_in|1
45|screen_off_timeout|-1

Your setting db contains default time out set by the system which is probably low so the device went to sleep immediately due to low timeout value. You can issue adb shell command to increase screen timeout.

adb shell settings put system screen_off_timeout 60000

Note: 60000 = 1 minute

You can also update setting db with the desired timeout and then push db back to device but it requires root. Above command does not require device to be rooted.

This is related to Activity , There is no impact from DB . Just add android:keepScreenOn="true" to the layout in your xml

Did you try this

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
 PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
 wl.acquire();

For more go through this link http://thiranjith.com/2012/02/22/android-prevent-screen-timeout/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM