天天看点

android中获取通话记录

转自:http://blog.163.com/[email protected]/blog/static/647443192010111753159614/

String str = "";

        int type;

        long callTime;

        Date date;

        String time= "";

        ContentResolver cr = getContentResolver();

        final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER,CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE}, null, null,CallLog.Calls.DEFAULT_SORT_ORDER);

        for (int i = 0; i < cursor.getCount(); i++) {   

            cursor.moveToPosition(i);

            str = cursor.getString(0);

            str = cursor.getString(1);

            type = cursor.getInt(2);

            SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

            date = new Date(Long.parseLong(cursor.getString(3)));

            time = sfd.format(date);

           }