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

The following examples show how to use android.telephony.PhoneNumberUtils#isWellFormedSmsAddress() . 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: RecipientsEditor.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidAddress(String number, boolean isMms) {
    /*if (isMms) {
        return MessageUtils.isValidMmsAddress(number);
    } else {*/
        // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid
        // GSM SMS address. If the address contains a dialable char, it considers it a well
        // formed SMS addr. CDMA doesn't work that way and has a different parser for SMS
        // address (see CdmaSmsAddress.parse(String address)). We should definitely fix this!!!
    return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
 
Example 2
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 3
Source File: RecipientsFormatter.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private static String parseRecipient(String recipient) throws RecipientFormattingException {
  recipient = recipient.trim();

  if ((recipient.indexOf('<') != -1) && (recipient.indexOf('>') != -1))
    return parseBracketedNumber(recipient);

  if (PhoneNumberUtils.isWellFormedSmsAddress(recipient))
    return recipient;

  throw new RecipientFormattingException("Recipient: " + recipient + " is badly formatted.");
}
 
Example 4
Source File: RecipientsFormatter.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private static String parseBracketedNumber(String recipient) throws RecipientFormattingException {
  int begin    = recipient.indexOf('<');
  int end      = recipient.indexOf('>');
  String value = recipient.substring(begin + 1, end);

  if (PhoneNumberUtils.isWellFormedSmsAddress(value))
    return value;
  else
    throw new RecipientFormattingException("Bracketed value: " + value + " is not valid.");
}
 
Example 5
Source File: CanonicalAddressDatabase.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@VisibleForTesting
static boolean isNumberAddress(@NonNull String number) {
  if (number.contains("@"))             return false;

  final String networkNumber = PhoneNumberUtils.extractNetworkPortion(number);

  if (TextUtils.isEmpty(networkNumber)) return false;
  if (networkNumber.length() < 3)       return false;

  return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
 
Example 6
Source File: RecipientsEditor.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidAddress(String number, boolean isMms) {
    /*if (isMms) {
        return MessageUtils.isValidMmsAddress(number);
    } else {*/
        // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid
        // GSM SMS address. If the address contains a dialable char, it considers it a well
        // formed SMS addr. CDMA doesn't work that way and has a different parser for SMS
        // address (see CdmaSmsAddress.parse(String address)). We should definitely fix this!!!
    return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
 
Example 7
Source File: SmsOperationData.java    From Easer with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"SimplifiableIfStatement", "RedundantIfStatement"})
@Override
public boolean isValid() {
    if (Utils.isBlank(destination))
        return false;
    if (!PhoneNumberUtils.isWellFormedSmsAddress(destination))
        return false;
    if (Utils.isBlank(content))
        return false;
    return true;
}
 
Example 8
Source File: RecipientsFormatter.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private static String parseRecipient(String recipient) throws RecipientFormattingException {
  recipient = recipient.trim();

  if ((recipient.indexOf('<') != -1) && (recipient.indexOf('>') != -1))
    return parseBracketedNumber(recipient);

  if (PhoneNumberUtils.isWellFormedSmsAddress(recipient))
    return recipient;

  throw new RecipientFormattingException("Recipient: " + recipient + " is badly formatted.");
}
 
Example 9
Source File: RecipientsFormatter.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private static String parseBracketedNumber(String recipient) throws RecipientFormattingException {
  int begin    = recipient.indexOf('<');
  int end      = recipient.indexOf('>');
  String value = recipient.substring(begin + 1, end);

  if (PhoneNumberUtils.isWellFormedSmsAddress(value))
    return value;
  else
    throw new RecipientFormattingException("Bracketed value: " + value + " is not valid.");
}
 
Example 10
Source File: RecipientsEditor.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private boolean isValidAddress(String number, boolean isMms) {
    /*if (isMms) {
        return MessageUtils.isValidMmsAddress(number);
    } else {*/
        // TODO: PhoneNumberUtils.isWellFormedSmsAddress() only check if the number is a valid
        // GSM SMS address. If the address contains a dialable char, it considers it a well
        // formed SMS addr. CDMA doesn't work that way and has a different parser for SMS
        // address (see CdmaSmsAddress.parse(String address)). We should definitely fix this!!!
    return PhoneNumberUtils.isWellFormedSmsAddress(number);
}
 
Example 11
Source File: RecipientsFormatter.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static String parseRecipient(String recipient) throws RecipientFormattingException {
  recipient = recipient.trim();

  if ((recipient.indexOf('<') != -1) && (recipient.indexOf('>') != -1))
    return parseBracketedNumber(recipient);

  if (PhoneNumberUtils.isWellFormedSmsAddress(recipient))
    return recipient;

  throw new RecipientFormattingException("Recipient: " + recipient + " is badly formatted.");
}
 
Example 12
Source File: RecipientsFormatter.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static String parseBracketedNumber(String recipient) throws RecipientFormattingException {
  int begin    = recipient.indexOf('<');
  int end      = recipient.indexOf('>');
  String value = recipient.substring(begin + 1, end);

  if (PhoneNumberUtils.isWellFormedSmsAddress(value))
    return value;
  else
    throw new RecipientFormattingException("Bracketed value: " + value + " is not valid.");
}
 
Example 13
Source File: NumberUtil.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidSmsOrEmail(String number) {
  return PhoneNumberUtils.isWellFormedSmsAddress(number) || isValidEmail(number);
}
 
Example 14
Source File: ContactAccessor.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
/***
 * If the code below looks shitty to you, that's because it was taken
 * directly from the Android source, where shitty code is all you get.
 */

public Cursor getCursorForRecipientFilter(CharSequence constraint,
    ContentResolver mContentResolver)
{
  final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," +
                            Contacts.DISPLAY_NAME + "," +
                            Contacts.Data.IS_SUPER_PRIMARY + " DESC," +
                            Phone.TYPE;

  final String[] PROJECTION_PHONE = {
      Phone._ID,                  // 0
      Phone.CONTACT_ID,           // 1
      Phone.TYPE,                 // 2
      Phone.NUMBER,               // 3
      Phone.LABEL,                // 4
      Phone.DISPLAY_NAME,         // 5
  };

  String phone = "";
  String cons  = null;

  if (constraint != null) {
    cons = constraint.toString();

    if (RecipientsAdapter.usefulAsDigits(cons)) {
      phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
      if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
        phone = "";
      } else {
        phone = phone.trim();
      }
    }
  }
  Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
  String selection = String.format("%s=%s OR %s=%s OR %s=%s",
                                   Phone.TYPE,
                                   Phone.TYPE_MOBILE,
                                   Phone.TYPE,
                                   Phone.TYPE_WORK_MOBILE,
                                   Phone.TYPE,
                                   Phone.TYPE_MMS);

  Cursor phoneCursor = mContentResolver.query(uri,
                                              PROJECTION_PHONE,
                                              null,
                                              null,
                                              SORT_ORDER);

  if (phone.length() > 0) {
    ArrayList result = new ArrayList();
    result.add(-1);                    // ID
    result.add((long) -1);             // CONTACT_ID
    result.add(Phone.TYPE_CUSTOM);     // TYPE
    result.add(phone);                                  // NUMBER

  /*
  * The "\u00A0" keeps Phone.getDisplayLabel() from deciding
  * to display the default label ("Home") next to the transformation
  * of the letters into numbers.
  */
    result.add("\u00A0");                               // LABEL
    result.add(cons);                                   // NAME

    ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
    wrap.add(result);

    ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);

    return new MergeCursor(new Cursor[] { translated, phoneCursor });
  } else {
    return phoneCursor;
  }
}
 
Example 15
Source File: NumberUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidSmsOrEmail(String number) {
  return PhoneNumberUtils.isWellFormedSmsAddress(number) || isValidEmail(number);
}
 
Example 16
Source File: NumberUtil.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidSmsOrEmail(String number) {
  return PhoneNumberUtils.isWellFormedSmsAddress(number) || isValidEmail(number);
}
 
Example 17
Source File: NumberUtil.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isValidSmsOrEmailOrGroup(String number) {
  return PhoneNumberUtils.isWellFormedSmsAddress(number) ||
      isValidEmail(number);
}
 
Example 18
Source File: ContactAccessor.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
/***
 * If the code below looks shitty to you, that's because it was taken
 * directly from the Android source, where shitty code is all you get.
 */

public Cursor getCursorForRecipientFilter(CharSequence constraint,
    ContentResolver mContentResolver)
{
  final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," +
                            Contacts.DISPLAY_NAME + "," +
                            Contacts.Data.IS_SUPER_PRIMARY + " DESC," +
                            Phone.TYPE;

  final String[] PROJECTION_PHONE = {
      Phone._ID,                  // 0
      Phone.CONTACT_ID,           // 1
      Phone.TYPE,                 // 2
      Phone.NUMBER,               // 3
      Phone.LABEL,                // 4
      Phone.DISPLAY_NAME,         // 5
  };

  String phone = "";
  String cons  = null;

  if (constraint != null) {
    cons = constraint.toString();

    if (RecipientsAdapter.usefulAsDigits(cons)) {
      phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons);
      if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) {
        phone = "";
      } else {
        phone = phone.trim();
      }
    }
  }
  Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons));
  String selection = String.format("%s=%s OR %s=%s OR %s=%s",
                                   Phone.TYPE,
                                   Phone.TYPE_MOBILE,
                                   Phone.TYPE,
                                   Phone.TYPE_WORK_MOBILE,
                                   Phone.TYPE,
                                   Phone.TYPE_MMS);

  Cursor phoneCursor = mContentResolver.query(uri,
                                              PROJECTION_PHONE,
                                              null,
                                              null,
                                              SORT_ORDER);

  if (phone.length() > 0) {
    ArrayList result = new ArrayList();
    result.add(Integer.valueOf(-1));                    // ID
    result.add(Long.valueOf(-1));                       // CONTACT_ID
    result.add(Integer.valueOf(Phone.TYPE_CUSTOM));     // TYPE
    result.add(phone);                                  // NUMBER

  /*
  * The "\u00A0" keeps Phone.getDisplayLabel() from deciding
  * to display the default label ("Home") next to the transformation
  * of the letters into numbers.
  */
    result.add("\u00A0");                               // LABEL
    result.add(cons);                                   // NAME

    ArrayList<ArrayList> wrap = new ArrayList<ArrayList>();
    wrap.add(result);

    ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap);

    return new MergeCursor(new Cursor[] { translated, phoneCursor });
  } else {
    return phoneCursor;
  }
}