Android Question Having trouble with FindContactsByPhone

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
 

mmieher

Active Member
Licensed User
I was told to insert code as follows ...

B4X:
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
 

mmieher

Active 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.
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
 

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
Erel -- I found the SearchView util. This should solve it.

Thanks.
 
Top