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