Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to access call logs in android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 382
    Comment on it

    Easiest way to get the call duration of last call in android device is by using CallLog.Calls. Content Provider CallLog.Calls is used to provide access to the call logs data. CallLog.Calls provides interface between data and the code, also it contain information about the incoming, outgoing and missed calls.

    Cursor managedCursor = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, CallLog.Calls.DATE );
    
            number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
            type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
            date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
            duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
    
            while (managedCursor.moveToNext()) {
    
                phNumber = managedCursor.getString(number);
                callType = managedCursor.getString(type);
                callDate = managedCursor.getString(date);
                Date callDayTime = new Date(Long.valueOf(callDate));
                callDuration = managedCursor.getString(duration);
                String dir = null;
    
            int dircode = Integer.parseInt(callType);
                switch (dircode) {
                    case CallLog.Calls.OUTGOING_TYPE:
                        dir = "OUTGOING";
                        break;
    
                    case CallLog.Calls.INCOMING_TYPE:
                        dir = "INCOMING";
                        break;
    
                    case CallLog.Calls.MISSED_TYPE:
                        dir = "MISSED";
                        break;
                }
                tvCall.setText("Phone Number:--- " + phNumber +
                        " \nCall Type:--- " + dir +
                        " \nCall Date:--- " + callDayTime +
                        " \nCall duration in sec :--- " + callDuration);
    
            }
            managedCursor.close();
    

    don't forget to add permissions in AdroidManifiest.xml file

    <uses-permission android:name="android.permission.READ_CALL_LOG" />
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: