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
Trusted Contributor
Davidf65
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

how to get the total duration of a call?

[ Edited ]

Hi, I want to get the total duration of a call from the time a user answers it till he/she hangs up. How could this be done?

I've tried several different things but in vain. 

the code is as follows:

public void callConnected(int callId){

 

start = System.currentTimeMillis();

 

}

 

public void callDisconnected(int callId){

end = System.currentTimeMillis();

 

totalTime = (end-start)/1000;

 

String time = Long.toString(totalTime)

}

 

 

Unfortunately, this is giving me a wrong output, for e.g. if the total call duration was 10 seconds, I'm getting some weird output like 26, etc.

How could this be done effectively?

Thanks.

 

David

 

David

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: how to get the total duration of a call?

This info is already in the PhoneLog.

 

Any reason why you don't just get it there?

 

Please use plain text.
Trusted Contributor
Davidf65
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

Re: how to get the total duration of a call?

well yes, this info is picked up during a 3 way conference call. I need to get this bit of information when the call gets connected to the 3rd user

Thanks

 

David

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: how to get the total duration of a call?

if it is a native conference the next user would trigger http://www.blackberry.com/developers/docs/7.1.0api/net/rim/blackberry/api/phone/PhoneListener.html#c... i think.
----------------------------------------------------------
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.
Trusted Contributor
Davidf65
Posts: 151
Registered: ‎07-20-2010
My Device: Not Specified

Re: how to get the total duration of a call?

Thanks Simon I'm using an AbstractPhoneListener but why is the System.currentTimeMillis giving me wrong values? I just did a call that lasted 10 seconds, but the final output I got after running the above routine is 211.054 which is like totally weird lol

 

David

Please use plain text.
Developer
simon_hain
Posts: 15,874
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: how to get the total duration of a call?

how do you store the time?
check the values of the long variables in the debugger and calculate the differentce on the PC, is it correct there?
----------------------------------------------------------
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.
Developer
pankajace12
Posts: 192
Registered: ‎04-30-2011
My Device: Software
My Carrier: Airtel

Re: how to get the total duration of a call?

Hi David,

 

Let try this one, may be it will help you.

 

static String start="";

static String end="";

 

public void callConnected(int callId){

 

start = getTime();

 System.out.println("Starting time : -> " + start);

}

 

public void callDisconnected(int callId){

 

end = getTime();

System.out.println("Now : -> " + end);

String timeDiff = getTimediff(start,end)

}

public static String getTimediff(String now, String later)
	{
	
	StringBuffer sb = new StringBuffer();
	sb.append(Integer.parseInt(later.substring(0, 2))-Integer.parseInt(now.substring(0, 2))).
	append(":")
	.append(Integer.parseInt(later.substring(3, 5))-Integer.parseInt(now.substring(3, 5))).
	append(":")
	.append(Integer.parseInt(later.substring(6, 8))-Integer.parseInt(now.substring(6, 8)));
	
	return sb.toString();	
	}

 

 

 

public static String getTime()
	{
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		Calendar cal = Calendar.getInstance();
		return dateFormat.format(cal.getTime());
	}

 

Thanks

Pawan

 

Please use plain text.