本文整理汇总了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
}
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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;
}