I am looking for the easiest way to get the call duration of the last number dialed. So, for example, if I called my mom, as soon as I cut the call, a notification should appear.
I am trying to do the following, but the problem is that it comes with a full duration list. incoming, outgoing, missed.
How to do it:
I tried the following:
private void getCallDetails() { StringBuffer sb = new StringBuffer(); Cursor cur = getContentResolver().query( CallLog.Calls.CONTENT_URI,null, null,null, android.provider.CallLog.Calls.DATE + " DESC"); int number = cur.getColumnIndex( CallLog.Calls.NUMBER ); int duration = cur.getColumnIndex( CallLog.Calls.DURATION); sb.append( "Call Details : \n"); while ( cur.moveToNext() ) { String phNumber = cur.getString( number ); String callDuration = cur.getString( duration ); String dir = null; sb.append( "\nPhone Number:--- "+phNumber +" \nCall duration in sec :--- "+callDuration ); sb.append("\n----------------------------------"); } cur.close(); call.setText(sb); }
source share