Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Using EventInjector to ignore incoming calls

Hello everyone. I'm trying to use EventInjector to intercept and end an incoming call in incomingCall(). My MainScreen implements PhoneListener and I'm overriding incomingCall() like this:

 

public void callIncoming(int callId)  
		{   
		EventInjector.invokeEvent( new EventInjector.KeyCodeEvent( EventInjector.KeyCodeEvent.KEY_DOWN , (char)Keypad.KEY_END, 100));
		EventInjector.invokeEvent( new EventInjector.KeyCodeEvent( EventInjector.KeyCodeEvent.KEY_UP , (char)Keypad.KEY_END, 100));	  
		}

 This of course isn't working. What am I doing wrong? I know there are some apps that will automatically ignore incoming calls. Is this how they do it? I'm developing for OS 5.

Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Using EventInjector to ignore incoming calls

Got it working. In the constructor of my class that implements PhoneListener: Silly me. I had to add Phone.addPhoneListener(this); to the constructor.

then in the callIncoming(

EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_END,  100);  
	        EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent( KeyCodeEvent.KEY_UP, (char) Keypad.KEY_END,  100);  
	   
	        try {  
	            Thread.sleep(1000);  
	        } catch (InterruptedException e) {  
	            // TODO Auto-generated catch block  
	        e.printStackTrace();  
	        }  
	        EventInjector.invokeEvent(pressEndKey);  
	        EventInjector.invokeEvent(releaseEndKey);  

 

 

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Using EventInjector to ignore incoming calls

just as a sidenote, as you got it working:

the phonelistener runs in the context of the phone application.
if you use Thread.sleep without spawning an own thread first you block the phone application.
worst case (saw it in the wild) would be that the phone app is terminated (it will be restarted by a watchdog process).

to avoid this i move the context into my own application using global events (in callincoming, for example, i only fire an event with a custom id).
use a thread if you want to use sleep or do lengthy processing.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Using EventInjector to ignore incoming calls

Thanks simon that's very good to know. 

New Contributor
Posts: 4
Registered: ‎01-24-2011
My Device: Not Specified

Re: Using EventInjector to ignore incoming calls

I have followed your suggestion but am getting the below exception net.rim.device.api.system.ControlledAccessException below is my log: ##########callIncoming() Start######### number:Work ?+918121591725 MSM[36]: Stream 21003 watermark remain=4117 avail=61419 MSM[36]: Stream Streaming session: 21003 wrote 18139 MSM[36]: Stream Streaming session: 21003 wrote 41253 MSM[36]: Stream Streaming session: 21003 wrote 2186 [STREAM] write [handle: 21003] no bytes written MSM[36]: Stream Streaming session: 21003 wrote 0 **********Exception:net.rim.device.api.system.ControlledAccessException please give me some suggestion
Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Using EventInjector to ignore incoming calls

please open an own thread for your issue.
controlledaccess usually means that your application does not have the correct permissions.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 442
Registered: ‎08-02-2010
My Device: Z10
My Carrier: Telus

Re: Using EventInjector to ignore incoming calls

In the sim you have to go into the sim's options and set permissions.
Contributor
Posts: 31
Registered: ‎05-18-2010
My Device: 9550
My Carrier: Blackberry

Re: Using EventInjector to ignore incoming calls

Great thanks a lot