本文整理汇总了Java中com.google.i18n.phonenumbers.Phonenumber.PhoneNumber类的典型用法代码示例。如果您正苦于以下问题:Java PhoneNumber类的具体用法?Java PhoneNumber怎么用?Java PhoneNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PhoneNumber类属于com.google.i18n.phonenumbers.Phonenumber包,在下文中一共展示了PhoneNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendOTPNumber
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
private void sendOTPNumber(){
if(checkNull()){
PhoneNumberUtil util = PhoneNumberUtil.getInstance();
// assuming you only a button in your layout...
boolean isAuthentic = false;
try {
PhoneNumber number = util.parse(countryPrefix + edtMobile.getText().toString().trim(), countryIso);
isAuthentic = true;
} catch (NumberParseException e) {
e.printStackTrace();
}
if (isAuthentic) {
comman.hideSoftKeyBoard(context, edtMobile);
createJson(edtMobile.getText().toString().trim(), countryPrefix, countryName);
}
}
}
示例2: toInternationalFormat
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static String toInternationalFormat(String number) throws NumberParseException {
if (!isValidNumber(number)) {
throw new NumberParseException(ErrorType.NOT_A_NUMBER, number + " is not a valid number");
}
number = number.replaceAll("\\s+", "");
if (!number.contains("+")) {
number = "+" + number;
}
PhoneNumber phoneNmber = PhoneNumberUtil.getInstance().parse(number, null);
String nationalNumber = String.valueOf(phoneNmber.getNationalNumber());
String countryCode = String.valueOf(phoneNmber.getCountryCode());
String leadingZero = phoneNmber.hasItalianLeadingZero() ? "0" : "";
return countryCode + leadingZero + nationalNumber;
}
示例3: formatE164
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的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]", "");
}
示例4: updateContactName
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的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);
}
示例5: parseNumber
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static String parseNumber(String number) {
if (!Pattern.matches(PHONE_NUMBER_REGEX, number)) {
LOGGER.error("invalid phone number. {}", number);
return null;
}
if (Pattern.matches(SHORT_PHONE_NUMBER_REGEX, number)) {
number = "+86" + number;
}
try {
PhoneNumber phoneNumber = PN_Util.parse(number, "CH");
if (PN_Util.isValidNumber(phoneNumber)) {
return String.valueOf(phoneNumber.getNationalNumber());
}
LOGGER.error("invalid phone number. {}", number);
return null;
} catch (NumberParseException e) {
LOGGER.error("invalid phone number. {}", number);
return null;
}
}
示例6: validatePhone
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static boolean validatePhone(String phone, String countryCode) {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
if (!ProjectUtil.isStringNullOREmpty(countryCode) && (countryCode.charAt(0) != '+')) {
countryCode = "+" + countryCode;
}
try {
if (isStringNullOREmpty(countryCode)) {
countryCode = PropertiesCache.getInstance().getProperty("sunbird_default_country_code");
}
phone = countryCode + "-" + phone;
PhoneNumber numberProto = phoneUtil.parse(phone, "");
// phoneUtil.isValidNumber(number)
ProjectLogger.log("Number is of region - " + numberProto.getCountryCode() + " "
+ phoneUtil.getRegionCodeForNumber(numberProto));
ProjectLogger.log("Is the input number valid - "
+ (phoneUtil.isValidNumber(numberProto) == true ? "Yes" : "No"));
return phoneUtil.isValidNumber(numberProto);
} catch (NumberParseException e) {
ProjectLogger.log("Exception occurred while validating phone number : ", e);
ProjectLogger.log(phone + "this phone no. is not a valid one.");
}
return false;
}
示例7: convertPhoneNumberToE164
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的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;
}
示例8: format
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static String format( String phone, String region, int style )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = utl_.format( num, format_to_enum( style ) );
}
catch ( Exception e )
{
val = phone;
}
return val;
}
示例9: get_region_code
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static String get_region_code( String phone )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, "" );
val = utl_.getRegionCodeForNumber( num );
}
catch ( Exception e )
{
val = "";
}
return val;
}
示例10: is_valid_for_region
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static boolean is_valid_for_region( String phone, String region )
{
boolean ok = false;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
ok = utl_.isValidNumberForRegion( num, region );
}
catch ( Exception e )
{
ok = false;
}
return ok;
}
示例11: get_type
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static int get_type( String phone, String region )
{
int val = TYPE_UNKNOWN;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = enum_to_type( utl_.getNumberType( num ) );
}
catch ( Exception e )
{
val = TYPE_UNKNOWN;
}
return val;
}
示例12: get_countrycode
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static int get_countrycode( String phone, String region )
{
int val = 0;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = num.getCountryCode();
}
catch ( Exception e )
{
val = 0;
}
return val;
}
示例13: get_national
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static long get_national( String phone, String region )
{
long val = 0;
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, region );
val = num.getNationalNumber();
}
catch ( Exception e )
{
val = 0;
}
return val;
}
示例14: truncate_number
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的package包/类
public static String truncate_number( String phone )
{
String val = "";
try
{
Phonenumber.PhoneNumber num = utl_.parse( phone, "" );
val = format( phone, "", FORMAT_INTERNATIONAL );
}
catch ( Exception e )
{
val = phone;
}
return val;
}
示例15: isValid
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; //导入依赖的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));
}