Here you will find an exemple with button to Allow Write Settings permisssion.
when this permission is granted you can change brigthness
ther is a button to keep screen on and an other to sleep it according to screen settings.
for this i used some extentions:
de.ullisroboterseite.ursai2applauncher.aix (29,4 Ko) to go to permissions setting screen
de.UllisRoboterSeite.UrsAI2WakeLock.aix (11,6 Ko) to keep screen on
both from Ullis Roboter Seite
his site is full of interresting extentions...you can donate to him...
and i wrote a small extension to add "android.permission.WRITE_SETTINGS" in manifest in order to be able to turn it on.jml.SETTINGSpermission.aix (4,9 Ko)
here is aia: Change_luminosite.aia (56,5 Ko)
I hope it will help it works very well on my Redmi 7A.
