How are call types (incoming / outgoing / missed) stored in the Android call log?

This may be a stupid question, I'm a little noob. I read this post: How to access the call log for Android?

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

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

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

Thanks Matt

+5
source share
5 answers

The type is stored as a whole. 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 CallLog.Calls.MISSED_TYPE, INCOMING_TYPE and OUTGOING_TYPE constants would be better.

+9

CallLog.Calls.TYPE , , .

1

2

3

android.provider.CallLog.Calls.MISSED_TYPE, android.provider.CallLog.Calls.INCOMING_TYPE android.provider.CallLog.Calls.OUTGOING_TYPE.

+5

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();
}
+3
+2
source

It also helped me try.

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

0
source

All Articles