我正在尝试在我的应用程序中实现以下功能。 如果用户选择某个日期(开始日期),则我的应用程序将能够显示该特定日期之后和今天之前的未接来电,去电和来电计数。 我已经实现了代码,如果我不放置任何过滤器,则它可以正常工作并正确计数所有呼叫日志。我已经使用IF条件块添加了dateFilter。但这不起作用。
我还尝试了相关问题中的一些方法,这些方法指示我们修改查询,但没有任何效果。您能帮我找到失踪的物品吗? 这是我的功能。
/* Operation of Counting the call logs will be performed */
void performCount() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {
Cursor dataCursor = getApplicationContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null,
null);
/* Date choosen by user, to get the Call logs after this date */
Date startDate=new Date(2018,5,5);
Toast.makeText(getApplicationContext(),startDate.toString(),Toast.LENGTH_SHORT).show();
/* Tried Solution but it doesn't work */
/*
dataCursor = getApplicationContext().getContentResolver().query(CallLog.Calls.CONTENT_URI,
new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
CallLog.Calls.NUMBER, CallLog.Calls._ID },
CallLog.Calls.DATE + ">?",
new String[] { String.valueOf(startDate.getTime())},
CallLog.Calls.NUMBER + " asc");
*/
int PhoneNumber=dataCursor.getColumnIndex(CallLog.Calls.NUMBER);
int TypeofCall=dataCursor.getColumnIndex(CallLog.Calls.TYPE);
//int DurationofCall=dataCursor.getColumnIndex(CallLog.Calls.DURATION);
int dateofCall=dataCursor.getColumnIndex(CallLog.Calls.DATE);
/*Traverse the Result Set */
while(dataCursor.moveToNext()){
//Log.d("Running","In while loop");
String pNumber=dataCursor.getString(PhoneNumber);
String typeNumber=dataCursor.getString(TypeofCall);
int tnumber=Integer.parseInt(typeNumber);
String dateString=dataCursor.getString(dateofCall);
Date dateobject= new Date(Long.valueOf(dateString));
Log.d("Date: ",dateobject.toString());
//String durationNumber=dataCursor.getString(DurationofCall);
if(dateobject.after(startDate)){
Log.d("Running","In IF CONDITIOn");
if(tnumber==CallLog.Calls.MISSED_TYPE){
missedCallsCount+=1;
}
else if(tnumber==CallLog.Calls.OUTGOING_TYPE){
OutgoingCallCount+=1;
}
else if(tnumber==CallLog.Calls.INCOMING_TYPE){
IncomingCallsCount+=1;
}
}
}
dataCursor.close();
return;
}
}