想要得到联系人的通话记录或者通话时长 有什么方式可以实现 ,看到网上只有这样的一段代码
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);
           }不大懂这代码的意思,我将str和time 打印出来 得到这样的信息 null:1970-01-01 08:00:00 完全不是想要的东西啊
请教大牛指点这段代码 

解决方案 »

  1.   

    从 CallLog.Calls.CONTENT_URI读取是OK的,进入for循环之前先看下cursor 取到数据没,如果取到了,那就是for操作的不对,或者再尝试下不要指定列,试试
      

  2.   

    ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI, id)
      

  3.   

    String CallNumber = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));这样做吧,可以保证他的所在行的index
      

  4.   

    你的str被上一个str覆盖了