I have a requirement in my app where I have to select various buttons like Search, Volume Up, Volume Down, Back buttons to launch my app.
I know that I have to override the functionality of the these buttons but what API do I have to use and exactly how can I override them.
Your application should be running and you need this code:
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
// Do your thing
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
List of keys: http://developer.android.com/reference/android/view/KeyEvent.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With