I ran into a problem today with trying to override the screen brightness for the current activity. I found there are 2 methods of changing your screen brightness, 1 which changed the whole system brightness or the other which is to change your current activity’s brightness.
I went for the latter however I came up against some problems when I tried to use the code I found here;
http://stackoverflow.com/a/5090578/276220
public void SetBright(float value) { Window mywindow = getWindow(); WindowManager.LayoutParams lp = mywindow.getAttributes(); lp.screenBrightness = value; mywindow.setAttributes(lp); } |
public void setBrightness(float brightness){ try{ int brightnessMode = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE); if (brightnessMode == android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) { android.provider.Settings.System.putInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); } WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.screenBrightness = brightness; getWindow().setAttributes(layoutParams); } catch (Exception e){ // do something useful } } |
http://android-er.blogspot.com/2011/02/change-system-screen-brightness-using.html