0

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?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
devguy
  • 2,336
  • 5
  • 27
  • 31
  • Do you have access to UiEngine or UiApplication instances from your application? IE, does it extend UiApplication or communicate with a foreground app that can reference a UiApplication? – Ken Gentle Nov 21 '08 at 16:31
  • yes I can reference UiApplication. But, if possible, I'd like a solution that works in both cases...just in case... – devguy Nov 21 '08 at 17:08

3 Answers3

0

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) {
    }
}
Community
  • 1
  • 1
Maksym Gontar
  • 22,765
  • 10
  • 78
  • 114
0

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.

Anthony Rizk
  • 3,666
  • 20
  • 21
0

This should work:

UiApplication.getUiApplication().invokeLater(new Runnable(){
  public void run(){
    UiApplication.getActiveScreen().close();
  }
});
kozen
  • 509
  • 3
  • 5