I know that some devices headphone ports (maybe all of them? any reference here would be good) have 3 channels, for stereo sound and microphone. So I was wondering if it\'s poss
I finally managed to read the pedal input. @emrys57 is right, replacing the jack with the 4-pin connector, triggered the input the same way microphones with a hook button do. However occasionally it seems to trigger the volume up and the volume down keys as well. I suppose this is related to me replacing the 4-pin jack with a knife and tape.
It was fairly simple to override onKeyUp. Be aware that you also have to override onKeyDown to prevent the default behavior:
@Override
public boolean onKeyDown(int keyCode,KeyEvent event){
int action = event.getAction();
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_HEADSETHOOK) {
if (action == KeyEvent.ACTION_UP) {
Log.d(TAG, "action_up");
clickStart(null);
return true;
} else if (action == KeyEvent.ACTION_DOWN) {
Log.d(TAG, "action_down");
return true;
} else {
Log.d(TAG, "action:" + action);
return true;
}
}
return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
int action = event.getAction();
Log.d(TAG, "onKeyDown!");
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
|| keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|| keyCode == KeyEvent.KEYCODE_HEADSETHOOK) {
if (action == KeyEvent.ACTION_UP) {
Log.d(TAG, "action_up");
clickStart(null);
return true;
} else if (action == KeyEvent.ACTION_DOWN) {
Log.d(TAG, "action_down");
return false;
} else {
Log.d(TAG, "action:" + action);
return true;
}
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
Log.d(TAG, "returning false");
return false;
}