5

This may be a silly question, I'm a bit of a noob. I was reading this post: How do I access call log for android?

and in the answer at the bottom of the code they have this line:

int type = Integer.parseInt(c.getString(c.getColumnIndex(CallLog.Calls.TYPE)));// for call type, Incoming or out going

I'm a little confused as to how the call type is stored, is it as a string or as an integer? The line of code shown makes me think its saved as a number, but in string format. Can anyone explain this to me?

Thanks, Matt

Community
  • 1
  • 1
Matt Harris
  • 3,496
  • 5
  • 32
  • 43

5 Answers5

9

The type is stored as integer. This is how I get a list of new missed calls:

cursor = cr.query(Uri.parse("content://call_log/calls"), null, "type = 3 AND new = 1", null, "date DESC");

Of course using the CallLog.Calls.MISSED_TYPE, INCOMING_TYPE and OUTGOING_TYPE constant would be better.

Pal Szasz
  • 2,954
  • 3
  • 20
  • 18
5

Here CallLog.Calls.TYPE gives you the field name in the database to fetch the info of call type which contains integer values to save the type of calls,though it might be a text field.

1 for incoming type

2 for missed type

3 for outgoing type

You just need to use them like android.provider.CallLog.Calls.MISSED_TYPE, android.provider.CallLog.Calls.INCOMING_TYPE and android.provider.CallLog.Calls.OUTGOING_TYPE only.

Hiral Vadodaria
  • 19,158
  • 5
  • 39
  • 56
3

Referring to the: http://developer.android.com/reference/android/provider/CallLog.Calls.html#INCOMING_TYPE

1 for incoming type

2 for outgoing type

3 for missed type

Michael Celey
  • 12,645
  • 6
  • 57
  • 62
3

use this method

private static String getCallDetails(Context context) {
    StringBuffer stringBuffer = new StringBuffer();
    Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI,
            null, null, null, CallLog.Calls.DATE + " DESC");
    int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
    int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
    int date = cursor.getColumnIndex(CallLog.Calls.DATE);
    int duration = cursor.getColumnIndex(CallLog.Calls.DURATION);       
    while (cursor.moveToNext()) {
        String phNumber = cursor.getString(number);
        String callType = cursor.getString(type);
        String callDate = cursor.getString(date);
        Date callDayTime = new Date(Long.valueOf(callDate));
        String callDuration = cursor.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;
        }
        stringBuffer.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- "
                + dir + " \nCall Date:--- " + callDayTime
                + " \nCall duration in sec :--- " + callDuration);
        stringBuffer.append("\n----------------------------------");
    }
    cursor.close();
    return stringBuffer.toString();
}
ingyesid
  • 2,864
  • 2
  • 23
  • 21
  • How we can get the number on which Callogs is received? ex. I have dual sim mobile so i want to know that +987654123 is Incoming call on SIM1 and +369258147 Missed call on SIM2? Please help me if you have solution of it. – Naimish B. Makwana Dec 28 '15 at 09:24
0

This also worked for me try this.

String where = CallLog.Calls.TYPE + "=" + "=1 "+" OR "+ CallLog.Calls.TYPE + "=" + "=3";

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
Load Reconn
  • 141
  • 1
  • 2