I have the same need like this, but I found the answer under that question aren't work.
I want to make buttons to change my screen brightness while my app is running.
I have found this code, but it doesn't work if I copy this code into my mainActivity directly.
WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness=1.0f;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
I use android studio and API level is 21 and I added user permission.
This piece code is the nearest to my target, who can help me run this code?