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
Java or Python for Natural Language Processing
Most Efficient Way to Cast List<Subclass> to List<Baseclass>
How to Generate Multiple Lines in PDF Using Apache PDFbox
How to Escape Apostrophe or Quotes on a Jsp (Used by JavaScript)
Transformexception Duplicate Entry for Common.Annotations.Beta
Firebase Realtime Database Search by Word in Between the Query
Fragment Add or Replace Not Working
Convert a String to a Byte Array and Then Back to the Original String
PDF Library to Rendering the PDF Files in Android
Rotate Marker and Move Animation on Map Like Uber Android
How to Wait for All Tasks in an Threadpoolexecutor to Finish Without Shutting Down the Executor
Android 6.0 (Marshmallow): How to Play Midi Notes
How to Ask Permission to Access Gallery on Android M.
Google Cloud Messaging: Don't Receive Alerts When iOS App Is in Background
Is String Interning Really Useful
What Is the Equivalent of a Java Hashmap<String,Integer> in Swift