I am using the following code to dim screen on Android. It is working well for the android version except version 6.0 (Marshmallow).
WindowManager.LayoutParams params = getActivity().getWindow().getAttributes();
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0f;
getActivity().getWindow().setAttributes(params);
How to solve this problem for Android version 6.0?