Android通话记录陌生号码与联系人号码后8位模糊匹配问题
1、参考相关文章如下
链接1: https://blog.csdn.net/u012932409/article/details/117472230
链接2: https://juejin.cn/post/6979416844755025934
参考这2篇文献后,联系人详情里能正常匹配到对应的通话记录
(例如联系人A下的号码为12345678,陌生通话记录0912345678不会显示到联系人A详情里)
2、相邻的通话记录依然存在模糊匹配问题分析
1)相邻的通话记录对比的代码处
package android.telephony;
public class PhoneNumberUtils {
·····
/**
* Compare phone numbers a and b, return true if they're identical enough for caller ID purposes.
*/
public static boolean compare(String a, String b) {
// We've used loose comparation at least Eclair, which may change in the future.
//todo可以改这里 (注意这里传了false,会存在后8位模糊匹配)
return compare(a, b, false);
}
/**
* Compare phone numbers a and b, and return true if they're identical
* enough for caller ID purposes. Checks a resource to determine whether
* to use a strict or loose comparison algorithm.
*/
public static boolean compare(Context context, String a, String b) {
boolean useStrict = context.getResources().getBoolean(
com.android.internal.R.bool.config_use_strict_phone_number_comparation);
return compare(a, b, useStrict);
}
/**
* @hide only for testing.
*/
public static boolean compare(String a, String b, boolean useStrictComparation) {
return (useStrictComparation ? compareStrictly(a, b) : compareLoosely(a, b));
}
·····
}
2)Dialer应用里的CallLogGroupBuilder类如何判断相邻的号码是不是同一个号码
package com.android.dialer.app.calllog;
public class CallLogGroupBuilder {
.....
public void addGroups(Cursor cursor) {
.....
final boolean isSameNumber = equalNumbers(groupNumber, number);
.....
}
/**
* Returns true when the two input numbers can be considered identical enough for caller ID
* purposes and put in a call log group.
*/
@VisibleForTesting
boolean equalNumbers(@Nullable String number1, @Nullable String number2) {
if (PhoneNumberHelper.isUriNumber(number1) || PhoneNumberHelper.isUriNumber(number2)) {
return compareSipAddresses(number1, number2);
}
// PhoneNumberUtils.compare(String, String) ignores special characters such as '#'. For example,
// it thinks "123" and "#123" are identical enough for caller ID purposes.
// When either input number contains special characters, we put the two in the same group iff
// their raw numbers are exactly the same.
if (PhoneNumberHelper.numberHasSpecialChars(number1)
|| PhoneNumberHelper.numberHasSpecialChars(number2)) {
return PhoneNumberHelper.sameRawNumbers(number1, number2);
}
//这里本来是调用了PhoneNumberUtils.compare(number1, number2),也就是非严格匹配(问题出现在这里)
return PhoneNumberUtils.compare(mContext, number1, number2);
}
.....
}
有问题欢迎指出,谢谢