title: How I can get the contact name from the android (CallLog.Calls.CONTENT_URI) table?
body: <p>I am new to android and working on an application where I need the all the outgoing call logs, number, call duration and Name of the contact. So my question is can I get the Name and number of the outgoing call for the CallLog.Calls.CONTENT_URI table of android system or I need to read it from separate table and map it. Below is my code. Thanks in advance.</p>
  
  <pre>
  private String getCallDetails() {
  
          StringBuffer sb = new StringBuffer();
          // Cursor managedCursor =
          // getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
          // null, null, null);
  
          Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, CallLog.Calls.DATE + ">?",
                  new String[] { String.valueOf("1451586601000") }, CallLog.Calls.NUMBER + " asc");
          int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
          int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
          int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
          int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
          int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
          // int geoCodeColumn =
          // managedCursor.getColumnIndex(CallLog.Calls.GEOCODED_LOCATION);
  
          // sb.append("Call Details :");
          while (managedCursor.moveToNext()) {
              String phNumber = managedCursor.getString(number);
              String callType = managedCursor.getString(type);
              String callDate = managedCursor.getString(date);
              String callerName = managedCursor.getString(name);
              // long calldate_timeStamp= Long.parseLong(callDate);
              // long temp_time = 1451586601000L;
              // if(calldate_timeStamp>temp_time){
              // String geoCode = managedCursor.getString(geoCodeColumn);
              Date callDayTime = new Date(Long.valueOf(callDate));
              String callDuration = managedCursor.getString(duration);
              String dir = null;
              int dircode = Integer.parseInt(callType);
              switch (dircode) {
              case CallLog.Calls.OUTGOING_TYPE:
                  dir = "OUTGOING";
                  int total_call_duration = Integer.parseInt(callDuration);
                  total_time = total_time + total_call_duration;
                  MyContact dialedContact = new MyContact();
                  dialedContact.setPhoneNumber(Long.parseLong(phNumber));
                  dialedContact.setCallDuration(Integer.parseInt(callDuration));
                  // dialedContact.se
                   sb.append("\nPhone Number:--- " + phNumber + " \nCallType:--- "
                   + dir + " \nCall Date:--- " + callDayTime
                   + " \nCall duration in sec :--- " + callDuration+ " \nGeocode: " );
                   sb.append("\n----------------------------------");
  
                  break;
  
              case CallLog.Calls.INCOMING_TYPE:
                  dir = "INCOMING";
                  break;
  
              case CallLog.Calls.MISSED_TYPE:
                  dir = "MISSED";
                  break;
              }
          }
  
          // }
          managedCursor.close();
      //  sb.append("" + total_time / 60);// call duration in minute
          return sb.toString();
  
      }
  </pre>