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


Java PhoneNumberUtil.format方法代码示例

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


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

示例1: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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: updateContactName

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
private void updateContactName(String phone) {
    mPhoneContactNumber = phone;
    mPhoneContactName = phone;

    try {
        // phone must begin with '+'
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumber numberProto = phoneUtil.parse(phone, "");
        String countryCode = "+" + String.valueOf(numberProto.getCountryCode());
        String formatedPhoneNumber = phoneUtil.format(numberProto, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
        Contact contact = AppManager.getInstance().getPhoneContactFromContacts(phoneContacts, phone, countryCode);
        if (contact == null) {
            mPhoneContactName = formatedPhoneNumber;
        } else {
            mPhoneContactName = contact.getName();
        }
    } catch (NumberParseException e) {
        System.err.println("NumberParseException was thrown: " + e.toString());
    }

    tvUsername.setText(mPhoneContactName);
}
 
开发者ID:AppHero2,项目名称:Raffler-Android,代码行数:23,代码来源:ChatListRecyclerViewAdapter.java

示例3: convertPhoneNumberToE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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

示例4: convertToE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/**
 * Helper method to convert a phone number to E164 format as expected by the server
 * (+1XXXXXXXXXX)
 *
 * @param raw_phone_number The unformatted phone number as stored by the system contacts
 *                         application
 * @return String storing the E164-formatted phone number
 */
public static String convertToE164(String raw_phone_number) {
    PhoneNumberUtil phone_util = PhoneNumberUtil.getInstance();
    try {
        Phonenumber.PhoneNumber phone_proto = phone_util.parse(raw_phone_number,
                Constants.DEFAULT_PHONE_REGION);
        if (phone_util.isValidNumber(phone_proto)) {
            return phone_util.format(phone_proto, PhoneNumberUtil.PhoneNumberFormat.E164);
        } else {
            Log.d(TAG, "Invalid number");
            return null;
        }
    } catch (NumberParseException e) {
        Log.d(TAG, "Error parsing phone number");
        return null;
    }
}
 
开发者ID:whereuat,项目名称:whereuat-android,代码行数:25,代码来源:PhonebookUtils.java

示例5: 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

示例6: getDisplay

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/**
 * Gets a representation of the URN for display
 */
public String getDisplay(Org org, boolean full) {
    if (org.isAnon()) {
        return ANON_MASK;
    }

    if (m_scheme == Scheme.TEL && !full) {
        // if we don't want a full tell, see if we can show the national format instead
        try {
            if (StringUtils.isNotEmpty(m_path) && m_path.charAt(0) == '+') {
                PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
                return phoneUtil.format(phoneUtil.parse(m_path, null), PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
            }
        }
        catch (Exception ignored) {}
    }

    return m_path;
}
 
开发者ID:rapidpro,项目名称:flows,代码行数:22,代码来源:ContactUrn.java

示例7: normalize

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/**
     * normalize number to E164 format. Returns null if null is provided.
     *
     * @param aNumber the phone number to normalize
     * @return e164 phone number string
     */
    public static String normalize(Context context, String aNumber) {
        if (aNumber == null) { return null; }

        PhoneNumberUtil pnu = PhoneNumberUtil.getInstance();
        Locale locale = context.getResources().getConfiguration().locale;
        String countryIso = getCurrentCountryIso(context, locale);
        try {
//            Log.d(LOGTAG, countryIso);
            String numberE164 = pnu.format(pnu.parse(aNumber, countryIso), PhoneNumberUtil.PhoneNumberFormat.E164);
//            Log.d(LOGTAG, numberE164);
            return numberE164;
        } catch (NumberParseException e) {
            Log.w(LOGTAG, "normalize caught NumberParseException: number=" + aNumber);
            return aNumber;
        }
    }
 
开发者ID:doerfli,项目名称:leavemealone,代码行数:23,代码来源:PhoneNumberHelper.java

示例8: getFormattedPhoneNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
private String getFormattedPhoneNumber() {
    String phoneNumberText = getPhoneNumberText();
    Country country = getCountry();

    String formattedPhoneNumber = null;
    Phonenumber.PhoneNumber phoneNumber;
    PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
    try {
        phoneNumber = phoneNumberUtil.parse(phoneNumberText, country.getIsoCode());
        if (phoneNumberUtil.isValidNumber(phoneNumber)) {
            formattedPhoneNumber = phoneNumberUtil.format(phoneNumber,
                    PhoneNumberUtil.PhoneNumberFormat.E164);
        }
    } catch (NumberParseException npe) {
        formattedPhoneNumber = null;
    }

    return formattedPhoneNumber;
}
 
开发者ID:arpankapoor,项目名称:VerifyMobileNumber,代码行数:20,代码来源:MainActivity.java

示例9: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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

示例10: formatE164

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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

示例11: normalizeNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public static String[] normalizeNumber(String phoneNumber, String defaultRegion) {
	PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
	PhoneNumber input;
	try {
		input = phoneUtil.parse(phoneNumber, defaultRegion.trim().toUpperCase(Locale.US));
		if (phoneUtil.isValidNumber(input)) {
			String parsedRegionCode = phoneUtil.getRegionCodeForNumber(input);
			if (parsedRegionCode != null) {
				return new String[] { phoneUtil.format(input, PhoneNumberUtil.PhoneNumberFormat.E164), parsedRegionCode };
			}
			else {
				return null;
			}
		}
		else {
			return null;
		}
	}
	catch (Exception e) {
		return null;
	}
}
 
开发者ID:delight-im,项目名称:Faceless,代码行数:23,代码来源:Global.java

示例12: convertToModel

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public String convertToModel(final String value, final Class<? extends String> targetType, final Locale locale) throws ConversionException {
    if (isNullOrEmpty(value))
        return null;

    final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    final String country = locale == null ? "RU" : locale.getCountry();
    Phonenumber.PhoneNumber phone = null;
    try {
        phone = phoneUtil.parse(value, country);
    } catch (final NumberParseException e) {
        throw new ConversionException("Неправильный формат телефона", e);
    }

    return phoneUtil.format(phone, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:18,代码来源:PhoneConverter.java

示例13: convertToPresentation

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public String convertToPresentation(final String value, final Class<? extends String> targetType, final Locale locale) throws ConversionException {
    if (isNullOrEmpty(value))
        return null;

    final PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    final String country = locale == null ? "RU" : locale.getCountry();
    Phonenumber.PhoneNumber phone = null;
    try {
        phone = phoneUtil.parse(value, country);
    } catch (final NumberParseException e) {
        throw new ConversionException("Неправильный формат телефона", e);
    }

    return phoneUtil.format(phone, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
}
 
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:18,代码来源:PhoneConverter.java

示例14: getInternationalNumber

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的package包/类
public String getInternationalNumber(String phoneNo) throws NumberParseException {
    PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
    if (HTTextUtils.isEmpty(phoneNo))
        return null;

    Phonenumber.PhoneNumber number = phoneUtil.parse(phoneNo, getCountryCode());
    return phoneUtil.format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:9,代码来源:HyperTrackLiveUser.java

示例15: formatNumberInternational

import com.google.i18n.phonenumbers.PhoneNumberUtil; //导入方法依赖的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


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