how can i detect if volume up and down buttons are pressed simultaneously for certain period of time to perform specific task on android. I'm currently using java to develop an application which increment the count on pressing volume up and down button together for some period of time.
if(keycode == KeyEvent.KEYCODE_VOLUME_DOWN && keycode == KeyEvent.KEYCODE_VOLUME_UP) {
// Two buttons pressed, call your function
count++;
String num = String.valueOf(count);
number.setText(num);
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
}
I tried this code but it didn't work
I also used boolean
while(keycode == KeyEvent.KEYCODE_VOLUME_DOWN || keycode == KeyEvent.KEYCODE_VOLUME_UP){
if (keycode == KeyEvent.KEYCODE_VOLUME_DOWN){
down = true;
if(keycode == KeyEvent.KEYCODE_VOLUME_UP){
up = true;
if(up && down) {
// Two buttons pressed, call your function
Toast.makeText(getApplicationContext(), "Hello",
Toast.LENGTH_SHORT).show();
}
}
}
}