如何使Phonenumberutil识别阵列



我在带有电话号码的Recyclerview中有一个联系人列表。我希望Phonenumberutil(LibphoneNumber(告诉我,这些联系人中的一个是通过将传入数字与列表中的数字进行比较而呼唤的。目前,这仅适用于只有一个电话号码的联系人。我想要的是与具有几个数字的联系人一起工作。

这是我的代码的一部分:

String listNumbers = listItem.getNumbers().toString();
                System.out.println(listNumbers);
                PhoneNumberUtil pnu = PhoneNumberUtil.getInstance();
                PhoneNumberUtil.MatchType mt = pnu.isNumberMatch(listNumbers, number);
                if (mt == PhoneNumberUtil.MatchType.NSN_MATCH || mt == PhoneNumberUtil.MatchType.SHORT_NSN_MATCH || mt == PhoneNumberUtil.MatchType.EXACT_MATCH) {
                    if (selected) {
                        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                        if (notificationManager != null) {
                            notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
                        }
                    }
                }

这就是我的系统外观:

I/System.out: [029-426-9301, 029-426-9302, 029-426-9303]
I/System.out: [044-070-2586]
I/System.out: [225-649-86, 225-649-86]
I/System.out: [078-885-21174]

我尝试的是:

我尝试格式化字符串阵列,以便将逗号替换为方括号,例如:[029-426-9301] [029-426-9302] [029-426-9303]。但是,这没有什么区别,数字仍未得到认可。

我会感谢一些建议。

您可以做这样的事情:

boolean isMatch = false;
String matchedNumber = null;
for (String currentNumber : listItem.getNumbers ()) {
    PhoneNumberUtil.MatchType mt = pnu.isNumberMatch (currentNumber, number);
    if (mt == PhoneNumberUtil.MatchType.NSN_MATCH || mt == PhoneNumberUtil.MatchType.SHORT_NSN_MATCH || mt == PhoneNumberUtil.MatchType.EXACT_MATCH) {
        isMatch = true;
        matchedNumber = currentNumber;
        break;
    }
}
if (isMatch) {
    // your business logic
}

最新更新