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


Java NumberParseException類代碼示例

本文整理匯總了Java中com.google.i18n.phonenumbers.NumberParseException的典型用法代碼示例。如果您正苦於以下問題:Java NumberParseException類的具體用法?Java NumberParseException怎麽用?Java NumberParseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NumberParseException類屬於com.google.i18n.phonenumbers包,在下文中一共展示了NumberParseException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendOTPNumber

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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);
		}
	}
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:18,代碼來源:SignIn.java

示例2: isShortCode

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
public static boolean isShortCode(@NonNull String localNumber, @NonNull String number) {
  try {
    PhoneNumberUtil         util              = PhoneNumberUtil.getInstance();
    Phonenumber.PhoneNumber localNumberObject = util.parse(localNumber, null);
    String                  localCountryCode  = util.getRegionCodeForNumber(localNumberObject);
    String                  bareNumber        = number.replaceAll("[^0-9+]", "");

    // libphonenumber doesn't seem to be correct for Germany and Finland
    if (bareNumber.length() <= 6 && ("DE".equals(localCountryCode) || "FI".equals(localCountryCode) || "SK".equals(localCountryCode))) {
      return true;
    }

    // libphonenumber seems incorrect for Russia and a few other countries with 4 digit short codes.
    if (bareNumber.length() <= 4 && !SHORT_COUNTRIES.contains(localCountryCode)) {
      return true;
    }

    Phonenumber.PhoneNumber shortCode = util.parse(number, localCountryCode);
    return ShortNumberInfo.getInstance().isPossibleShortNumberForRegion(shortCode, localCountryCode);
  } catch (NumberParseException e) {
    Log.w(TAG, e);
    return false;
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:25,代碼來源:ShortCodeUtil.java

示例3: toInternationalFormat

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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;
   
}
 
開發者ID:peterjurkovic,項目名稱:travel-agency,代碼行數:17,代碼來源:PhoneUtils.java

示例4: getUserParams

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
private UserParams getUserParams(final Context context, final String name, final String number, String ISOCode, File profileImage)
        throws NumberParseException {
    final HyperTrackLiveUser user = this.onboardingManager.getUser();

    // Update Country Code from device's current location
    if (!HTTextUtils.isEmpty(ISOCode))
        user.setCountryCode(ISOCode);

    String encodedImage = null;
    // Set user's profile image
    if (profileImage != null && profileImage.length() > 0) {
        user.setPhotoImage(profileImage);
        byte[] bytes = convertFiletoByteArray(profileImage);
        if (bytes != null && bytes.length > 0)
            encodedImage = Base64.encodeToString(bytes, Base64.DEFAULT);
    }

    HyperTrackLiveUser.setHyperTrackLiveUser(context);

    String phoneNumber = user.getInternationalNumber(number);
    return new UserParams()
            .setName(name)
            .setPhone(phoneNumber)
            .setPhoto(encodedImage)
            .setLookupId(phoneNumber);
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:27,代碼來源:ProfilePresenter.java

示例5: initializeNumber

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
private void initializeNumber() {
  PhoneNumberUtil numberUtil  = PhoneNumberUtil.getInstance();
  String          localNumber = Util.getDeviceE164Number(this);

  try {
    if (!TextUtils.isEmpty(localNumber)) {
      Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);

      if (localNumberObject != null) {
        this.countryCode.setText(String.valueOf(localNumberObject.getCountryCode()));
        this.number.setText(String.valueOf(localNumberObject.getNationalNumber()));
      }
    } else {
      String simCountryIso = Util.getSimCountryIso(this);

      if (!TextUtils.isEmpty(simCountryIso)) {
        this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso)+"");
      }
    }
  } catch (NumberParseException npe) {
    Log.w(TAG, npe);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:24,代碼來源:RegistrationActivity.java

示例6: formatE164

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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

示例7: updateContactName

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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

示例8: parseNumber

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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;
	}
}
 
開發者ID:JK-River,項目名稱:RobotServer,代碼行數:21,代碼來源:PhoneNumberUtils.java

示例9: toMsisdn

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
private void toMsisdn(BackendAuthResult result, String phoneNumber) {
    if (StringUtils.isBlank(phoneNumber)) {
        return;
    }

    try {
        String number = phoneUtil.format(
                phoneUtil.parse(
                        phoneNumber,
                        null // No default region
                ),
                PhoneNumberUtil.PhoneNumberFormat.E164
        ).substring(1); // We want without the leading +
        result.withThreePid(new ThreePid(ThreePidMedium.PhoneNumber.getId(), number));
    } catch (NumberParseException e) {
        log.warn("Invalid phone number: {}", phoneNumber);
    }
}
 
開發者ID:kamax-io,項目名稱:mxisd,代碼行數:19,代碼來源:GoogleFirebaseAuthenticator.java

示例10: validatePhone

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:24,代碼來源:ProjectUtil.java

示例11: isValidMobileNumber

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
public Boolean isValidMobileNumber(String mobileNumber, String countryISO) {
    Boolean isValidNumber = false;

    try {
        Phonenumber.PhoneNumber mNumber = phoneNumberUtil.parse(mobileNumber, countryISO);
        if ("MX".equalsIgnoreCase(countryISO)) { // Temporary hardcode for mexico due to libphonenumber issue
        	isValidNumber = phoneNumberUtil.isValidNumber(mNumber);
        } else {
        	isValidNumber = phoneNumberUtil.isValidNumber(mNumber) &&
                    ( PhoneNumberUtil.PhoneNumberType.MOBILE.equals(phoneNumberUtil.getNumberType(mNumber)) ||
                      PhoneNumberUtil.PhoneNumberType.FIXED_LINE_OR_MOBILE.equals(phoneNumberUtil.getNumberType(mNumber))
                    );
        }
        
    } catch (NumberParseException ex) {
        myLog.debug(ex.getMessage(), ex);
    }

    return isValidNumber;
}
 
開發者ID:SECQME,項目名稱:watchoverme-server,代碼行數:21,代碼來源:DefaultMobileNumberUtil.java

示例12: isValidNumberInE164Format

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
public boolean isValidNumberInE164Format(String number) {
  final PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();

  Phonenumber.PhoneNumber phoneNumber = null;

  int country;
  try {
    phoneNumber = phoneNumberUtil.parse(number, "");
    country = phoneNumber.getCountryCode();
  } catch (NumberParseException e) {
    e.printStackTrace();
    return false;
  }

  return phoneNumberUtil.isValidNumberForRegion(phoneNumber,
      phoneNumberUtil.getRegionCodeForCountryCode(country));
}
 
開發者ID:Aptoide,項目名稱:aptoide-client-v8,代碼行數:18,代碼來源:ContactUtils.java

示例13: initializeNumber

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
private void initializeNumber() {
  PhoneNumberUtil numberUtil  = PhoneNumberUtil.getInstance();
  String          localNumber = Util.getDeviceE164Number(this);

  try {
    if (!TextUtils.isEmpty(localNumber)) {
      Phonenumber.PhoneNumber localNumberObject = numberUtil.parse(localNumber, null);

      if (localNumberObject != null) {
        this.countryCode.setText(localNumberObject.getCountryCode()+"");
        this.number.setText(localNumberObject.getNationalNumber()+"");
      }
    } else {
      String simCountryIso = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).getSimCountryIso();

      if (!TextUtils.isEmpty(simCountryIso)) {
        this.countryCode.setText(numberUtil.getCountryCodeForRegion(simCountryIso.toUpperCase())+"");
      }
    }
  } catch (NumberParseException npe) {
    Log.w("CreateAccountActivity", npe);
  }
}
 
開發者ID:redcracker,項目名稱:TextSecure,代碼行數:24,代碼來源:RegistrationActivity.java

示例14: convertToE164

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的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

示例15: sendTestSms

import com.google.i18n.phonenumbers.NumberParseException; //導入依賴的package包/類
@ApiMethod(
        name = "sendTestSms",
        path = "sendTestSms",
        httpMethod = ApiMethod.HttpMethod.POST
)
@SuppressWarnings("unused")
public StringWrapperObject sendTestSms(
        // final HttpServletRequest httpServletRequest,
        final User googleUser,
        final @Named("phoneNumber") String phoneNumber,
        final @Named("smsMessage") String smsMessage
        // see: https://cloud.google.com/appengine/docs/java/endpoints/exceptions
) throws UnauthorizedException, BadRequestException, NotFoundException, NumberParseException,
        IllegalArgumentException, TwilioRestException {

    /* --- Check authorization: */
    CryptonomicaUser cryptonomicaUser = UserTools.ensureCryptonomicaOfficer(googleUser);

    /* --- Send SMS */
    Message message = TwilioUtils.sendSms(phoneNumber, smsMessage);

    return new StringWrapperObject(message.toJSON());

}
 
開發者ID:Cryptonomica,項目名稱:cryptonomica,代碼行數:25,代碼來源:OnlineVerificationAPI.java


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