Search code examples
androidscreen-brightness

changing screen brightness programmatically in android


I want to change the screen brightness programmatically in android. At the moment I use this code:

WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness=1.0f;
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);

But this sample code works on cupcake, not on latest versions. I am using the latest version of SDK.. What is the preferred solution for newer Android Versions?


Solution

  • How about using the IHardwareService interface for this? An example can be found in this tutorial.

    Update: tutorial link still works, but actual code is also available in next answer.