6

i would get outgoing call duration a call, I thought to get when the persone to the other side answer my call, but with PhoneStateListener we can get the state of a call, but PhoneStateListener changes state to CALL_STATE_OFFHOOK immediately when the outgoing call starts and not when the person to other side answers, so i can't get the effective time of call during a conversation. Any ideas to do this

Thanks in advance!

mardvd
  • 61
  • 1
  • 3
  • would it be possible to detect when the call starts, record the time on your own, and then at later times compute the duration of time that passed since the start of the call? You might have to do some trickery to be resilient to clock change or something, but in theory something like this may be possible. (I didn't try this, which is why I didn't make it an answer). – Tom Apr 29 '11 at 12:52
  • @Tom it is possible , but sometimes it takes some time till you get the intent of having the call being started/answered. – android developer Sep 30 '13 at 11:36
  • 1
    @mardvd did you solve this problem? would also like to know the answer about incoming calls and not just outgoing calls. – android developer Sep 30 '13 at 11:39
  • @androiddeveloper Wait, how can you know when an outgoing call was answered? What intent are you talking about? I've been searching for a solution on this for some days now. – Edw590 Dec 24 '20 at 02:49
  • 1
    @DADi590 Sorry I think I wrote the opposite. Outgoing calls are the problematic ones. The only solution I've found is to actually replace the Phone app, but this is a huge amount of work – android developer Dec 24 '20 at 08:29
  • Oh.... damn. You gave me hope for a moment hahaha. About replacing the Phone app, I'm not sure if you need root or system permissions for that, but if you do, as of API 23 or 30 (don't remember now), you can use READ_PRECISE_CALL_STATE and know when a call actually starts and measure duration from that (from the start until it finishes). Though, I've been trying without any of those permissions (I have root and system perms, but I need to have a backup method, if it exists...). Also no idea how you still remember after 7 years, but cool hahaha. – Edw590 Dec 24 '20 at 13:36

1 Answers1

2

I think this is possible simply by spying on the call log. You can query the call log at the end of a call and the duration field will tell you what you want to know.

Here's a nice tutorial. Just add the field CallLog.Calls.DURATION to the array.

http://www.dcpagesapps.com/developer-resources/android/25-android-tutorial-call-logs

I hope this helps.

Emmanuel

Emmanuel
  • 16,791
  • 6
  • 48
  • 74
  • 2
    This is true, and I can confirm that this works, but it is *not* possible to determine the duration *during* the call, as the OP inquired. – Paul Lammertsma Mar 07 '11 at 09:55