當前位置: 首頁>>代碼示例>>Java>>正文


Java PhoneNumberUtil.getNumberType方法代碼示例

本文整理匯總了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 "";
    }
}
 
開發者ID:Piasy,項目名稱:YaMvp,代碼行數:18,代碼來源:MainPresenter.java

示例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;
  }
}
 
開發者ID:SilenceIM,項目名稱:Silence,代碼行數:24,代碼來源:AutoInitiate.java

示例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);
	}
}
 
開發者ID:yonadev,項目名稱:yona-server,代碼行數:17,代碼來源:UserService.java

示例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);
	}
}
 
開發者ID:waynell,項目名稱:DialerBox,代碼行數:11,代碼來源:GeocoderUtils.java


注:本文中的com.google.i18n.phonenumbers.PhoneNumberUtil.getNumberType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。