Help Center

Local Navigation

Respond when a BlackBerry device user presses a volume key

  1. Import the required classes.
    import net.rim.device.api.ui.Screen;
    import net.rim.device.api.system.Characters;
  2. Create a class that extends the Screen class.
  3. Override Screen.keyControl().
    protected boolean keyControl(char c, int status, int time) {
  4. Identify the volume key that the BlackBerry device user changes.
    if (c == Characters.CONTROL_VOLUME_UP) {
    } else if (c == Characters.CONTROL_VOLUME_DOWN) {
    }
    Note: In the net.rim.device.api.media.MediaKeyListener class, the keyDown(), keyRepeat(), and keyUp() methods are invoked with Keypad.KEY_VOLUME_UP and Keypad.KEY_VOLUME_DOWN, which proves finer-grain control compared to using keyChar().

Was this information helpful? Send us your comments.