ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

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?

Image credit: Pixel 4a Quick Settings (Joe Maring)

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 screenBrightnessattribute 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.

Let’s take a look at the example below:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

No responses yet

Write a response