画面の明るさを設定しようとしていますが、 this.getWindow() で現在のウィンドウを取得しようとすると null になります。どうしてこれなの?すべてのコードを setBrightness() メソッドに投稿します。
System.putInt(getContentResolver(), System.SCREEN_BRIGHTNESS,
brightness);
Window window = getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.screenBrightness = brightness / (float) 255;
window.setAttributes(lp);