Created
May 22, 2019 08:01
-
-
Save CodeK1988/6465089cbf50ab037d42ebff65017e95 to your computer and use it in GitHub Desktop.
change volume
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var audioManager: AudioManager? = null | |
audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager | |
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { | |
when (keyCode) { | |
KeyEvent.KEYCODE_BACK -> { | |
} | |
KeyEvent.KEYCODE_VOLUME_DOWN -> { | |
audioManager?.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI) | |
return true | |
} | |
KeyEvent.KEYCODE_VOLUME_UP -> { | |
audioManager?.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI) | |
return true | |
} | |
} | |
return super.onKeyDown(keyCode, event) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment