Using LibPhoneNumber google lib in Android
Asked Answered
H

8

15

The library libphonenumber doesn't work on Android and the exception says: "Caused by: java.lang.UnsupportedOperationException: CANON_EQ flag not supported"

The description in the webpage says that the lib is for "Smartphones" but Android doesn't support CANON_EQ reg_ex flag..

Am I missing something?

Hilda answered 27/1, 2011 at 15:26 Comment(1)
Most of the features of this library are available with the android framework itself, Please read developer.android.com/reference/android/telephony/…Pontine
P
6

Please try using libphonenumber-2.5.1.jar from the download page:

http://code.google.com/p/libphonenumber/downloads/list

The jar from the Right-Number project works because they are using libphonenumber-2.4.jar. The CANON_EQ flag was introduced in v2.5, but is now removed from 2.5.1 to be compatible with Android until it supports the flag.

Peptidase answered 28/1, 2011 at 8:51 Comment(0)
Z
31

If you're using Android studio use

implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.32'

If you want to download the latest JAR file goto

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

Zilla answered 7/11, 2015 at 17:0 Comment(4)
7000 methods, it's so heavy %)Otology
Yes and this library is too buggy too. My client got frustrated and ditched this lib..Zilla
worth editing to add where the latest version is I think it's 8.4.2 nowConfocal
I used compile 'com.googlecode.libphonenumber:libphonenumber:8.8.3'Legibility
P
9

Hi Please use this function to pass phone number and country code like india 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;
}
Photophore answered 7/8, 2014 at 7:30 Comment(0)
P
6

Please try using libphonenumber-2.5.1.jar from the download page:

http://code.google.com/p/libphonenumber/downloads/list

The jar from the Right-Number project works because they are using libphonenumber-2.4.jar. The CANON_EQ flag was introduced in v2.5, but is now removed from 2.5.1 to be compatible with Android until it supports the flag.

Peptidase answered 28/1, 2011 at 8:51 Comment(0)
I
2

compile 'com.googlecode.libphonenumber:libphonenumber:7.1.1'

Use this dependency in you gradle.

check this https://github.com/googlei18n/libphonenumber

Inculpable answered 23/9, 2016 at 7:15 Comment(1)
Worked! I tried downloading the latest jar from their repo (libphonenumber-7.7.2) and it kept throwing exception in runtime. With this older version and with import via gradle it works!!!!Homochromatic
D
2

On android :

implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.31'
Desta answered 1/9, 2021 at 8:49 Comment(0)
H
1

I've struggled with the exact same question myself, and was able to solve it by using the following version:

http://code.google.com/p/right-number/source/browse/trunk/RightNumber/libs/libphonenumber.jar

This version is from the Right-Number project that aims to build a user interface for dealing with phone number formatting on Android.

I've used it in my project and it works fine.

Hexahedron answered 27/1, 2011 at 16:10 Comment(0)
P
1

Submit an issue at:

http://code.google.com/p/libphonenumber/issues/list

I had a similar issue with the newest revision and they were very fast with answering my issue. It's definitely just a bug which has surfaced and you should report it if you want it fixed. Took them 10 minutes to acknowledge my issue and 15 min after that they said they had a patch ready for it.

The jar at Right-Number is just an older revision.

Pectoral answered 28/1, 2011 at 7:58 Comment(0)
S
1

The new version of libphonenumber http://code.google.com/p/libphonenumber/ is compiled for Java 1.5 and will now work on older android systems.

Previous versions were compiled for Java 1.6, but you could have re-compiled for any version using the supplied source code.

Sclerotic answered 11/2, 2011 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.