您的位置:首页 > 移动开发 > Android开发

Android 通话记录列表同一号码显示多次的问题

2013-07-07 14:28 381 查看
上几天遇到了一个比较怪的问题,用一个号码给测试机拨号,然后再用测试机给刚才的机器拨号,然后就是各种通话,然后查看通话记录列表,有意思的事情发生了,相同通话类型的通话记录是合并在了一起,但是不同通话类型的通话记录是分开的,开始很痛苦啊,后来有仔细的看了一下code,终于找到了问题的原因,导致问题发生的文件实在联系人目录的calllog包中,文件名是CallLogGroupBuilder

/**
* Finds all groups of adjacent entries in the call log which should be grouped together and
* calls {@link GroupCreator#addGroup(int, int, boolean)} on {@link #mGroupCreator} for each of
* them.
* <p>
* For entries that are not grouped with others, we do not need to create a group of size one.
* <p>
* It assumes that the cursor will not change during its execution.
*
* @see GroupingListAdapter#addGroups(Cursor)
*/
public void addGroups(Cursor cursor) {
final int count = cursor.getCount();
if (count == 0) {
return;
}

int currentGroupSize = 1;
cursor.moveToFirst();
// The number of the first entry in the group.
String firstNumber = cursor.getString(CallLogQuery.NUMBER);
// This is the type of the first call in the group.
int firstCallType = cursor.getInt(CallLogQuery.CALL_TYPE);
int firstVideoFlag = cursor.getInt(CallLogQuery.VIDEO_CALL_FLAG);
while (cursor.moveToNext()) {
// The number of the current row in the cursor.
final String currentNumber = cursor.getString(CallLogQuery.NUMBER);
final int callType = cursor.getInt(CallLogQuery.CALL_TYPE);
final int videoFlag = cursor.getInt(CallLogQuery.VIDEO_CALL_FLAG);
final boolean sameNumber = equalNumbers(firstNumber, currentNumber);
final boolean sameVideoFlag = (firstVideoFlag == videoFlag);
final boolean shouldGroup;

if (CallLogQuery.isSectionHeader(cursor)) {
// Cannot group headers.
shouldGroup = false;
} else if (!sameNumber||!sameVideoFlag) {
// Should only group with calls from the same number.
shouldGroup = false;
} else if (firstCallType == Calls.VOICEMAIL_TYPE
|| firstCallType == Calls.MISSED_TYPE) {
// Voicemail and missed calls should only be grouped with subsequent missed calls.
shouldGroup = callType == Calls.MISSED_TYPE;
} else {
// Incoming and outgoing calls group together.
shouldGroup = callType == Calls.INCOMING_TYPE || callType == Calls.OUTGOING_TYPE;
}

if (shouldGroup) {
// Increment the size of the group to include the current call, but do not create
// the group until we find a call that does not match.
currentGroupSize++;
} else {
// Create a group for the previous set of calls, excluding the current one, but do
// not create a group for a single call.
if (currentGroupSize > 1) {
addGroup(cursor.getPosition() - currentGroupSize, currentGroupSize);
}
// Start a new group; it will include at least the current call.
currentGroupSize = 1;
// The current entry is now the first in the group.
firstNumber = currentNumber;
firstCallType = callType;
firstVideoFlag = videoFlag;
}
}
// If the last set of calls at the end of the call log was itself a group, create it now.
if (currentGroupSize > 1) {
addGroup(count - currentGroupSize, currentGroupSize);
}
}上面这个方法的功能就是将所有的通话记录来过滤一遍,然后将相连的通话类型相同的合并,请查看firstCallType的逻辑就可以很清楚的知道为什么会出现此问题了,通话记录的显示和此有很大的关系,暂时先写这过,过一段时间会将通话记录列表的显示的流程写出来
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐