2

I have a broadcast listener which looks for any outgoing call and then starts a service upon completion of an outgoing call. The thing is within the service, I need to try and fetch the last call duration. I try querying the CallLog.Calls.CONTENT_URI using the query,

Cursor s = r.query(android.provider.CallLog.Calls.CONTENT_URI, null, null, null,CallLog.Calls.DATE + " DESC");

What i'm looking for is only the duration of the last call. I tried both, s.moveToFirst(); and also s.moveToLast();. But somehow I'm not able to get the correct value corresponding to the duration of the last outgoing call. I try and obtain the duration as,

int duration=s.getColumnIndex(android.provider.CallLog.Calls.DURATION);
String Duration=s.getString(duration);

Am i missing out on something? How can i get the last call duration alone? Because the service is started only after an outgoing call I dont have to check for the call type here.

Renjith
  • 5,783
  • 9
  • 31
  • 42
user1043023
  • 31
  • 1
  • 6
  • In brief what i'm looking for here is, what should the sort order be when querying the database and also if the cursor should be moved to first or to the last in order to get the last call duration. – user1043023 Nov 01 '12 at 05:31

1 Answers1

1

add the field CallLog.Calls.DURATION to the array.

courtesy

and look at this tutorial

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95
  • I'm sorry but i don't get which array to add it to. The thing is using s.getColumnIndex(android.provider.CallLog.Calls.DURATION);, i'm getting the some duration value from the calllog database but then i want only the last call duration. – user1043023 Nov 01 '12 at 05:18