Android Question Having trouble with FindContactsByPhone

Discussion in 'Android Questions' started by mmieher, Apr 23, 2015.

  1. mmieher

    mmieher Active Member Licensed User

    I am having trouble getting the FindContactsByPhone method to return anything. In the example below, I know I have the phone number in my contacts (I changed it to protect the innocent in this example) but it never returns the contact.

    Please help.

    Sub UpdateContacts

    Dim fI As String
    Dim TR As TextReader

    Dim i As Int

    Dim tEmpName As String
    Dim tCell As String
    Dim tMail As String

    Dim cu As ContactsUtils
    Dim c As cuContact
    Dim cup As cuPhone

    Dim phoneList As List

    cu.Initialize
    phoneList.Initialize


    fI = "PMC/Contacts.txt"
    TR.Initialize(File.OpenInput(File.DirRootExternal,fI))

    rLine = TR.ReadLine

    Do While rLine <> Null

    POVendRec.NumPOs = s.Right(rLine,5)

    tEmpName = s.Rtrim(s.Mid(rLine,14,30))
    tCell = s.Rtrim(s.Mid(rLine,44,15))
    tMail = s.Rtrim(s.Mid(rLine,59,45))

    Msgbox(tCell,"tCell")

    phoneList.Clear

    phoneList = cu.FindContactsByPhone("5035551212", False, True)

    Msgbox(phoneList.Size,"")

    For i = 0 To phoneList.Size - 1
    Msgbox(phoneList.get(i),"")
    Next

    rLine = TR.ReadLine

    Loop

    TR.Close


    End Sub
     
  2. mmieher

    mmieher Active Member Licensed User

    I was told to insert code as follows ...

    Code:
    Sub UpdateContacts

        
    Dim fI As String
        
    Dim TR As TextReader
       
        
    Dim i As Int
       
        
    Dim tEmpName As String
        
    Dim tCell As String
        
    Dim tMail As String
       
        
    Dim cu As ContactsUtils
        
    Dim c As cuContact
        
    Dim cup As cuPhone
       
        
    Dim phoneList As List

        cu.Initialize
        phoneList.Initialize
       
       
        fI = 
    "PMC/Contacts.txt"
        TR.Initialize(
    File.OpenInput(File.DirRootExternal,fI))
       
        rLine = TR.ReadLine
           
        
    Do While rLine <> Null
           
            POVendRec.NumPOs = s.Right(rLine,
    5)

            tEmpName = s.Rtrim(s.Mid(rLine,
    14,30))
            tCell = s.Rtrim(s.Mid(rLine,
    44,15))
            tMail = s.Rtrim(s.Mid(rLine,
    59,45))
           
            
    Msgbox(tCell,"tCell")
           
            phoneList.Clear
           
            phoneList = cu.FindContactsByPhone(
    "5035551212"FalseTrue)
           
            
    Msgbox(phoneList.Size,"")
           
            
    For i = 0 To phoneList.Size - 1
                
    Msgbox(phoneList.get(i),"")
            
    Next

            rLine = TR.ReadLine
       
        
    Loop
           
        TR.Close


    End Sub
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Try to find the specific contact record with another query and check the values returned from cu.GetPhones. Maybe the stored number is different than what you expect.
     
  4. mmieher

    mmieher Active Member Licensed User

    Thanks, Erel. You are right again (of course).

    Sometimes the numbers are stored as 5035551212, other times 503-555-1212, and also (503) 555-1212.

    Not sure how to deal with that but will think of something!

    Marc
     
  5. mmieher

    mmieher Active Member Licensed User

    Erel -- I found the SearchView util. This should solve it.

    Thanks.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You will need to "normalize" the phone numbers and remove all non-digit characters.
     
Loading...
  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