You can do the following to get the volume button with android:
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { //If volumedown key if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { this.loadUrl("javascript:cordova.fireDocumentEvent('volumedownbutton');"); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { this.loadUrl("javascript:cordova.fireDocumentEvent('volumeupbutton');"); return true; } else { //return super.onKeyDown(keyCode, event); } //return super.onKeyDown(keyCode, event); return true; } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { LOG.d(TAG, "KeyUp has been triggered on the view" + keyCode); // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');"); return true; } // Legacy else if (keyCode == KeyEvent.KEYCODE_MENU) { this.loadUrl("javascript:cordova.fireDocumentEvent('menubutton');"); return true; } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { this.loadUrl("javascript:cordova.fireDocumentEvent('searchbutton');"); return true; } return false; }
I copied this code from the cordova error report. This code is valid for cordova 2.0. I lost weight, you have to change "cordova.fireDocumentEvent" to "phonegap.fireDocument" or "PhoneGap.fireDocumentEvent"
update: Just wrote a small blog post about the error that was resolved using the code above. Link to Cordoba-Problem-Tracker can be found in this post: http://christian-kuetbach.de/blog/post/13
update 2: The problem seems to be fixed inside cordova 1.9: https://issues.apache.org/jira/browse/CB-871
Hope this helps.
source share