0

I'm writing an app to change screen brightness with seekbar and I use this code on event onProgressChanged

Settings.System.putInt(getApplicationContext().getContentResolver(),Settings.System.SCREEN_BRIGHTNESS,newBrightness);

but the application crashed after this code. I also added

<uses-permission android:name="android.permission.WRITE_SETTINGS"/> to Manifest

Does anyone know why? please help me

Thanks in advance

AskNilesh
  • 63,753
  • 16
  • 113
  • 150
Lirus
  • 97
  • 2
  • 12

1 Answers1

1

You should refresh the screen too. It's more complicated that your code.

Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 20);
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = 0.2f;
getWindow().setAttributes(layoutParams);
startActivity(new Intent(this,RefreshScreen.class));

And also you may need to set automatic mode off :

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Arash Hatami
  • 4,771
  • 4
  • 38
  • 53