Dismiss a system dialog on BlackBerry
-
08-07-2019 - |
Question
I have a BlackBerry app running in the background that needs to know when a "Missed call" system dialog is brought up by the system, and programmatically close it without user intervention. How can I do that?
I could actually almost know when the dialog is brought up, i.e. a little later I programmatically end the call...but how can I get a reference to the dialog, and close it?
Solution
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) {
}
}
OTHER TIPS
If you know the dialog is there, and is the topmost dialog, the EventInjector APIs might do it - net.rim.device.api.system.EventInjector. When you know the dialog is there, send a KeyEvent with an ESCAPE keycode. That API is usually locked out in most enterprise environments though...
Disclaimer: I haven't tried it myself, I'd be a little surprised if it worked, since that might mean you could also dismiss the 'Allow This Connection' dialog, which would be a security hole.
This should work:
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
UiApplication.getActiveScreen().close();
}
});