2011-09-06 79 views
1

大家好'我想在我的應用程序中使用EventInjector來自動關閉所有來電。我的主屏幕實現PhoneListener。以下是我的代碼黑莓 - 使用EventInjector忽略來電

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); 
     } 

此代碼不起作用,換句話說在其中沒有任何作用。來電屏幕繼續彈出,直到採取行動纔會消失。

+0

我不知道這是否會影響它,但你的應用程序有「輸入模擬」權限轉向允許? –

+0

是的,在模擬的IT策略中啓用了EventInjection – RapsFan1981

+0

您是否調試過它以確保它正在執行此代碼塊? – jprofitt

回答

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); 
    } 
+0

鏈接到一個私人博客。 –