Member-only story
Change Screen Brightness Programmatically-Android
How can brightness be changed programmatically on the Android app screen and reflected on the system level?

It has been commonly practiced by increasing the brightness of the device when scanning or showing QR codes for payment. I’ve come across multiple applications that follow this practice, most of them either wallet or banking apps.
Now, there are 2 ways to achieve this task With and Without Permission. Let’s start with the easy one.
Without Permissions
The easier way is to adjust the brightness of the screen without affecting the system's brightness.
You can set the screenBrightness
attribute of the window, like so
val layout: WindowManager.LayoutParams? = activity?.window?.attributes
layout?.screenBrightness = 0.9f
activity?.window?.attributes = layout
The screenBrightness
attribute is a floating-point value ranging from 0 to 1, where 0.0 is 0% brightness, 0.5 is 50% brightness, and 1.0 is 100% brightness.