【发布时间】:2018-04-28 16:50:36
【问题描述】:
我在 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);
}
}
}
这就是我的 System Out 的样子:
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]。但是,这并没有什么区别,数字仍然无法识别。
如果有一些建议,我将不胜感激。
【问题讨论】:
-
listItem.getNumbers()的数据类型是什么? -
这是列表
。这是你要问的吗? -
是的。检查我的答案。
标签: java android arrays libphonenumber phonenumberutils