有谁知道如何显示个别来电的通话记录详情?当我进入通话记录时,显示的唯一时间是“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!
答案 0 :(得分: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();
}