I do something like mp3 player. It is necessary, when the keyboard is locked, to track down a long press on the volume buttons, one would switch music. How can this be implemented?

    1 answer 1

    We'll have to catch the time when the volume button is pressed in milliseconds!

    Tracking algorithm:

    Button pressed for the first time!

    (1) set the flag of the first click (2) got the time.

    The button is pressed more (for example) 2000 ms, proceed!

    The button was released before 2000 ms: (1) reset the flag of the first press.

    Use: onTouch (View v, MotionEvent event) {}