I want to adjust screen brightness by clicking a button, so when the backgroud is white the screen brightness should be maximum, meanwhile if the background is black the screen brightness should be the minimum, but I got an error: NullPointerException... here is my code :
public void lamp2(boolean mode){
if(mode){
r.setBackgroundColor(Color.WHITE);
btn.setText("Turn OFF");
btn.setTextColor(Color.RED);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 90 / 100.0f;
getWindow().setAttributes(lp);
this.mode = true;
}
else if(!mode){
r.setBackgroundColor(Color.BLACK);
btn.setText("Turn ON");
btn.setTextColor(Color.GREEN);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 100 / 100.0f;
getWindow().setAttributes(lp);
this.mode = false;
}
}