Android Question Same Contact name with multiple phone numbers using ContactSearcher

Discussion in 'Android Questions' started by Azam Memon, Jul 26, 2019.

  1. Azam Memon

    Azam Memon Member Licensed User

    Hi,

    I am using ContactSearcher to find phone contacts, my phone has stored multiple phone numbers in one contact profile, like Home phone, Mobile, Office phone etc.

    When using ContactSearcher, it shows same phone number under all contacts with same names like contact profile with my name is one but has 3 numbers, it is showing 3 entries with the same name and same phone number in all three (see attachment).

    Any solution to display different phone numbers under the same display name?
     

    Attached Files:

  2. asales

    asales Well-Known Member Licensed User

    The screen is from your app? After you import the contacts?
    How do you do the import?
    I think you need to store the numbers in variables (phone_home, phone_mobile, phone_work) and clear this variables before the start a new import.
     
  3. Azam Memon

    Azam Memon Member Licensed User

    Yes, the screenshot is from my App.

    I am importing contacts using contactUtils library:

    Code:
    For Each c As cuContact In cu.FindAllContacts(True)
                    Sleep(
    0)
                    
    Dim it As Item
                    it.Title = c.DisplayName
                    it.SearchText = c.DisplayName.ToLowerCase
                    
    For Each phone As cuPhone In cu.GetPhones(c.Id)
                        it.Text = 
    phone.Number
                        
    Log("title: " & it.Title & ", phone: " & it.Text)
                        it.SearchText = c.DisplayName.ToLowerCase  & 
    " " & galaxy.CleanPhone(phone.Number)
                        it.Value = c
                        contacts_list.Add(it)
                    
    Next
                    
                
    Next
                index = menu_search1.SetItems(contacts_list)
    The logs show the different numbers with same display name as:

    Code:
    title: Azam Rafique Memon, phone: +92 333 2761402
    title: Azam Rafique Memon, 
    phone: +86 186 2110 6323
    title: Azam Rafique Memon, 
    phone: +92 347 3412887
    But on runtime, the contact numbers are same under display name, so the issue seems to be within ContactSearcher, which uses maps to store data.
     
  4. Brandsum

    Brandsum Active Member Licensed User

    Try this
    Code:
    For Each c As cuContact In cu.FindAllContacts(True)
            Sleep(
    0)
            
    Dim it As item
            it.Title = c.DisplayName
            
    For Each phone As cuPhone In cu.GetPhones(c.Id)
                
    If it.Text = "" Then
                    it.Text = 
    phone.Number
                
    Else
                    it.Text = it.Text & 
    "," & phone.Number
                
    End If
            
    Next
            it.SearchText = c.DisplayName.ToLowerCase  & 
    " " & it.Text
            it.Value = c
            contacts_list.Add(it)
                    
        
    Next
        index = menu_search1.SetItems(contacts_list)
     
  5. Azam Memon

    Azam Memon Member Licensed User

    This shows all phone numbers together within a single entry (See attachment).

    I want to display a separate entry for each of contact number, to enable users to send a message to a specific user on one specified number from his multiple contact numbers.
     

    Attached Files:

  6. Brandsum

    Brandsum Active Member Licensed User

    Then your code was ok just dim item inside second loop like this
    Code:
    For Each c As cuContact In cu.FindAllContacts(True)
            Sleep(
    0)
            
    For Each phone As cuPhone In cu.GetPhones(c.Id)
                
    Dim it As Item
                it.Title = c.DisplayName
                it.Text = 
    phone.Number
                it.SearchText = c.DisplayName.ToLowerCase  & 
    " " & galaxy.CleanPhone(phone.Number)
                it.Value = c
                contacts_list.Add(it)
            
    Next
                    
        
    Next
        index = menu_search1.SetItems(contacts_list)
     
    Erel and Azam Memon like this.
  7. Azam Memon

    Azam Memon Member Licensed User

    Great, this worked.
     
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