一般android手机旁边有两个控制声音加、减的按钮,我现在的项目要求用户按了声音的加、减后拦截下来,把这两个命令用于别的用途,求大神解答~
------解决方案--------------------
好像是这个,错了别喷我
- Java code
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_VOLUME_UP: audio.adjustStreamVolume( AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audio.adjustStreamVolume( AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI); return true; default: break; } return super.onKeyDown(keyCode, event); }