當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneNumberUtil.findNumbers方法代碼示例

本文整理匯總了Java中com.google.i18n.phonenumbers.PhoneNumberUtil.findNumbers方法的典型用法代碼示例。如果您正苦於以下問題:Java PhoneNumberUtil.findNumbers方法的具體用法?Java PhoneNumberUtil.findNumbers怎麽用?Java PhoneNumberUtil.findNumbers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.i18n.phonenumbers.PhoneNumberUtil的用法示例。


在下文中一共展示了PhoneNumberUtil.findNumbers方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: evaluate

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
/**
 * @see Test#evaluate(Runner, RunState, EvaluationContext, String)
 */
@Override
public Result evaluate(Runner runner, RunState run, EvaluationContext context, String text) {
    String country = run.getOrg().getCountry();
    PhoneNumberUtil numberUtil = PhoneNumberUtil.getInstance();

    // try to find a phone number in the text we have been sent
    Iterable<PhoneNumberMatch> matches = numberUtil.findNumbers(text, country);

    // try it as an international number if we failed
    if (!matches.iterator().hasNext()) {
        matches = numberUtil.findNumbers("+" + text, country);
    }

    if (matches.iterator().hasNext()) {
        Phonenumber.PhoneNumber number = matches.iterator().next().number();
        return Result.match(numberUtil.format(number, PhoneNumberUtil.PhoneNumberFormat.E164));
    } else {
        return Result.NO_MATCH;
    }
}
 
開發者ID:rapidpro,項目名稱:flows,代碼行數:24,代碼來源:HasPhoneTest.java

示例2: parse

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
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;
}
 
開發者ID:GoogleCloudPlatform,項目名稱:endpoints-codelab-android,代碼行數:26,代碼來源:PhoneNumberParser.java

示例3: parseResults

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:gpadmaku1,項目名稱:card-reader,代碼行數:17,代碼來源:MainActivity.java

示例4: phoneNumberParsingTest

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
@Test
public void phoneNumberParsingTest(){
    String text = "Dank Pepe 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);
    }
}
 
開發者ID:gpadmaku1,項目名稱:card-reader,代碼行數:16,代碼來源:PhoneNumberTest.java

示例5: format

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
@Override
public String format(String text) {
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> matches = phoneNumberUtil.findNumbers(text, getCurrentCountryIso());
    for (PhoneNumberMatch match : matches) {
        Contact contact = Contact.get(match.rawString(), true);
        if (contact.isNamed()) {
            String nameAndNumber = phoneNumberUtil.format(match.number(), PhoneNumberFormat.NATIONAL)
                    + " (" + contact.getName() + ")";
            text = text.replace(match.rawString(), nameAndNumber);
        } // If the contact doesn't exist yet, leave the number as-is
    }
    return text;
}
 
開發者ID:moezbhatti,項目名稱:qksms,代碼行數:15,代碼來源:NumberToContactFormatter.java

示例6: gatherTelLinks

import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static final void gatherTelLinks(ArrayList<LinkSpec> links, Spannable s) {
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> matches = phoneUtil.findNumbers(s.toString(),
            Locale.getDefault().getCountry(), PhoneNumberUtil.Leniency.POSSIBLE, Long.MAX_VALUE);
    for (PhoneNumberMatch match : matches) {
        LinkSpec spec = new LinkSpec();
        spec.url = PhoneNumberUtils.normalizeNumber(match.rawString());
        spec.start = match.start();
        spec.end = match.end();
        spec.type = PHONE_NUMBERS;
        links.add(spec);
    }
}
 
開發者ID:omgnuts,項目名稱:android-sidekick,代碼行數:15,代碼來源:Extractor.java


注:本文中的com.google.i18n.phonenumbers.PhoneNumberUtil.findNumbers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。