Android Screen Timeout

How to change screen timeout programmatically?

It is simple to do.. You should learn to solve your problem from Android source code.

  /**
* set screen off timeout
* @param screenOffTimeout int 0~6
*/
private void setTimeout(int screenOffTimeout) {
int time;
switch (screenOffTimeout) {
case 0:
time = 15000;
break;
case 1:
time = 30000;
break;
case 2:
time = 60000;
break;
case 3:
time = 120000;
break;
case 4:
time = 600000;
break;
case 5:
time = 1800000;
break;
default:
time = -1;
}
android.provider.Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, time);
}

Android Screen Timeout

The Settings.System provider offers a SCREEN_OFF_TIMEOUT setting that might be what you are looking for.

How to get Default Screen Timeout Time from settings programmatically?

You need to use getInt() for that

Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT))

Reference

Android prevent screen timeout

Solution was very simple done using Unity adding the following Code into the Start() Function:

        Screen.sleepTimeout = SleepTimeout.NeverSleep;

I doesn't know if it is switched of automatically by Unity or nor but I hope so.

Link to Unity Documentation

Screen timeout time remains?

You can get the default screen timeout set by the system using this:

android.provider.Settings.System.getInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT,-1);

So you have the default timeout and the last time the user touched the device. With this you can approximate the time left for the screen to turn off.

Though i am not sure how you would handle user touches to the NotificationBar which would reset the timeout.



Related Topics



Leave a reply



Submit