我想在android中使用耳机按钮“KEYCODE_HEADSETHOOK”作为通话按钮,即按住时我可以做某事,然后当我释放它时停止。谢谢
这是我的代码
if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK/*KEYCODE_HEADSETHOOK*/ && event.getAction() == KeyEvent.ACTION_DOWN) {
Log.e("RAM","Set");
setPushToTalk(true);
return true;
}
else if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK && event.getRepeatCount() == 0 && (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) == KeyEvent.FLAG_LONG_PRESS) {
switch (keyCode) {
case MotionEvent.ACTION_DOWN:
if(!mService.isConnected()){
playTone();
return false ;
}
boolean waitFlag = false;
for (User user : mService.getUserList()) {
if (user.getChannel().equals(getChannel())) {
if (user.talkingState == 1)
waitFlag = true;// user);
// Log.e("Talking user",user.name+"/"+user.talkingState);
}
}
if (waitFlag){
sendWaitingMsg();
}
else{
setPushToTalk(true);
}
Log.e("headphone btn", "down");
return true;
case MotionEvent.ACTION_UP:
setPushToTalk(false);
Log.e("headphone btn", "up");
return true;
}