Android Question Same Contact name with multiple phone numbers using ContactSearcher

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?
 

Attachments

  • wechat azam.jpg
    wechat azam.jpg
    84 KB · Views: 343

asales

Expert
Licensed User
Longtime 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.
 
Upvote 0

Azam Memon

Member
Licensed User
The screen is from your app?
Yes, the screenshot is from my App.

I am importing contacts using contactUtils library:

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

B4X:
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.
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Try this
B4X:
    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)
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
I want to display a separate entry for each of contact number
Then your code was ok just dim item inside second loop like this
B4X:
    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)
 
Upvote 0
Top