Changing the system setting for the brightness may work, but will not trigger the screen brightness to actually change. The WindowManager will need to receive an event to be refreshed, as pointed out in an answer to this related question. Furthermore, if the brightness switch is set to auto, your setting will be overridden as soon as the light sensor's value changes.
Unfortunately, in order to somehow cause the WindowManager to acknowledge the new brightness setting, you'll need an activity context. Instead of needlessly creating a new activity only to destroy it immediately, I would suggest creating a window, and applying the brightness value to the LayoutParams as suggested by others in this thread.
A common way of doing this is displaying a system modal window, and applying the LayoutParams to its attributes:
final View view = new View(this);
int dimension = 0;
int pixelFormat = PixelFormat.TRANSLUCENT;
if (DISPLAY) {
view.setBackgroundColor(Color.argb(128, 255, 0, 0));
dimension = LayoutParams.MATCH_PARENT;
pixelFormat = PixelFormat.RGBA_8888;
}
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
dimension, dimension,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
pixelFormat);
// 0f = minimum brightness; 1f = maximum brightness
float brightness = 1f;
params.screenBrightness = brightness;
Settings.System.putInt(cResolver,
Settings.System.SCREEN_BRIGHTNESS, 255 * brightness);
final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(view, params);
You'll need to add the following permission to your manifest:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
In the snippet, DISPLAY
is a simple switch to enable display of the overlay window for testing purposes. (You should see a half-transparent red overlay.)