本文整理匯總了Java中com.google.i18n.phonenumbers.PhoneNumberUtil.getNumberType方法的典型用法代碼示例。如果您正苦於以下問題:Java PhoneNumberUtil.getNumberType方法的具體用法?Java PhoneNumberUtil.getNumberType怎麽用?Java PhoneNumberUtil.getNumberType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.i18n.phonenumbers.PhoneNumberUtil
的用法示例。
在下文中一共展示了PhoneNumberUtil.getNumberType方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateThenFormatMobileNumber
import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
private String validateThenFormatMobileNumber(String phone) {
try {
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
Phonenumber.PhoneNumber phoneNumber = phoneNumberUtil.parse(phone, "+86");
if (phoneNumberUtil.isValidNumber(phoneNumber) && (
phoneNumberUtil.getNumberType(phoneNumber)
== PhoneNumberUtil.PhoneNumberType.MOBILE
|| phoneNumberUtil.getNumberType(phoneNumber)
== PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE)) {
return phoneNumberUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
} else {
return "";
}
} catch (NumberParseException e) {
return "";
}
}
示例2: isTaggableDestination
import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
public static boolean isTaggableDestination(Recipients recipients){
// Be safe - err on the side of not tagging
if (recipients.isGroupRecipient())
return false;
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
try {
PhoneNumber num = util.parse(recipients.getPrimaryRecipient().getNumber(),
Locale.getDefault().getCountry());
PhoneNumberType type = util.getNumberType(num);
Log.d(TAG, "Number type: " + type.toString());
return type == PhoneNumberType.FIXED_LINE ||
type == PhoneNumberType.MOBILE ||
type == PhoneNumberType.FIXED_LINE_OR_MOBILE;
}
catch (NumberParseException e){
Log.w(TAG, "Couldn't get number type (country: " + Locale.getDefault().getCountry() + ")");
return false;
}
}
示例3: assertNumberIsMobile
import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
private void assertNumberIsMobile(String mobileNumber)
{
try
{
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
PhoneNumberType numberType = util.getNumberType(util.parse(mobileNumber, null));
if ((numberType != PhoneNumberType.MOBILE) && (numberType != PhoneNumberType.FIXED_LINE_OR_MOBILE))
{
throw InvalidDataException.notAMobileNumber(mobileNumber, numberType.toString());
}
}
catch (NumberParseException e)
{
throw YonaException.unexpected(e);
}
}
示例4: getDescriptionForNumber
import com.google.i18n.phonenumbers.PhoneNumberUtil; //導入方法依賴的package包/類
static String getDescriptionForNumber(Phonenumber.PhoneNumber number, Locale languageCode) {
final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
final PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
PhoneNumberUtil.PhoneNumberType numberType = phoneNumberUtil.getNumberType(number);
if (numberType == PhoneNumberUtil.PhoneNumberType.UNKNOWN) {
return "";
} else {
return geocoder.getDescriptionForValidNumber(number, languageCode);
}
}