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
Highlighted
Developer
Posts: 77
Registered: ‎06-03-2009
My Device: Not Specified

Invoking a keypad event when device is locked

Can someone confirm that invoking an event is not possible  when device is locked.

 

I'm trying to invoke a keypad event when the blackberry flip is flipped, it works on simulator but not on device:

 

 

Timer timer = new Timer();
		TimerTask timerTask = new TimerTask()
		{
			public void run() {		
					//do some task
				if (Sensor.isSupported(Sensor.FLIP))
				{
					int state = Sensor.getState(Sensor.FLIP);
					if (state == Sensor.STATE_FLIP_CLOSED)
					{
						EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_DOWN, (char)Keypad.KEY_CONVENIENCE_2,
								KeypadListener.STATUS_NOT_FROM_KEYPAD
										));
						EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_UP, (char)Keypad.KEY_CONVENIENCE_2,
								KeypadListener.STATUS_NOT_FROM_KEYPAD
										));
					}
				}
			}
		};
		timer.scheduleAtFixedRate(timerTask, 0, 30000);

 

 

is the device get locked when the flip is closed?

is there other way which works to press a key programmatically when the device is locked?

Timer timer = new Timer();
        TimerTask timerTask = new TimerTask()
        {
            public void run() {        
                    //do some task
                if (Sensor.isSupported(Sensor.FLIP))
                {
                    int state = Sensor.getState(Sensor.FLIP);
                    if (state == Sensor.STATE_FLIP_CLOSED)
                    {
                        EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_DOWN, (char)Keypad.KEY_CONVENIENCE_2,
                                KeypadListener.STATUS_NOT_FROM_KEYPAD
                                        ));
                        EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_UP, (char)Keypad.KEY_CONVENIENCE_2,
                                KeypadListener.STATUS_NOT_FROM_KEYPAD
                                        ));
                    }
                }
            }
        };
        timer.scheduleAtFixedRate(timerTask, 0,
Timer timer = new Timer();
		TimerTask timerTask = new TimerTask()
		{
			public void run() {		
					//do some task
				if (Sensor.isSupported(Sensor.FLIP))
				{
					int state = Sensor.getState(Sensor.FLIP);
					if (state == Sensor.STATE_FLIP_CLOSED)
					{
						EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_DOWN, (char)Keypad.KEY_CONVENIENCE_2,
								KeypadListener.STATUS_NOT_FROM_KEYPAD
										));
						EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyEvent.KEY_UP, (char)Keypad.KEY_CONVENIENCE_2,
								KeypadListener.STATUS_NOT_FROM_KEYPAD
										));
					}
				}
			}
		};
		timer.scheduleAtFixedRate(timerTask, 0, 30000);

 

30000);