当前位置: 首页>>代码示例>>Java>>正文


Java PhoneNumber.getCountryCode方法代码示例

本文整理汇总了Java中com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.getCountryCode方法的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumber.getCountryCode方法的具体用法?Java PhoneNumber.getCountryCode怎么用?Java PhoneNumber.getCountryCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.i18n.phonenumbers.Phonenumber.PhoneNumber的用法示例。


在下文中一共展示了PhoneNumber.getCountryCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: syncCountryCodeSelector

import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入方法依赖的package包/类
/** Sync country code with text entered by the user, if possible. */
void syncCountryCodeSelector() {
    try {
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        CountryCode cc = (CountryCode) mCountryCode.getSelectedItem();
        PhoneNumber phone = util.parse(mPhone.getText().toString(), cc != null ? cc.regionCode : null);
        // autoselect correct country if user entered country code too
        if (phone.hasCountryCode()) {
            CountryCode ccLookup = new CountryCode();
            ccLookup.regionCode = util.getRegionCodeForNumber(phone);
            ccLookup.countryCode = phone.getCountryCode();
            int position = ((CountryCodesAdapter) mCountryCode.getAdapter()).getPositionForId(ccLookup);
            if (position >= 0) {
                mCountryCode.setSelection(position);
            }
        }
    }
    catch (NumberParseException e) {
        // ignored
    }
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:22,代码来源:NumberValidation.java

示例2: getPhoneNumber

import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入方法依赖的package包/类
public static String getPhoneNumber(String number, String defaultCountryCode) {
    if (TextUtils.isEmpty(number)) {
        return "";
    }

    PhoneNumber phoneNumber;
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();

    if (TextUtils.isEmpty(number)) {
        return "";
    }

    long contactNumber = 0;
    int countryCode = 0;

    try {
        phoneNumber = phoneUtil.parse(number, defaultCountryCode);
        if (phoneNumber.hasCountryCode()) {
            countryCode = phoneNumber.getCountryCode();
        }

        contactNumber = phoneNumber.getNationalNumber();
    } catch (Exception ex) {
        try {
            contactNumber = Long.parseLong(number);
        } catch (Exception e) {
            return number;
        }
    } finally {

    }
    return "+" + countryCode + contactNumber;
}
 
开发者ID:AppLozic,项目名称:Applozic-Android-Chat-Sample,代码行数:34,代码来源:ContactNumberUtils.java

示例3: isSpecialNumber

import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入方法依赖的package包/类
/** Handles special numbers not handled by libphonenumber. */
public static boolean isSpecialNumber(PhoneNumber number) {
    if (number.getCountryCode() == 31) {
        // handle special M2M numbers: 11 digits starting with 097[0-8]
        final Pattern regex = Pattern.compile("^97[0-8][0-9]{8}$");
        Matcher m = regex.matcher(String.valueOf(number.getNationalNumber()));
        return m.matches();
    }
    return false;
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:11,代码来源:NumberValidator.java

示例4: handleSpecialCases

import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入方法依赖的package包/类
/**
 * Handles special cases in a parsed phone number.
 * @param phoneNumber the phone number to check. It will be modified in place.
 */
public static void handleSpecialCases(PhoneNumber phoneNumber) {
    PhoneNumberUtil util = PhoneNumberUtil.getInstance();

    // Argentina numbering rules
    int argCode = util.getCountryCodeForRegion("AR");
    if (phoneNumber.getCountryCode() == argCode) {
        // forcibly add the 9 between country code and national number
        long nsn = phoneNumber.getNationalNumber();
        if (firstDigit(nsn) != 9) {
            phoneNumber.setNationalNumber(addSignificantDigits(nsn, 9));
        }
    }
}
 
开发者ID:kontalk,项目名称:androidclient,代码行数:18,代码来源:NumberValidator.java

示例5: getCountry

import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入方法依赖的package包/类
/**
 * This function is never used, delete on next major
 */
@Deprecated
public static int getCountry(String numberText) {
    final PhoneNumber phoneNumber = getPhoneNumber(numberText);
    if (phoneNumber != null) {
        return phoneNumber.getCountryCode();
    }
    return -1;
}
 
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:12,代码来源:PhoneUtil.java


注:本文中的com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.getCountryCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。