1

In Android user can change brightness by "rolling down" the status bar (or notification bar, whatever this is called in Android) and changing brightness there.

I need to display brightness slider in my app. I know how to get system brightness value, but the question is how to know if user changed the brightness? When user rolls-up the notification bar I don't get onResume. How do I know that the brightness has changed or the notification bar revealed my activity to the user?

Łukasz Sromek
  • 3,637
  • 3
  • 30
  • 43
  • https://stackoverflow.com/questions/46119279/how-to-detect-if-screen-brightness-has-changed-in-android – user9170 Oct 07 '20 at 14:48

2 Answers2

3

Try creating a thread with a runnable that runs indefinitely (or till you want it to run) where you listen for a change in the current brightness. This can be done pretty easily

  1. Find the original screen brightness and assign it to a variable called oldScreenBrightness.

  2. In your thread check

    currentScreenBrightness = getCurrentScreenBrightness();
    if (oldScreenBrightness != currentScreenBrightness)
    {
        doSomething()
        oldScreenBrightness = currentScreenBrightness
    }
    else
    {
       doNothing or doSomethingElse
    }
    
Lucifer
  • 29,392
  • 25
  • 90
  • 143
A Random Android Dev
  • 2,691
  • 1
  • 18
  • 17
-1

Go to settings Select display Select notification panel Check Brightness adjustment