我正在创建一个 android 应用程序,它从设备中获取呼叫日志、格式化其日期等,在列表中显示所有呼叫以及一段代码来计算持续时间到分钟。它工作正常,但我希望我的应用程序显示从每月 20 日到下个月 20 日的通话记录。这样我就可以计算出我一个月说话的分钟数。这是我的代码
private String getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Details :");
while (managedCursor.moveToNext()) {
String phNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String dateStr = new SimpleDateFormat("dd:MM:yyyy", Locale.ENGLISH).format(callDayTime);
String callDuration = managedCursor.getString(duration);
float caldu =Float.parseFloat(callDuration); //convert seconds into minutes eg. 4secs to 1 minute
float value = caldu/60;
String tempStr=""+value;
StringTokenizer tokens = new StringTokenizer(tempStr, ".");
String strToken1=tokens.nextToken();
String strToken2=tokens.nextToken();
int lVal=Integer.parseInt(strToken1);
int rVal=Integer.parseInt(strToken2);
String CallsDurationStr = null;
if(rVal>0)
{
lVal=lVal+1;
CallsDurationStr=""+lVal;
}
else if(rVal==0)
{
CallsDurationStr=""+lVal;
}
String dir = null;
int dircode = Integer.parseInt(callType);
if(dircode==CallLog.Calls.OUTGOING_TYPE)
{
dir="outgoing";
sb.append("\nPhone Number:--- " + phNumber + " \nCall Date:--- " + dateStr
+ " \nCall duration in min :--- " + CallsDurationStr);
sb.append("\n----------------------------------");
}
}
managedCursor.close();
return sb.toString();
}
它显示了我在设备中的所有通话记录。如何获取特定时期的通话记录。提前致谢!