Android Question ContactsUtils.FindContactsByPhone pattern

Discussion in 'Android Questions' started by peacemaker, Feb 3, 2017.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All

    I have found that my contacts were saved sometimes without delimiters like "12345678", but sometimes with spaces and\or "-" like "123 45-678".
    And note that i did not enter these delimiters - it seems to be due to various Android versions saved contacts into the Google account such ways.

    BTW, the calls log shows all numbers all without delimiters.

    And now, when i try to .FindContactsByPhone - saved contact with number "12345678" is not found by the first time. And the calls log shows this incoming call number as unknown, without a name.

    But if to make a new call and search second time - it's found among contacts ! And calls log also shows the contact name together with this number.

    How to understand it and to be sure that delimiters are not used during finding process ?
    Last edited: Feb 3, 2017
  2. peacemaker

    peacemaker Well-Known Member Licensed User

    More over - some contacts are with "(XXX)" :(
    So, it needs to modify searching by phone number by this ContactsUtils class.
    Now it can be only by
    1) .FindAllContacts
    2) iterating cuContacts
    3) iterating cuPhones of each cuContact
    4) removing "+", " ", "-", "(", ")" in each cuPhone
    5) and only here to compare the number with needed one
    Such searching is several seconds at last, very long :(

    How to make SQL request with removing these ?
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can do something like:
    Dim possibleContacts As List = cu.FindContactsByPhone(PhoneNumber.Substring(PhoneNumber.Length - 3), FalseTrue)
    This will return all the contacts with a phone number that contains the last three digits.
    Now go over the list and find out the matches.
  4. peacemaker

    peacemaker Well-Known Member Licensed User

    Yes, Erel, thanks, but it's not universal way. It will be for sure if to select the latest one digit only firstly :)
    But no way to filter by SQL request ?
  5. Erel

    Erel Administrator Staff Member Licensed User

    This is no SQL engine there. It just looks like SQL.

    This will not help much as it will only remove a few items.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice