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: 155
Registered: ‎05-20-2009
My Device: Not Specified

How to handle Send Key events?

while pressing green button I want to invoke my application.

How to call my application after user enters a number from keypad in BB device, Below is my code.....Plz suggest me.

 

public class SampleKeypad extends UiApplication implements KeyListener { public static String tf="1802107"; public static void main(String[] args) { SampleKeypad theApp = new SampleKeypad(); theApp.enterEventDispatcher(); } public SampleKeypad() { //pushScreen(new Express()); } public boolean keyDown(int keycode, int time) { System.out.println("Inside KeyDown Method..."); switch(Keypad.key(keycode)) { case Keypad.KEY_END: System.out.println("Key_END"); break; case Keypad.KEY_SEND: System.out.println("Key_SEND");

// Calling for TollFree Number.....

Ui.getUiEngine().pushScreen(new Express()); break; } return true; } public boolean keyUp(int keycode, int time) { // TODO Auto-generated method stub return true; } public boolean keyRepeat(int keycode, int time) { // TODO Auto-generated method stub return true; } public boolean keyStatus(int keycode, int time) { // TODO Auto-generated method stub return true; } public boolean keyChar(char key, int status, int time) { // TODO Auto-generated method stub return true; } public void deactivate() { System.exit(0); } } class Express extends MainScreen { public static String str; public static String phno; public static String phNumber; public static String tf="1802107"; public Express() { super();

PhoneArguments call = new PhoneArguments(PhoneArguments.ARG_CALL, tf); Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, call); } public boolean onClose() { int i= Dialog.ask(Dialog.D_YES_NO,"Are you sure you want to quit !"); if(i>0 && i != -1 ) { System.exit(0); return true; } return false; } /*public boolean keyChar(char key, int status, int time) { //intercept the ESC key - exit the app on its receipt boolean retval = false; switch (key) { case Characters.ESCAPE: onClose(); retval = true; break; } return retval; }*/ }

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to handle Send Key events?

What is happening when you push the screen from your application when the send key is pressed. Please note, only the application which is in foreground is able to get the key input.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 155
Registered: ‎05-20-2009
My Device: Not Specified

Re: How to handle Send Key events?

In my application, when I am pressing send key....Default call information screen is displaying.

 

Plz send me the sample code if u have and plz suggest me .

 

 

Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to handle Send Key events?

I am not quite sure what exactly you are trying to do but... let me make a guess or two.

 

1) You want your application to be in the background and  activate when user presses the SEND key

 (assumption derived from your original post)

2) You want to capture the green (SEND) key in your application

 (assumption derived from BBdeveloper's reply and your reply to his statement-question)

 

Answer(s):

 

First of all, BBdeveloper's post gave you a hint that your screen has to be in the foreground to be able to recieve key events.

Your application implemetns keyListener which will never 'hear' anything from the system.

 

You have to push your screen first and then the listener will be active (but in that case there is no need to explicitely implement the interface because the Screen class already implements it)

 

In short:

 

public boolean keyDown(int keycode, int time)

{

System.out.println("Inside KeyDown Method...");

switch(Keypad.key(keycode))

{

case Keypad.KEY_END:

System.out.println("Key_END");

return true; // consume the END click

case Keypad.KEY_SEND:

System.out.println("Key_SEND");

// Calling for TollFree Number.....

// Invoke call making procedures

return true; // consume the SEND click

}

//return true; // consume the click -> any (non control) click in this case

return super.keyDown(keycode, time); // let it go

}

 must be inside the Express class not in the SampleKeypad.

 

and, of course, the Express screen MUST be pushed on top of the screen stack (otherwise it will not receive key events).

 

 

 

 

 

 

 

 



"Listen carefully, I shall say this only once"
Developer
Posts: 155
Registered: ‎05-20-2009
My Device: Not Specified

Re: How to handle Send Key events?

How to invoke my custom application when user dials a number from keypad ,i.e. when user dials a number for example 9930565658 and pressess Green button it should invoke my custom application.

 

How to achieve this...plz help me.

Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to handle Send Key events?

Hmmm.

The only way I see it doable is to implement PhoneListener and react on callInitiated() event.

 

But, unfortunately a call will already be in the process of calling, so you should probably terminate it (maybe by injecting the END key ?) if you want to be the one making the call.

 



"Listen carefully, I shall say this only once"
Developer
Posts: 155
Registered: ‎05-20-2009
My Device: Not Specified

Re: How to handle Send Key events?

Hi,Thanks for your reply...

 

I want to invoke my application ( i.e, already there in device...) whenever user presses the green button.

 

For example...in a BB device,

 

1) user entered a number like..+919930565658 through keypad

 

2) after entering the number user presses the Green button...

 

3) after pressing the green button...I want to invoke my application without clicking the application icon..

 

 

Could you plz help me out regarding this....without clicking application icon .....I want to invoke my application..whenver user presses the green button.

Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to handle Send Key events?

As I already explained, you can do that but not in a clean way.

 

1) create a system autostarted application

2)  the application must implement and register a phoneListener

(see phoneListener implementation)

3)  inside the callInitiated you have to terminate the outgoing call

 

// Outbound call initiated by the handheld public void callInitiated(int callid) { showPhoneEvent("Call Initiated", callid);

// inject the end key here, hoping it will be quick enough for the user not to notice anything

  // push your application screen on top

// do whatever you like (bud try not to block the event thread here)

}

 

 

4) do whatever you like 

 

 

I guess you will have to play arround for some time to make the transition between native dialer and your application smoth, but it can be done.

 

P.S. There is no other way to "intercept" the SEND (a.k.a. green) key pressed action from the main screen. Only the topmost screen can receive key pressed events.



"Listen carefully, I shall say this only once"
Developer
Posts: 155
Registered: ‎05-20-2009
My Device: Not Specified

Re: How to handle Send Key events?

How to create a system autostarted application, it will run while pressing the green key.

whatever u said I has developed some sample example..but I am getting some error like cannot find symbol showPhoneEvent Below is my code ...plz check and suggest me.

 

public class SampleKeypad extends UiApplication { public static String tf="1802107"; public static void main(String[] args) { SampleKeypad theApp = new SampleKeypad(); theApp.enterEventDispatcher(); } public SampleKeypad() { pushScreen(new Express()); } } class Express extends MainScreen implements PhoneListener { public static String str; public static String phno; public static String phNumber; public static AutoTextEditField Num; public static ButtonField dialButton; public static String tf="1802107"; public static String regNum ="911066464646"; public static String pinNum ="8308"; public static String result; public String phone; public static PersistentObject mystoreNum = PersistentStore.getPersistentObject(0xd6dc779737bcc266L); public Express() { super(); LabelField title = new LabelField("Welcome",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); //EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, ((char)Keypad.KEY_SEND), KeypadListener.STATUS_NOT_FROM_KEYPAD,100); // EventInjector.invokeEvent(ev); } public void callConnected(int callId) { System.out.println("Inside Call Connected..."); try { PhoneCall pcall=Phone.getCall(callId); if(pcall.isOutgoing()) { this.callAnswered(callId); } } catch(Exception e) { System.out.println("Exception inside Call Connected try block...:"); } } public void callAdded(int callId) { // TODO Auto-generated method stub } public void callAnswered(int callId) { System.out.println("Inside Call Answered..."); try { Thread.sleep(200); } catch(Exception e) { System.out.println("Exception After TollFree call...."); } //PhoneCall pcall=Phone.getActiveCall(); try { result = regNum+pinNum; System.out.println("********** Registration and Pin Number result **********:"+result); PhoneCall pcall=Phone.getActiveCall(); System.out.println("Before DTMF Tones...."); pcall.sendDTMFTones(result); System.out.println("After DTMF Tones...."); //Phone.removePhoneListener(this); } catch(Exception e) { System.out.println("After First Dtmf Tones"); } try { Thread.sleep(500); } catch(Exception e) { System.out.println("After Second pause..."); } } public void callConferenceCallEstablished(int callId) { // TODO Auto-generated method stub } public void callDirectConnectConnected(int callId) { // TODO Auto-generated method stub } public void callDirectConnectDisconnected(int callId) { // TODO Auto-generated method stub } public void callDisconnected(int callId) { System.out.println("Inside callDisconnected..."); Phone.removePhoneListener(this); UiApplication.getUiApplication().requestBackground(); } public void callEndedByUser(int callId) { System.out.println("Inside callEndedByUser..."); Phone.removePhoneListener(this); UiApplication.getUiApplication().requestBackground(); } public void callFailed(int callId, int pReason) { // TODO Auto-generated method stub } public void callHeld(int callId) { // TODO Auto-generated method stub } public void callIncoming(int callId) { // TODO Auto-generated method stub } public void callInitiated(int callId) { System.out.println("Inside Call Initiated..."); PhoneCall call = Phone.getCall(callId); System.out.println("Outgoing number is :"+call.getDisplayPhoneNumber()); showPhoneEvent("Call Initiated", callId); } public void callRemoved(int callId) { // TODO Auto-generated method stub } public void callResumed(int callId) { // TODO Auto-generated method stub } public void callWaiting(int callId) { // TODO Auto-generated method stub } public void conferenceCallDisconnected(int callId) { // TODO Auto-generated method stub } public boolean onClose() { int i= Dialog.ask(Dialog.D_YES_NO,"Are you sure you want to quit !"); if(i>0 && i != -1) { System.exit(0); return true; } return false; } public boolean keyDown(int keycode, int time) { System.out.println("Inside KeyDown Method..."); switch (keycode) { case Keypad.KEY_END: //return true; // break; case Keypad.KEY_SEND: Dialog.alert("Bye..."); return true; //break; } return super.keyDown(keycode, time); } }

 

Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: How to handle Send Key events?

You are heading in a good direction.

 

For system module please check the forums (ok here's a hint).

 

The code snippet I provided was an example one. 

Of course the compiler complains because the showPhoneEvent() method call was a copy-paste from the KB. 

 

Instead of calling this method you must try to end the active call:

 

 

public void callInitiated(int callId) { System.out.println("Inside Call Initiated..."); PhoneCall call = Phone.getCall(callId); System.out.println("Outgoing number is :"+call.getDisplayPhoneNumber()); EventInjector.KeyCodeEvent ev = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, ((char)Keypad.KEY_SEND), KeypadListener.STATUS_NOT_FROM_KEYPAD,100); EventInjector.invokeEvent(ev); }

 

After you get the callDisconnected (or callFailed) event, you can try to dial any number you need like this:

 

 

PhoneArguments phoneCallArgs = new PhoneArguments(PhoneArguments.ARG_CALL, "+10555444333", false); Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, phoneCallArgs);

 

 

 

The rest is up to you to discover Smiley Wink

 



"Listen carefully, I shall say this only once"