Here's the relevant code:
WindowManager.LayoutParams windowParams = getWindow().getAttributes();
windowParams.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
windowParams.screenBrightness = 0.0f;
getWindow().setAttributes(windowParams);
I also tried setting screenBrightness to 0 (an integer rather than float), as well as the following line I found in a Stack Overflow answer:
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
No dice. The screen dims, but does not turn off. The above code worked in previous Android versions. I just tested it in an emulator to make sure. Was a new method implemented to control the screen?