t3hcakeman
t3hcakeman

Reputation: 2339

Hold down volume button on android?

I'm trying to make an app where if you hold down the volume down button, an action occurs. How would I go abouts doing this? I'm a noob for java, so an example would be excellent.

Upvotes: 0

Views: 1220

Answers (1)

Maurice Lam
Maurice Lam

Reputation: 354

Override onKeyLongPress in your Activity

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 
    {
        // to your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

how to capture long press volume down key in android?

Upvotes: 3

Related Questions