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
New Contributor
Posts: 4
Registered: ‎07-13-2011
My Device: Blackberry Torch 9800
My Carrier: TIGO

Monitor Phone Call Duration

Hi..!

I need to know how can I get the current call time from a outgoing call, actually I'm using phoneCall.getElapsedTime() but it  gets the time only once. 

 

What I need is: When call time reaches 30 seconds, show a message...!!

Please help me...

Thanks in advance.

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

Re: Monitor Phone Call Duration

welcome to the support forums.

you can use the
http://www.blackberry.com/developers/docs/6.0.0api/net/rim/blackberry/api/phone/PhoneListener.html
class to get notifications about call events.
use a TimerTask (for example) and start it in the callConnected call with 30s wait time.

please note that code in a phonelistener does run inside the phone application, not your own. use global events to send the event to your own app (for example).
----------------------------------------------------------
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
New Contributor
Posts: 4
Registered: ‎07-13-2011
My Device: Blackberry Torch 9800
My Carrier: TIGO

Re: Monitor Phone Call Duration

Thanks for your answer... I have used a TimerTask as you suggested but when it fires the simulator throws an exception.

would be possible for you to give me an example?
Thanks again...
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Monitor Phone Call Duration

and the exception would be?

i don't have a sample for this, and before i write code for you to copy i rather let you copy code to a post here to correct.
----------------------------------------------------------
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
New Contributor
Posts: 4
Registered: ‎07-13-2011
My Device: Blackberry Torch 9800
My Carrier: TIGO

Re: Monitor Phone Call Duration

here is what I have:

 

public void callConnected(int callId) {

int delay = 5000;   // delay for 5 sec

int period = 1000;  // repeat every sec.          

Timer timer = new Timer();


           timer.scheduleAtFixedRate(new TimerTask() {

                   public void run() {                    

Status.show("Time is Over..!", 2000);

                   }

               }, delay, period);

The exception is

JVM Error 10

Uncaught Runtime Exceptio

Thanks..

Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Monitor Phone Call Duration

When you get an exception like this, I recommend getting the detail text from the Exception.  IllegalState is a very general exception and the detail message will tie the problem down.  You could just run this in the debugger or do something like:

 

try {

Status.show(...)

} catch (Exception e) {

System.out.println(e.toString());

}

 

IN this case, I believe that callConnected(..) is actually invoked in the background (off the Event Thread, and since Status.show requires the event Thread, this will give you the IllegalState.

 

To get round this problem, you can just use something like

UiApplication.getUiApplication().invokeLater(new Runnable()

public void run() {

Status.show(..)

}

});

 

Or use one of the other methods to get the Event Lock.

 

That said, I would encourage you to take careful note of Simon's suggestion regarding not running in the Phone Application.  The code you are running here will run in the Phone Application.  if you break it, you might have users whose phone stops working.  Running the checking processing in your own Application with notifications sent using GlobalEvents from the phone is safer.  More work of course.  Whether this is worthwhile or not depends on where you are going with this app.

 

One final thing, are you sure you want to initiate a Status screen that will display for 2 seconds, every second - There will be times when you have 2 Status screens on show which seems a bit redundant.