【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);
    }
.....
}

有问题欢迎指出,谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值