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


Java PhoneNumberFormat类代码示例

本文整理汇总了Java中com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumberFormat类的具体用法?Java PhoneNumberFormat怎么用?Java PhoneNumberFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PhoneNumberFormat类属于com.google.i18n.phonenumbers.PhoneNumberUtil包,在下文中一共展示了PhoneNumberFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatE164(String countryCode, String number) {
  try {
    PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
    int parsedCountryCode    = Integer.parseInt(countryCode);
    PhoneNumber parsedNumber = util.parse(number,
                                          util.getRegionCodeForCountryCode(parsedCountryCode));

    return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
  } catch (NumberParseException | NumberFormatException npe) {
    Log.w(TAG, npe);
  }

  return "+"                                                     +
      countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") +
      number.replaceAll("[^0-9]", "");
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:17,代码来源:PhoneNumberFormatter.java

示例2: convertPhoneNumberToE164

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String convertPhoneNumberToE164(Context context, String ph_no) {
	PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
	PhoneNumber pn = null;
	String temp_ph_no = null;
	try {
		pn = phoneNumberUtil.parse(ph_no, "");
		temp_ph_no = phoneNumberUtil.format(pn, PhoneNumberFormat.E164);
	} catch (Exception e) {
		try {
			pn = phoneNumberUtil.parse(ph_no,
					((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
							.getSimCountryIso().toUpperCase());
			temp_ph_no = phoneNumberUtil.format(pn, PhoneNumberFormat.E164);
		} catch (Exception ee) {
			FirebaseCrash.log(ee.getStackTrace().toString());
		}
	}
	return temp_ph_no;
}
 
开发者ID:arunrajora,项目名称:Chit-Chat,代码行数:20,代码来源:Utils.java

示例3: format_to_enum

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
private static PhoneNumberFormat format_to_enum( int type )
{
    PhoneNumberFormat e = PhoneNumberFormat.INTERNATIONAL;

    switch ( type )
    {
        case FORMAT_RFC3966:
             e = PhoneNumberFormat.RFC3966;
            break;

        case FORMAT_E164:
            e = PhoneNumberFormat.E164;
            break;

        case FORMAT_NATIONAL:
            e = PhoneNumberFormat.NATIONAL;
            break;

        case FORMAT_INTERNATIONAL:
        default:
            e = PhoneNumberFormat.INTERNATIONAL;
            break;
    }

    return e;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:27,代码来源:PhoneNumberImpl.java

示例4: enum_to_format

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
private static int enum_to_format( PhoneNumberFormat type )
{
    int e = FORMAT_INTERNATIONAL;

    switch ( type )
    {
        case RFC3966:
            e = FORMAT_RFC3966;
            break;

        case E164:
            e = FORMAT_E164;
            break;

        case NATIONAL:
            e = FORMAT_NATIONAL;
            break;

        case INTERNATIONAL:
        default:
            e = FORMAT_INTERNATIONAL;
            break;
    }

    return e;
}
 
开发者ID:nvanwyen,项目名称:libphonenumber-oracle,代码行数:27,代码来源:PhoneNumberImpl.java

示例5: isValid

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {

    if (value == null) {
        return false;
    }
    try {

        final PhoneNumber parsingResult = pnu.parse(value, null);
        if (!pnu.format(parsingResult, PhoneNumberFormat.E164).equals(value)) {
            return false;
        }
        return true;
    } catch (final NumberParseException t) {
        // Errors when parsing phonenumber
        return false;
    }

    // CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
    // log.debug("Phone Number: {}", value);
    // log.debug("Country code: {}", numberProto.getCountryCode());
    // log.debug("National Number: {}", numberProto.getNationalNumber());
    // log.debug("E164 format: {}", pnu.format(numberProto,
    // PhoneNumberFormat.E164));

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:E164Validator.java

示例6: parse

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public List<String> parse(String inputText) {
    if (inputText == null) {
        return Collections.emptyList();
    }

    // Only run the phone number parser if Android version is not Honeycomb
    // API level 11 - 13
    int sdk = Build.VERSION.SDK_INT;

    if (sdk >= 11 && sdk <= 13) {
        return Collections.emptyList();
    }

    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    Iterable<PhoneNumberMatch> numbersMatch = phoneUtil.findNumbers(
            inputText, Locale.getDefault().getCountry());
    ArrayList<String> numbers = new ArrayList<String>();

    for (PhoneNumberMatch number : numbersMatch) {
        numbers.add(phoneUtil.format(number.number(),
                PhoneNumberFormat.NATIONAL));
    }

    return numbers;
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:26,代码来源:PhoneNumberParser.java

示例7: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatE164(String countryCode, String number) {
    try {
        PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
        int parsedCountryCode    = Integer.parseInt(countryCode);
        PhoneNumber parsedNumber = util.parse(number,
                util.getRegionCodeForCountryCode(parsedCountryCode));

        return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
    } catch (NumberParseException | NumberFormatException npe) {
        Log.w(TAG, npe);
    }

    return "+"                                                     +
            countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") +
            number.replaceAll("[^0-9]", "");
}
 
开发者ID:Securecom,项目名称:Securecom-Messaging,代码行数:17,代码来源:PhoneNumberFormatter.java

示例8: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatE164(String countryCode, String number) {
  try {
    PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
    int parsedCountryCode    = Integer.parseInt(countryCode);
    PhoneNumber parsedNumber = util.parse(number,
                                          util.getRegionCodeForCountryCode(parsedCountryCode));

    return util.format(parsedNumber, PhoneNumberUtil.PhoneNumberFormat.E164);
  } catch (NumberParseException npe) {
    Log.w("CreateAccountActivity", npe);
  } catch (NumberFormatException nfe) {
    Log.w("CreateAccountActivity", nfe);
  }

  return "+"                                                     +
      countryCode.replaceAll("[^0-9]", "").replaceAll("^0*", "") +
      number.replaceAll("[^0-9]", "");
}
 
开发者ID:Securecom,项目名称:Securecom-Text,代码行数:19,代码来源:PhoneNumberFormatter.java

示例9: getPhoneNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
/**
 * 解析手机号和电话号码
 * @param phone	需要解析的号码
 * @param defaultRegion 默认为CN
 * @return
 * @throws NumberParseException
 */
public static Map<String, String> getPhoneNumber(String phone, String defaultRegion) throws NumberParseException
{
	Map<String, String> phones = new LinkedHashMap<String, String>();
	
	if (null == defaultRegion)
	{
		defaultRegion = "CN";
	}
	
	PhoneNumber phoneNumber = phoneNumberUtil.parse(phone, defaultRegion);
	boolean isvalidNumber = phoneNumberUtil.isValidNumber(phoneNumber);		
	
	phones.put(IS_VALID_NUMBER, String.valueOf(isvalidNumber));
	phones.put(COUNTRY_CODE, String.valueOf(phoneNumber.getCountryCode()));
	phones.put(NATIONAL_NUMBER, String.valueOf(phoneNumber.getNationalNumber()));
	phones.put(E164_NUMBER, isvalidNumber ? phoneNumberUtil.format(phoneNumber, PhoneNumberFormat.E164) : "invalid");
	phones.put(NUMBER_TYPE, phoneNumberUtil.getNumberType(phoneNumber).name());
	return phones;
}
 
开发者ID:pengjieran,项目名称:OpenTools,代码行数:27,代码来源:PhoneUtil.java

示例10: E164PhoneNumberWithExtension

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
/**
 * Creates a instance from the given PhoneNumber
 * @param prototype The PhoneNumber to construct the instance from
 */
public E164PhoneNumberWithExtension(Phonenumber.PhoneNumber prototype) {

    StringBuilder e164Builder = new StringBuilder();
    PHONE_NUMBER_UTIL.format(prototype, PhoneNumberFormat.E164, e164Builder);
    
	try {
        this.number = PHONE_NUMBER_UTIL.parse(e164Builder.toString(), "GB");
    } catch (NumberParseException e) {
        throw new PhoneNumberParseException(
                EX_PARSE_MSG_PREFIX + prototype.getNationalNumber() +"}", e);
    }
	
	if (prototype.hasExtension()) {
		this.number.setExtension(prototype.getExtension());
	}
}
 
开发者ID:JadiraOrg,项目名称:jadira,代码行数:21,代码来源:E164PhoneNumberWithExtension.java

示例11: getUnderlyingPhoneNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
/**
 * Returns the underlying LibPhoneNumber {@link Phonenumber.PhoneNumber} instance. 
 * To preserve the immutability of E164PhoneNumber, a copy is made.
 * @return The underlying PhoneNumber instance
 */
public Phonenumber.PhoneNumber getUnderlyingPhoneNumber() {
    
	Phonenumber.PhoneNumber copy;
	
    StringBuilder e164Builder = new StringBuilder();
    PHONE_NUMBER_UTIL.format(number, PhoneNumberFormat.E164, e164Builder);
    
	try {
        copy = PHONE_NUMBER_UTIL.parse(e164Builder.toString(), "GB");
    } catch (NumberParseException e) {
        throw new PhoneNumberParseException(
                EX_PARSE_MSG_PREFIX + number.getNationalNumber() +"}", e);
    }
	
	if (number.hasExtension()) {
		copy.setExtension(number.getExtension());
	}
	return copy;
}
 
开发者ID:JadiraOrg,项目名称:jadira,代码行数:25,代码来源:E164PhoneNumberWithExtension.java

示例12: formatNumberInternational

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatNumberInternational(String number) {
  try {
    PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
    PhoneNumber parsedNumber = util.parse(number, null);
    return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
  } catch (NumberParseException e) {
    Log.w(TAG, e);
    return number;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:11,代码来源:PhoneNumberFormatter.java

示例13: formatNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatNumber(String number, String localNumber)
      throws InvalidNumberException
  {
    if (number == null) {
      throw new InvalidNumberException("Null String passed as number.");
    }

    if (number.contains("@")) {
      throw new InvalidNumberException("Possible attempt to use email address.");
    }

    number = number.replaceAll("[^0-9+]", "");

    if (number.length() == 0) {
      throw new InvalidNumberException("No valid characters found.");
    }

//    if (number.charAt(0) == '+')
//      return number;

    try {
      PhoneNumberUtil util          = PhoneNumberUtil.getInstance();
      PhoneNumber localNumberObject = util.parse(localNumber, null);

      String localCountryCode       = util.getRegionCodeForNumber(localNumberObject);
      Log.w(TAG, "Got local CC: " + localCountryCode);

      PhoneNumber numberObject      = util.parse(number, localCountryCode);
      return util.format(numberObject, PhoneNumberFormat.E164);
    } catch (NumberParseException e) {
      Log.w(TAG, e);
      return impreciseFormatNumber(number, localNumber);
    }
  }
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:35,代码来源:PhoneNumberFormatter.java

示例14: getInternationalFormatFromE164

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String getInternationalFormatFromE164(String e164number) {
  try {
    PhoneNumberUtil util     = PhoneNumberUtil.getInstance();
    PhoneNumber parsedNumber = util.parse(e164number, null);
    return util.format(parsedNumber, PhoneNumberFormat.INTERNATIONAL);
  } catch (NumberParseException e) {
    Log.w(TAG, e);
    return e164number;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:11,代码来源:PhoneNumberFormatter.java

示例15: formatNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat; //导入依赖的package包/类
public static String formatNumber(String number, String localNumber)
    throws InvalidNumberException
{
  if (number.contains("@")) {
    throw new InvalidNumberException("Possible attempt to use email address.");
  }

  number = number.replaceAll("[^0-9+]", "");

  if (number.length() == 0) {
    throw new InvalidNumberException("No valid characters found.");
  }

  if (number.charAt(0) == '+')
    return number;

  try {
    PhoneNumberUtil util          = PhoneNumberUtil.getInstance();
    PhoneNumber localNumberObject = util.parse(localNumber, null);

    String localCountryCode       = util.getRegionCodeForNumber(localNumberObject);
    Log.w(TAG, "Got local CC: " + localCountryCode);

    PhoneNumber numberObject      = util.parse(number, localCountryCode);
    return util.format(numberObject, PhoneNumberFormat.E164);
  } catch (NumberParseException e) {
    Log.w(TAG, e);
    return impreciseFormatNumber(number, localNumber);
  }
}
 
开发者ID:redcracker,项目名称:TextSecure,代码行数:31,代码来源:PhoneNumberFormatter.java


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