我正在尝试在当月添加所有来电的持续时间。我将移动时间月份与当月添加电话的通话月份进行比较。但是电话的日期正在返回1.我试图获得完整的日期,并且它始终是1.1.1970。(是的,我检查了通话日期及其权利4.4.2011)
源代码:
DateFormat date = new SimpleDateFormat("MM");
Calendar calendar = Calendar.getInstance();
long currentDate = calendar.getTimeInMillis();
String currentDatess = date.format(currentDate);
int d1 = Integer.valueOf(currentDatess.toString());
Log.d(TAG,"Value od d1: " + d1); **->> it is returning right value(now 4)**
Cursor cCall = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI, null, null, null, null");
while(cCall.moveToNext()){
CallsDuration = cCall.getColumnIndex(android.provider.CallLog.Calls.DURATION);
CallDateFull = cCall.getColumnIndex(android.provider.CallLog.Calls.DATE);
calendar.setTimeInMillis(CallDateFull);
String datess = date.format(calendar.getTime());
datesss = Integer.valueOf(datess.toString());
String callDate = DateFormat.getDateInstance().format(CallDateFull); **-> only for test,it is ever returning 1.1.1970**
Log.d(TAG, "Test: " + callDate);
totalTimeInInt = totalTimeInInt + CallsDuration; **--> Total duration time of all calls**
Log.d(TAG, "Date: " + datesss); --> this is returning 1(1.1.1970)
if (d1 == datesss){
CallsInMonth = CallsInMonth + CallsDuration;
}
}
TotalTime = String.valueOf(totalTimeInInt);
CallInMonthString = String.valueOf(CallsInMonth);
}
答案 0 :(得分:1)
您正在格式化列的索引:
CallDateFull = cCall.getColumnIndex(android.provider.CallLog.Calls.DATE);
您必须获取光标的长值:
CallDateFull = cCall.getLong(cCall.getColumnIndex(android.provider.CallLog.Calls.DATE));