在Android中使用LibPhoneNumber谷歌库

sha*_*agz 12 android numbers contacts libphonenumber

libphonenumber在Android上不起作用,异常说:"引起:java.lang.UnsupportedOperationException:不支持CANON_EQ标志"

网页上的描述说lib是针对"智能手机"但Android不支持CANON_EQ reg_ex标志.

我错过了什么吗?

Bal*_*hnu 21

如果你使用Android工作室使用

compile 'com.googlecode.libphonenumber:libphonenumber:8.4.2'

如果你想下载最新的JAR文件转到

http://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber


小智 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兼容,直到它支持该标志.


Vij*_*put 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;
}
Run Code Online (Sandbox Code Playgroud)