Java Code Examples for com.google.i18n.phonenumbers.PhoneNumberUtil#findNumbers()

The following examples show how to use com.google.i18n.phonenumbers.PhoneNumberUtil#findNumbers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhoneNumberParser.java    From endpoints-codelab-android with GNU General Public License v3.0 6 votes vote down vote up
public List<String> parse(String inputText) {
    if (inputText == null) {
        return Collections.emptyList();
    }

    // Only run the phone number parser if Android version is not Honeycomb
    // API level 11 - 13
    int sdk = Build.VERSION.SDK_INT;

    if (sdk >= 11 && sdk <= 13) {
        return Collections.emptyList();
    }

    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> numbersMatch = phoneUtil.findNumbers(
            inputText, Locale.getDefault().getCountry());
    ArrayList<String> numbers = new ArrayList<String>();

    for (PhoneNumberMatch number : numbersMatch) {
        numbers.add(phoneUtil.format(number.number(),
                PhoneNumberFormat.NATIONAL));
    }

    return numbers;
}
 
Example 2
Source File: MainActivity.java    From card-reader with MIT License 5 votes vote down vote up
/**
 * Parses phoneNumbers from a string using Google's libphonenumber library
 *
 * @param bCardText, The text obtained from the vision API processing
 * @return ArrayList of parsed phone numbers from the vision API processed text string
 */
private ArrayList<String> parseResults(String bCardText) {
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> numberMatches = phoneNumberUtil.findNumbers(bCardText, Locale.US.getCountry());
    ArrayList<String> data = new ArrayList<>();
    for(PhoneNumberMatch number : numberMatches){
        String s = number.rawString();
        data.add(s);
    }
    return data;
}
 
Example 3
Source File: PhoneNumberTest.java    From card-reader with MIT License 5 votes vote down vote up
@Test
public void phoneNumberParsingTest(){
    String text = "Hank Schrader Program Manager Org Activities Multi Studios 555 Horton Street, " +
            "P.0. Box 143 London, ON N6A 4H6 519 661 9000 Ext. 5014 Cell: 519 456 5463 Powering London. " +
            "[email protected] Empowering You. Fax: 519 611 5841 :";
    String text2 = "onlinestudiomarketing Darth Vader R Web Developer/ Designer/ Wordpress " +
            "Consultant 519-333-541 [email protected] London, ON Canada www.onlinestudiomarketing.ca";

    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> numberMatches = phoneNumberUtil.findNumbers(text2, Locale.US.getCountry());
    for(PhoneNumberMatch number : numberMatches){
        String s = number.rawString();
        System.out.println(s);
    }
}