I want to change the brightness of screen with volume keys. I used this code, but it doesn't work:
@Override
public boolean onKeyDown(int keyCode,KeyEvent keyEvent){
WindowManager.LayoutParams layout = getWindow().getAttributes();
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN){
switch (keyCode){
case KeyEvent.KEYCODE_VOLUME_DOWN:
layout.screenBrightness -= 0.1;
getWindow().setAttributes(layout);
break;
case KeyEvent.KEYCODE_VOLUME_UP:
layout.screenBrightness += 0.1;
getWindow().setAttributes(layout);
break;
}
}
return super.onKeyDown(keyCode , keyEvent);
}
When I press volume key down/up ringer volume is changed?