0

有谁知道如何显示个人通话的通话记录详细信息?当我进入通话记录时,显示的唯一时间是“1 小时前、3 小时前、昨天、2 天前”等。有没有办法查看通话的实际时间和日期?另外,我注意到在查看此信息的短信时,“发送”时间是不准确的。有人可以在上午 12:51 给我发短信,电话会显示“下午 6:31 发送,上午 12:51 收到”。有谁知道如何解决这一问题?

Cursor callLogCursor = getContentResolver().query(
                android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
                android.provider.CallLog.Calls.DEFAULT_SORT_ORDER);
        if (callLogCursor != null) {
            while (callLogCursor.moveToNext()) {

                String name = callLogCursor.getString(callLogCursor
                        .getColumnIndex(CallLog.Calls.CACHED_NAME));

                String number = callLogCursor.getString(callLogCursor
                        .getColumnIndex(CallLog.Calls.NUMBER));

                long dateTimeMillis = callLogCursor.getLong(callLogCursor
                        .getColumnIndex(CallLog.Calls.DATE));

                String duration = callLogCursor.getString(callLogCursor
                        .getColumnIndex(CallLog.Calls.DURATION));

                int callType = callLogCursor.getInt(callLogCursor
                        .getColumnIndex(CallLog.Calls.TYPE));

                Date date = new Date(dateTimeMillis);
                String dateString = new SimpleDateFormat("yyyy-MM-dd HH:mm")
                        .format(date);

                if (name == null)
                    name = "Unknown";
                int type = 0;
                switch (callType) {
                case CallLog.Calls.OUTGOING_TYPE:
                    type = R.drawable.out;
                    break;

                case CallLog.Calls.INCOMING_TYPE:
                    type = R.drawable.in;
                    break;

                case CallLog.Calls.MISSED_TYPE:
                    type = R.drawable.miss;
                    break;
                }




    Thanks for your help!
4

1 回答 1

0

这是从通话记录中获取通话日期和时间的示例代码

    Cursor callDetailCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null,null,null,android.provider.CallLog.Calls.DATE + " DESC limit 50");
    int phoneNumber= callDetailCursor.getColumnIndex(CallLog.Calls.NUMBER);
    int callType=callDetailCursor.getColumnIndex(CallLog.Calls.TYPE);
    int callDate=callDetailCursor.getColumnIndex(CallLog.Calls.DATE);
    int callDuration=callDetailCursor.getColumnIndex(CallLog.Calls.DURATION);
    int isReadint=callDetailCursor.getColumnIndex(CallLog.Calls.IS_READ);

    Log.i(">>CAllDetails", "getsCallLogs" );

    if(callDetailCursor.getCount()>0)
    {
        while(callDetailCursor.moveToNext())
        {
String phoneNumberString=callDetailCursor.getString(phoneNumber);
String  contactName= getContactName(CallDetails.this, phoneNumberString);
String callTypeString =callDetailCursor.getString(callType);
String callDateString=callDetailCursor.getString(callDate);
String callDurationString=callDetailCursor.getString(callDuration);
Date callDayTime=new Date(Long.valueOf(callDateString));//converting readable date 

            int callCode = Integer.parseInt(callTypeString);
            int calldur=Integer.parseInt(callDurationString);
            if (callCode==2 && calldur>=1)
            {




String location[]=dbTools.getLocation(phoneNumberString);
String addtolist= "Name :"+contactName+"\n"+
                        "Phone Number: "+phoneNumberString+"\n"+"Call Duration :"+
                        callDurationString+" Seconds\n"+"Call Date: "+callDayTime+"\n"+
                location[0]+" "+location[1];
                callArrayList.add(addtolist);


            }
        }
    }callDetailCursor.close();
  }
于 2013-10-24T22:25:59.650 回答