Key press injection for device Close button looks like this:
KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, Characters.ESCAPE, 0);
inject.post();
Don't forget to set permissions for device release:
Options => Advanced Options => Applications => [Your Application] =>Edit Default permissions =>Interactions =>key stroke Injection
May be useful:
BlackBerry - Simulate a KeyPress event
Code sample:
class Scr extends MainScreen implements PhoneListener {
public Scr() {
Phone.addPhoneListener(this);
}
public boolean onClose() {
Phone.removePhoneListener(this);
return super.onClose();
}
public void callDisconnected(int callId) {
Timer timer = new Timer();
timer.schedule(new TimerTask(){public void run() {
KeyEvent event = new KeyEvent(KeyEvent.KEY_DOWN,
Characters.ESCAPE,
KeyListener.STATUS_NOT_FROM_KEYPAD);
event.post();
}}, 1000);
}
public void callAdded(int callId) {
}
public void callAnswered(int callId) {
}
public void callConferenceCallEstablished(int callId) {
}
public void callConnected(int callId) {
}
public void callDirectConnectConnected(int callId) {
}
public void callDirectConnectDisconnected(int callId) {
}
public void callEndedByUser(int callId) {
}
public void callFailed(int callId, int reason) {
}
public void callHeld(int callId) {
}
public void callIncoming(int callId) {
}
public void callInitiated(int callid) {
}
public void callRemoved(int callId) {
}
public void callResumed(int callId) {
}
public void callWaiting(int callid) {
}
public void conferenceCallDisconnected(int callId) {
}
}