现在调用日志列表视图屏幕截图
我只是不想在我的数据库中重复值。因此,我的列表视图中将一次显示一个联系人姓名,并且我还希望与其号码关联的呼叫数量。通过查询插入数据库时,我可以通过使用唯一关键字获得独特的价值,但我没有任何关于计算我从该数字得到的电话的信息。
我正在使用以下代码从数据库中获取调用日志。现在我只是访问通话记录并显示它。我没有存储在数据库中。我不知道如何计算来自特定号码的呼叫数量并将其显示在前面。它显示在呼叫日志应用程序中。
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 id = callLogCursor.getString(callLogCursor
.getColumnIndex(CallLog.Calls._ID));
String name = callLogCursor.getString(callLogCursor
.getColumnIndex(CallLog.Calls.CACHED_NAME));
String cacheNumber = callLogCursor.getString(callLogCursor
.getColumnIndex(CallLog.Calls.CACHED_NUMBER_LABEL));
String number = callLogCursor.getString(callLogCursor
.getColumnIndex(CallLog.Calls.NUMBER));
long dateTimeMillis = callLogCursor.getLong(callLogCursor
.getColumnIndex(CallLog.Calls.DATE));
long durationMillis = callLogCursor.getLong(callLogCursor
.getColumnIndex(CallLog.Calls.DURATION));
int callType = callLogCursor.getInt(callLogCursor
.getColumnIndex(CallLog.Calls.TYPE));
String duration = getDuration(durationMillis * 1000);
String dateString = getDateTime(dateTimeMillis);
if (cacheNumber == null)
cacheNumber = number;
if (name == null)
name = "";
Uri image = null;
try {
String conId = fetchContactIdFromPhoneNumber(cacheNumber);
long contId = Long.parseLong(conId);
image = getPhotoUri(contId);
}catch(Exception e) {
Log.e("Exception", e.getMessage());
}
CallLogModel callLogModel = new CallLogModel(image, name, cacheNumber,
duration, dateString);
if (callType == CallLog.Calls.OUTGOING_TYPE) {
outgoingList.add(callLogModel);
} else if (callType == CallLog.Calls.INCOMING_TYPE) {
incomingList.add(callLogModel);
} else if (callType == CallLog.Calls.MISSED_TYPE) {
missedcallList.add(callLogModel);
}
}
callLogCursor.close();
}
}
答案 0 :(得分:0)
您可以尝试使用group by子句如下:
String[] columns = new String[] { CallLog.Calls._ID, CallLog.Calls.NUMBER, CallLog.Calls.CACHED_NAME };
Cursor cursor = getContentResolver().query(URI_CALL, columns, null, null, null);