当前位置: 首页>>代码示例>>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;未经允许,请勿转载。