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
simon_hain
Posts: 15,947
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Calling Application while Application in background

first, i would advise you not to execute any code in the phone listener method. move the context to your own application by using global events or the runtime store.

the phone listener executes within the phone application and can, worst case, kill it (will be restarted by a watchdog daemon though).

 

second, if you want to use sleep, use an own thread.

----------------------------------------------------------
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
Please use plain text.
Contributor
ichie
Posts: 22
Registered: ‎02-28-2010
My Device: BOLD 9700
My Carrier: Smart

Re: Calling Application while Application in background

Hi Simon,

 

I've changed my code to how I understand your suggestion:

 

1) Created a Class which extends the AbstractPhoneListener:

 

public class CustomPhoneListener extends AbstractPhoneListener {

	public void callInitiated(int callid) {
		ApplicationManager.getApplicationManager().postGlobalEvent(
				<insert long here>);
	}

}

 2) Implemented the GlobalListener on my main App:

 

public class HotKeyApp extends UiApplication implements GlobalEventListener {

	public HotKeyApp() {
		HotKeyScreen screen = new HotKeyScreen();
		pushScreen(screen);

		CustomPhoneListener listener = new CustomPhoneListener();
		Phone.addPhoneListener(listener);
		addGlobalEventListener(this);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		HotKeyApp app = new HotKeyApp();
		app.enterEventDispatcher();
	}

	public void stopCalling() {
		System.out.println("[HotKeyApp] callInitiated is called");
		PhoneCall call = Phone.getActiveCall();
		String number = trimPhoneNumber(call.getDisplayPhoneNumber());
		System.out.println("[HotKeyApp] number is " + number);

		if (number.equals("12")) {
			EndKeyPresser sleeper = new EndKeyPresser();
			sleeper.start();
		}
		System.out.println("[HotKeyApp] exiting callInitiated method");
	}

	public class EndKeyPresser extends Thread {
		public void run() {
			try {
				System.out
						.println("[HotKeyApp] Sleep for 100ms before pressing End Key");
				Thread.sleep(100);
				EventInjector.KeyCodeEvent pressEndKey = new EventInjector.KeyCodeEvent(
						EventInjector.KeyCodeEvent.KEY_DOWN,
						((char) Keypad.KEY_END),
						KeypadListener.STATUS_NOT_FROM_KEYPAD);
				System.out.println("[HotKeyApp] Press End Key");
				EventInjector.invokeEvent(pressEndKey);
				System.out.println("[HotKeyApp] End Key is pressed");

				System.out
						.println("[HotKeyApp] Sleep for 100ms before releasing End Key");
				Thread.sleep(100);

				EventInjector.KeyCodeEvent releaseEndKey = new EventInjector.KeyCodeEvent(
						EventInjector.KeyCodeEvent.KEY_UP,
						((char) Keypad.KEY_END),
						KeypadListener.STATUS_NOT_FROM_KEYPAD);
				System.out.println("[HotKeyApp] Release End Key");
				EventInjector.invokeEvent(releaseEndKey);
				System.out.println("[HotKeyApp] End Key is Release");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public void eventOccurred(long guid, int arg1, int arg2, Object arg3,
			Object arg4) {
		if (guid == <insert long here>) {
			stopCalling();
		}
	}

}

 

But still the same thing happens. It stops when I try to invoke the EventInjector. It runs until this part of the code:

 

 

EventInjector.invokeEvent(pressEndKey);
System.out.println("[HotKeyApp] End Key is pressed");

 

 

Here an excerpt from the logs when I debugged using the device:

 

[HotKeyApp] callInitiated is called
[HotKeyApp] number is 12
[HotKeyApp] exiting callInitiated method
[HotKeyApp] Sleep for 100ms before pressing End Key
AR: setAudioMode 9
EV_CALL_INITIATED(1)
CC: CallName,1,"false",""
CC: CallName,1,"false",""
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"false","12"
[HotKeyApp] Press End Key
CC: Conn,1
[HotKeyApp] callInitiated is called
[HotKeyApp] number is 12
[HotKeyApp] exiting callInitiated method
[HotKeyApp] Sleep for 100ms before pressing End Key
EV_CALL_CONNECTED(1)
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"false","12"
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"true",""
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"false","12"
CC: CallName,1,"false",""
Phone lookup time 0
CC: CallName,1,"false",""
CC: CallName,1,"false",""
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"false","12"
RadioGetCallStatus(1).phoneNumber = 12
CC: GetCallNumber,1,"false","12"
[HotKeyApp] Press End Key

 

Any idea why this is the case?

 

Note: I am compiling at 4.6.

 

regards,

ichie 

Please use plain text.
Contributor
ichie
Posts: 22
Registered: ‎02-28-2010
My Device: BOLD 9700
My Carrier: Smart

Re: Calling Application while Application in background

Thanks to all who have spent their time answering to my query. I found the solution to my problem.

 

All that's needed is to set the Application Permission for Input Simulation to 'Allow' and that's it. There are two ways to get this done: 1) Manual Setting and 2) Programmatically asked for the permission of the user to set the permission to 'Allow.'

 

Manual Setting:

Go to Options > Applications. Select your application. Press menu and select Edit Permissions. Find Input Simulation and set 'Allow' as value.

 

Programmatically:

You may check this thread: http://supportforums.blackberry.com/t5/Java-Development/ApplicationPermissions-not-working-on-every-...

 

This would not automatically set the value to 'Allow.' It only opens up the Permissions screen automatically. The user still needs to accept the settings by saving them.

 

Regards,

ichie

Please use plain text.