Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _
Accepted Solution

Listener of the Volume buttons and light switch off & on

I want to make tha background applications and i like to add the listener for the Volume buttons and light switch off & on. Please help me how can i do this.

 

Thanks in advance.

Please use plain text.
Developer
simon_hain
Posts: 16,093
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Listener of the Volume buttons and light switch off & on

i forgot which keys could be intercepted in the background. if you add a keyDown method in your mainscreen (or another class implementing keylistener) you should be able to determine which keys are logged in the background.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Listener of the Volume buttons and light switch off & on

It is possible to add a listener for the volume buttons that works when the app is in the background.

 

I wasn't aware of a key that turns the display off and on. 

Please use plain text.
Developer
ajaysainsgvu
Posts: 242
Registered: ‎02-19-2013
My Device: 9500
My Carrier: _

Re: Listener of the Volume buttons and light switch off & on

[ Edited ]

Thanks peter & simon. Its helped for the my requirement.

 

public MyApp() {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new MyScreen());
        addKeyListener(new ShortcutHandler());
    }

    private class ShortcutHandler implements KeyListener {

        public boolean keyChar(char key, int status, int time) {
            return false;
        }

        public boolean keyDown(int keycode, int time) {
            if (Keypad.KEY_VOLUME_DOWN == Keypad.key(keycode)) {
                return true;
            } else if(Keypad.KEY_VOLUME_UP == Keypad.key(keycode)) {
                return true;
            } else if(Keypad.KEY_LOCK == Keypad.key(keycode)) {
                return true;
            }
            //let the system to pass the event to another listener.
            return false;
        }

        public boolean keyRepeat(int keycode, int time) {
            return false;
        }

        public boolean keyStatus(int keycode, int time) {
            return false;
        }

        public boolean keyUp(int keycode, int time) {
            return false;
        }

    }

Please use plain text.