3

I have seen 2 methods so far in my search, both of which I am having trouble with.

Method 1)

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 100);

Method 2)

IHardwareService hardware = IHardwareService.Stub.asInterface(ServiceManager.getService("hardware"));
hardware.setScreenBacklight(.5);

Which of these methods is correct? Or is there another that I should be using?

Thanks

Jim Jenkins
  • 105
  • 2
  • 9

2 Answers2

5

I use the code below to do the same

WindowManager.LayoutParams WMLP = getWindow().getAttributes();
WMLP.screenBrightness = 0.15F;
getWindow().setAttributes(WMLP);

The advantage of using the above code is that this affects the screen brightness only in the activity that calls it. So when I move to some other activity (or) quit the application, the phone's default brightness (As set by the user) is restored.

Edit: I forgot to mention that the range of the screenBrightness attribute is 0.0 - 1.0

Anand Sainath
  • 1,807
  • 3
  • 22
  • 48
-1

android.provider.Settings.System.putInt(getContentResolver(), Settings.System.DIM_SCREEN, time); where time is in milli seconds. but this Settings.System.DIM_SCREEN is depricated.

user3207655
  • 188
  • 2
  • 15