1

Like the combination of Power button and Volume down button - takes a screenshot of the phone... similarly I am trying to access volume up and power button long pressed keys in my app and give a shortcut. Is this possible?

I know how to get the access of both buttons individually but not combined at the same time.

      @Override
      public boolean onKeyLongPress(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_POWER){
        Log.w("LongPress", "power LONG PRESS");
    }

                if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
        Log.w("LongPress", "Volume Up LONG PRESS");
    }

    return super.onKeyLongPress(keyCode, event);
   }

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
        event.startTracking();
        return true;
    }
    return super.onKeyDown(keyCode, event);
  }

How to get the combination done here '&&' doesn't work?

TheDevMan
  • 5,914
  • 12
  • 74
  • 144

1 Answers1

-1

I don't understand programming under android, but I see it uses Java classes, so try this

public class BitKeys implements KeyListener {

    private BitSet keyBits = new BitSet(256);

    @Override
    public void keyPressed(final KeyEvent event) {
        int keyCode = event.getKeyCode();
        keyBits.set(keyCode);
    }

    @Override
    public void keyReleased(final KeyEvent event) {
        int keyCode = event.getKeyCode();
        keyBits.clear(keyCode);
    }

    @Override
    public void keyTyped(final KeyEvent event) {
        // don't care
    }

    public boolean isKeyPressed(final int keyCode) {
        return keyBits.get(keyCode);
    }

}

I found this here : handle multiple key presses ignoring repeated key

Community
  • 1
  • 1