Skip to content

Instantly share code, notes, and snippets.

@melihmucuk
Created October 1, 2013 22:12
Show Gist options
  • Select an option

  • Save melihmucuk/6786011 to your computer and use it in GitHub Desktop.

Select an option

Save melihmucuk/6786011 to your computer and use it in GitHub Desktop.
Programmatically changing screen brightness on Android
boolean ScreenBrightness(int level, Context context) {
try {
android.provider.Settings.System.putInt(
context.getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS, level);
android.provider.Settings.System.putInt(context.getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE,
android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
android.provider.Settings.System.putInt(
context.getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS,
level);
return true;
}
catch (Exception e) {
Log.e("Screen Brightness", "error changing screen brightness");
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment