How do I get the volume up and down buttons?

I know KeyCode.ESC is the back button.
But how do I can the volume up and down buttons?
I’v noticed that while in Unity’s game, the volume buttons will make no changes in the volume, they just won’t do a thing.
So I guess if this is canceled, there got to be a keycode for it right?
I’m using Unity5.1.2

Anyone?..

No one knows? no ***** way!

Vol up and down are controlled by the OS. Its not implemented in Unity. What you can use is a Android Plugin that u build for yourself.

Here is the Android Code for that:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (action == KeyEvent.ACTION_DOWN) {
                //TODO
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                //TODO
            }
            return true;
        default:
            return super.dispatchKeyEvent(event);
        }
    }

If this is controlled by the OS why isn’t it work when I try to change the volume with game built with Unity5.1.2? If Unity blocks it, it better give access to it isn’t it?
And how exactly do I make the plugin that uses this code?

1 Like

Anyone figure this out? :frowning:

1 Like

Unity shouldn’t consume volume up/volume down events as far as I can tell. Please provide more information:

  • what Unity version are you using?
  • if you exit your application and then press volume up/volume down, and then get back to your application, does the sound changes then?

Anyway to detect whether the user wants louder music or otherwise in Unity?

AudioListener.volume value does not change if the player presses volume up or down buttons.

you can check the native binding in unity’s user manual

it only java code, not use for unity

I’m also interested in how to detect when the volume up button is pressed. I have a remote shutter control for phone cameras that basically sends a “volume up” event via Bluetooth and I want to detect the ON/OFF status of that button in a Unity script on Windows. Is that possible and if yes, how?

Were you able to detect the volume buttons?

No, I used a key redirection utility to redirect to a key that Unity recognises.