Java Code Examples for android.telephony.PhoneNumberUtils#isGlobalPhoneNumber()

The following examples show how to use android.telephony.PhoneNumberUtils#isGlobalPhoneNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Validate.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
public static boolean isValidPhone(String target) {
    if (target.equals("")) {
        return false;
    }
    else if(target.length()!=10){
    	return false;
    }
    else {
    	return PhoneNumberUtils.isGlobalPhoneNumber(target);
    }
}
 
Example 2
Source File: AutofillAddress.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Checks address completion status in the given profile.
 *
 * If the country code is not set or invalid, but all fields for the default locale's country
 * code are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress()
 * will use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param  profile The autofill profile containing the address information.
 * @return int     The completion status.
 */
@CompletionStatus
public static int checkAddressCompletionStatus(AutofillProfile profile) {
    int invalidFieldsCount = 0;
    int completionStatus = COMPLETE;

    if (!PhoneNumberUtils.isGlobalPhoneNumber(
                PhoneNumberUtils.stripSeparators(profile.getPhoneNumber().toString()))) {
        completionStatus = INVALID_PHONE_NUMBER;
        invalidFieldsCount++;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int fieldId : requiredFields) {
        if (fieldId == AddressField.RECIPIENT || fieldId == AddressField.COUNTRY) continue;
        if (!TextUtils.isEmpty(getProfileField(profile, fieldId))) continue;
        completionStatus = INVALID_ADDRESS;
        invalidFieldsCount++;
        break;
    }

    if (TextUtils.isEmpty(profile.getFullName())) {
        completionStatus = INVALID_RECIPIENT;
        invalidFieldsCount++;
    }

    if (invalidFieldsCount > 1) {
        completionStatus = INVALID_MULTIPLE_FIELDS;
    }

    return completionStatus;
}
 
Example 3
Source File: AutofillAddress.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Checks address completion status in the given profile.
 *
 * If the country code is not set or invalid, but all fields for the default locale's country
 * code are present, then the profile is deemed "complete." AutoflllAddress.toPaymentAddress()
 * will use the default locale to fill in a blank country code before sending the address to the
 * renderer.
 *
 * @param  profile The autofill profile containing the address information.
 * @return int     The completion status.
 */
@CompletionStatus
public static int checkAddressCompletionStatus(
        AutofillProfile profile, @CompletenessCheckType int checkType) {
    int invalidFieldsCount = 0;
    int completionStatus = COMPLETE;

    if (checkType != IGNORE_PHONE_COMPLETENESS_CHECK
            && !PhoneNumberUtils.isGlobalPhoneNumber(
                       PhoneNumberUtils.stripSeparators(profile.getPhoneNumber().toString()))) {
        completionStatus = INVALID_PHONE_NUMBER;
        invalidFieldsCount++;
    }

    List<Integer> requiredFields = AutofillProfileBridge.getRequiredAddressFields(
            AutofillAddress.getCountryCode(profile));
    for (int fieldId : requiredFields) {
        if (fieldId == AddressField.RECIPIENT || fieldId == AddressField.COUNTRY) continue;
        if (!TextUtils.isEmpty(getProfileField(profile, fieldId))) continue;
        completionStatus = INVALID_ADDRESS;
        invalidFieldsCount++;
        break;
    }

    if (TextUtils.isEmpty(profile.getFullName())) {
        completionStatus = INVALID_RECIPIENT;
        invalidFieldsCount++;
    }

    if (invalidFieldsCount > 1) {
        completionStatus = INVALID_MULTIPLE_FIELDS;
    }

    return completionStatus;
}
 
Example 4
Source File: NfcMessageUtilityImpl.java    From android-nfc-lib with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Precondition :  Telephone should not be null
 */
@Override
public NdefMessage createTel(@NotNull String telephone) throws FormatException {
    telephone = telephone.startsWith("+") ? "+" + telephone.replaceAll("\\D", "") : telephone.replaceAll("\\D", "");
    if (!PhoneNumberUtils.isGlobalPhoneNumber(telephone)) {
        throw new FormatException();
    }

    return createUriMessage(telephone, NfcPayloadHeader.TEL);
}
 
Example 5
Source File: NfcMessageUtilityImpl.java    From android-nfc-lib with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 * Precondition :  At least number should not be null
 */
@Override
public NdefMessage createSms(@NotNull String number, String message) throws FormatException {
    number = number.startsWith("+") ? "+" + number.replaceAll("\\D", "") : number.replaceAll("\\D", "");
    if (!PhoneNumberUtils.isGlobalPhoneNumber((number))) {
        throw new FormatException();
    }
    String smsPattern = "sms:" + number + "?body=" + message;
    //String externalType = "nfclab.com:smsService";
    return createUriMessage(smsPattern, NfcPayloadHeader.CUSTOM_SCHEME);
}
 
Example 6
Source File: MiscUtils.java    From caffeine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Uses androids android.telephony.PhoneNumberUtils to check if an phone number is valid.
 *
 * @param number Phone number to check
 * @return true if the <code>number</code> is a valid phone number.
 */
public final static boolean isValidPhoneNumber(String number) {
    if (number == null) {
        return false;
    } else {
        return PhoneNumberUtils.isGlobalPhoneNumber(number);
    }
}
 
Example 7
Source File: sendSMS.java    From ShellMS with GNU General Public License v3.0 5 votes vote down vote up
private Boolean isNumberValid(String contact)	{
if (contact == null)	{
	return false;
}
boolean valid1 = PhoneNumberUtils.isGlobalPhoneNumber(contact);
boolean valid2 = PhoneNumberUtils.isWellFormedSmsAddress(contact);
      return (valid1) && (valid2);
  }
 
Example 8
Source File: WeatherNumberAdapter.java    From Pigeon with MIT License 4 votes vote down vote up
private void doSendSMSTo(String phoneNumber) {
    if (PhoneNumberUtils.isGlobalPhoneNumber(phoneNumber)) {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));
        mContext.startActivity(intent);
    }
}