Android Screen Timeout
I know its possible to use a wakelock to hold the screen, cpu, ect on but how can I programmatically change the 'Screen Timeout' setting on an Android phone.
Solution 1:
publicclassHelloWorldextendsActivity
{
privatestaticfinalintDELAY=3000;
intdefTimeOut=0;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState)
{
// Be sure to call the super class.super.onCreate(savedInstanceState);
// See assets/res/any/layout/hello_world.xml for this// view layout definition, which is being set here as// the content of our screen.
setContentView(R.layout.hello_world);
defTimeOut = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
}
@OverrideprotectedvoidonDestroy()
{
super.onDestroy();
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, defTimeOut);
}
}
And also dont forget to add this permission in manifest:
android:name="android.permission.WRITE_SETTINGS"
Solution 2:
Above is correct:
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
But also include permission in manifest:
android:name="android.permission.WRITE_SETTINGS"
Solution 3:
The Settings.System provider offers a SCREEN_OFF_TIMEOUT setting that might be what you are looking for.
Solution 4:
Here is a code-sheet, you can do more.
long stand = Settings.System.getLong(
mContext.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT,
-1);
long sec = stand / 1000;
String time = null;
if(stand<0) {
//close.
}
elseif( sec >= 60) {//to minute
time = String.format(mContext.getString(R.string.minutes), (sec / 60) + "");
} else {
time = String.format( mContext.getString(R.string.seconds),sec + "");
}
Post a Comment for "Android Screen Timeout"