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
Posts: 235
Registered: ‎11-12-2008
My Device: Not Specified

How to get volume up and down key event

How to get  the event of volume up and down key,press event on my application programatically...

please help me with a piece of code...

Thanks in advance...

 

 

Developer
Posts: 374
Registered: ‎04-07-2010
My Device: Bold 9000
My Carrier: Airtel

Re: How to get volume up and down key event

Hi,

Use event injector... to press a keypad button....

Try this:  Hope it helps...

 

 

 UiApplication.getUiApplication().invokeLater(new Runnable() {
                         public void run() {
                               
                               
                             
                                ApplicationPermissions permissions = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
                                          if (permissions.getPermission(ApplicationPermissions.PERMISSION_EVENT_INJECTOR) == ApplicationPermissions.VALUE_ALLOW) {
                                              
                                             EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN,(char) Keypad.KEY_VOLUME_UP, KeypadListener.STATUS_NOT_FROM_KEYPAD, 100));
                                            EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP,(char) Keypad.KEY_VOLUME_UP, KeypadListener.STATUS_NOT_FROM_KEYPAD, 100));
                                                }
                                   }             
              });  

 

 

Press the Like button (Thumb up) on the left side to thank and
please mark the Thread as solved if its solved...
K.S
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to get volume up and down key event

Rather than injecting the key, I get the impression the OP wanted to detect the key being pressed. 

 

I have an application that detects this by overriding

 

    public boolean keyDown(int keycode, int time) {

 

and does this:

int key = Keypad.key(keycode);

if ( Keypad.KEY_VOLUME_DOWN == key ) ....

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: How to get volume up and down key event

you can also use keyControl() to catch them.

Developer
Posts: 216
Registered: ‎02-18-2010
My Device: 9350,8520
My Carrier: no

Re: How to get volume up and down key event

Yes you are right

 

 

protected boolean keyControl(char c, int status, int time) 
{
	if(c==Characters.CONTROL_VOLUME_DOWN)
	    Dialog.alert("down");

	if(c==Characters.CONTROL_VOLUME_UP)
	    Dialog.alert("up");

	return super.keyControl(c, status, time);
}