Changing screen brightness programmatically (as with the power widget)

This is the complete code I found to be working: Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 20); WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness =0.2f;// 100 / 100.0f; getWindow().setAttributes(lp); startActivity(new Intent(this,RefreshScreen.class)); The code from my question does not work because the screen doesn’t get refreshed. So one hack on refreshing the screen is starting dummy activity and than in on create … Read more

Change the System Brightness Programmatically

You can use following: // Variable to store brightness value private int brightness; // Content resolver used as a handle to the system’s settings private ContentResolver cResolver; // Window object, that will store a reference to the current window private Window window; In your onCreate write: // Get the content resolver cResolver = getContentResolver(); // … Read more