黑莓 - 使用EventInjector忽略来电

时间:2011-09-06 16:41:01

标签: events blackberry call listener

大家好'我正在尝试在我的应用中使用EventInjector来自动关闭所有来电。我的MainScreen实现了PhoneListener。以下是我的代码

public void callIncoming(int callId) {
            requestForeground();
            final PhoneCall call = Phone.getCall(callId);  
            final String number = call.getDisplayPhoneNumber();  
            System.out.println(number);  
            EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent(  
                    KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_END, 0, 100);  
            EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent(  
                    KeyCodeEvent.KEY_UP, (char) Keypad.KEY_END, 0, 100);

            EventInjector.invokeEvent(pressEndKey);  
            EventInjector.invokeEvent(releaseEndKey);   
        }

此代码不起作用,换句话说无效。来电屏幕继续弹出,并且在采取行动之前不会消失。

1 个答案:

答案 0 :(得分:4)

检查此链接,它有效!

http://www.codinguru.com/2011/08/block-incoming-call-in-blackberry.html

public void callIncoming(int callId) {
        final PhoneCall call = Phone.getCall(callId);  
        final String number = call.getDisplayPhoneNumber();  
        System.out.println(number);  

        EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_END, 0, 100);  
        EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_UP, (char) Keypad.KEY_END, 0, 100);  

        try {  
            Thread.sleep(1000);  
        } catch (InterruptedException e) {  
            // TODO Auto-generated catch block  
        e.printStackTrace();  
        }  
        EventInjector.invokeEvent(pressEndKey);  
        EventInjector.invokeEvent(releaseEndKey);  
    }