Reputation: 105
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
Upvotes: 3
Views: 1811
Reputation: 188
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.
Upvotes: -1
Reputation: 1807
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
Upvotes: 5