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
  • 67,701
  • 16
  • 123
  • 163
TRose
  • 302
  • 3
  • 16

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
  • 5,297
  • 5
  • 39
  • 59