Reputation: 186
So I am fairly new to the world of coding and I am doodling with a little private learning project. I have made a simple web browser based on WebView for a embedded android 7.1 ELOtouch device.
I have found plenty of articles online on how to turn the screen on/off etc but never really managed to make it work.
What I am trying to do is that the screen dims down to the lowest level after xx amount of time, let’s say 5min. And only dims back up to a defined level upon user touch/screen input.
The unit is always on and don’t have any form for advanced screen adjustments in settings, so as I see it, it has to be done programmatically.
Thankful for and advice or guidance.
Attached one of my sources:
How to change screen timeout programmatically?
Upvotes: 0
Views: 591
Reputation: 13539
To change screen brightness by user touch, you could do like this:
In AndroidManifest.xml file, add this line:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
And in some place of activity class file:
Settings.System.putInt(this.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, 80);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness =0.8f;
getWindow().setAttributes(lp);
startActivity(new Intent(this,DummyActivity.class));
Note: when setting up brightness,the modification doesn't take effect immediately, to solve this problem,just start another blank dummy activity and finish it in Oncreate
()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
finish();
}
Don' forget to include DummyActivity in AndroidManifest.xml.
Edited:
To dim screen after some time, the basic logic is same, and maybe you should create a Timer(TimerTask). Hope this is helpful!
Upvotes: 1