图书馆libphonenumber在Android上不起作用,例外情况说: “引起:java.lang.UnsupportedOperationException:不支持CANON_EQ标志”
网页上的描述说lib是针对“智能手机”但Android不支持CANON_EQ reg_ex标志..
我错过了什么吗?
答案 0 :(得分:20)
如果您使用Android工作室
compile 'com.googlecode.libphonenumber:libphonenumber:8.4.2'
如果要下载最新的JAR文件goto
http://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber
答案 1 :(得分:7)
请尝试使用下载页面中的libphonenumber-2.5.1.jar:
http://code.google.com/p/libphonenumber/downloads/list
Right-Number项目的jar工作正常,因为他们使用的是libphonenumber-2.4.jar。 CANON_EQ标志是在v2.5中引入的,但现在从2.5.1中移除以与Android兼容,直到它支持该标志。
答案 2 :(得分:6)
您好请使用此功能传递电话号码和国家代码,如印度91
public static String parseContact(String contact, String countrycode) {
PhoneNumber phoneNumber = null;
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
String finalNumber = null;
String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(countrycode));
boolean isValid = false;
PhoneNumberType isMobile = null;
try {
phoneNumber = phoneNumberUtil.parse(contact, isoCode);
isValid = phoneNumberUtil.isValidNumber(phoneNumber);
isMobile = phoneNumberUtil.getNumberType(phoneNumber);
} catch (NumberParseException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
if (isValid
&& (PhoneNumberType.MOBILE == isMobile || PhoneNumberType.FIXED_LINE_OR_MOBILE == isMobile)) {
finalNumber = phoneNumberUtil.format(phoneNumber,
PhoneNumberFormat.E164).substring(1);
}
return finalNumber;
}
答案 3 :(得分:2)
编译'com.googlecode.libphonenumber:libphonenumber:7.1.1'
在您的gradle中使用此依赖项。
答案 4 :(得分:1)
我自己一直在努力解决同样的问题,并且能够通过使用以下版本来解决它:
http://code.google.com/p/right-number/source/browse/trunk/RightNumber/libs/libphonenumber.jar
此版本来自Right-Number project,旨在构建用于处理Android上电话号码格式的用户界面。
我在我的项目中使用它并且工作正常。
答案 5 :(得分:1)
提交问题:
http://code.google.com/p/libphonenumber/issues/list
我在最新版本中遇到了类似的问题,他们在回答我的问题时非常快。它绝对只是一个浮出水面的错误,你应该报告它,如果你想修复它。他们花了10分钟来承认我的问题,15分钟后他们说他们准备好了补丁。
Right-Number的jar只是一个旧版本。
答案 6 :(得分:1)
新版本的libphonenumber http://code.google.com/p/libphonenumber/是为Java 1.5编译的,现在可用于较旧的Android系统。
以前的版本是为Java 1.6编译的,但您可以使用提供的源代码重新编译任何版本。
答案 7 :(得分:0)
暂时尝试http://code.google.com/p/libphonenumber/downloads版本2.5.1,因为它包含更多新元数据。
几周后会有更多更新。