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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 363
    Comment on it

    Android provides Cursor interface to get all calls logs. A cursor interface provides read-write to get the result set by database query.

    Here stringOrder query will access phone calls date wise in desc order. Cursor loader basically perform queries the ContentResolver and returns a Cursor.

     private void getCallsHistory() {
    
      StringBuffer stringBuffer = new StringBuffer();
      String stringOrder = android.provider.CallLog.Calls.DATE + " DESC";
    
      Cursor cursor = cursorLoader(CallLog.Calls.CONTENT_URI, null,
        null, null, strOrder);
    
      int num = cursor.getColumnIndex(CallLog.Calls.NUMBER);
      int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
      int date = cursor.getColumnIndex(CallLog.Calls.DATE);
      int dur = cursor.getColumnIndex(CallLog.Calls.DURATION);
    
      stringBuffer.append("All call logs :");
    
      while (cursor.moveToNext()) {
       String callNumber = managedCursor.getString(number);
       String callType = managedCursor.getString(type);
       String callDate = managedCursor.getString(date);
       Date callDate = new Date(Long.valueOf(strcallDate));
       String callDuration = managedCursor.getString(duration);
       String callType = null;
       int code = Integer.parseInt(callTypeCode);
       switch (code) {
       case CallLog.Calls.OUTGOING_TYPE:
        callType = "Outgoing";
        break;
       case CallLog.Calls.INCOMING_TYPE:
        callType = "Incoming";
        break;
       case CallLog.Calls.MISSED_TYPE:
        callType = "Missed";
        break;
       }
       sb.append("\ncalling Number:--- " + num + " \nCall Type:--- "
         + callType + " \nCall Date:--- " + callDate
         + " \nCall duration in sec :--- " + callDuration);
       sb.append("\n----------------------------------");
      }
      cursor.close();
     }
    

 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: