1

I try to change brightness when dialog fragment opened,i insert this code on oncreate() but it change only for one second.

    try {
        curBrightnessValue = Settings.System.getInt(
                getActivity().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);

        WindowManager.LayoutParams layout = getActivity().getWindow().getAttributes();
        layout.screenBrightness = 1F;
        getActivity().getWindow().setAttributes(layout);

    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }

In main fragment it works

tecn603
  • 211
  • 5
  • 14
  • Try to do it in `onResume` to see if there is a difference – cesarmarch Jun 18 '19 at 16:52
  • Thanks for reply, i already tried, but have the same result – tecn603 Jun 18 '19 at 16:59
  • Did you look at this thread ? https://stackoverflow.com/questions/18312609/change-the-system-brightness-programmatically – cesarmarch Jun 18 '19 at 18:30
  • Thanks for reply, i can't ask system permission to my users, not is a best solution. – tecn603 Jun 18 '19 at 18:44
  • I try to use ` onActivityResult()` from my caller fragmet ad try to set brightness before call a dialog fragment and reset after call it, but when dialog fragment opened it ignore the brightness setted by parent fragment. Can you help me? – tecn603 Jun 18 '19 at 19:16
  • I found the problem: `setStyle(DialogFragment.STYLE_NORMAL, R.style.MppTheme_FullScreenDialog);` I set a full-screen dialog with this code, if i remove it brightness work fine. How i can set in other way the full-screen fragment dialog? – tecn603 Jun 18 '19 at 19:47
  • I had the same problem. Check the solution at https://stackoverflow.com/a/49731557/896002. It worked for me – Ajeesh A Jul 15 '19 at 15:37

0 Answers0