Android Question Native Contacts / PhoneBook

FabioG

Active Member
Licensed User
Longtime User
Hello to all,

I need to be able to open the native Android phone book, select one of the numbers in the contact and set it in a variable

how can I do this?

I used Contacts and Contacts2 but I need to use the native address book

Thanks
Fabio
 

DonManfred

Expert
Licensed User
Longtime User
Have you tried this?
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
I recommend you to use ContactsUtils. It is possible to open the standard phone book however the result varies between different devices.

Hello Erel,

thanks for your reply

I have no idea how to do it
could you help me with an example?
I need to use the Android address book
 
Upvote 0

FabioG

Active Member
Licensed User
Longtime User
I'm not familiar with any library that opens the standard contacts book. It is quite simple to open the standard phonebook with an intent.
I did look into it in the past however the results were not satisfying / reliable enough.

Thanks again Erel!

you can suggest me the code to open the phone book with intent?
 
Upvote 0

konisek

Member
Licensed User
Longtime User
You can use a phonebook
B4X:
Sub Button1_Click
    'Dim Contacts As Contacts
    'Dim list1 As List
    list1 = Contacts.GetAll
    Dim listOfNames As List
    listOfNames.Initialize
    'Create a list with the contacts names
   
    For i = 0 To list1.Size - 1
        Dim c As Contact
        c = list1.Get(i) 'fetch the Contact from the original list
        If c.DisplayName.IndexOf("@") = -1 Then 'remove email, keep only contacts
            listOfNames.Add(c.DisplayName)
        End If
    Next
       
    listOfNames.Sort (True)
       
    Dim res As Int
    res = InputList(listOfNames, "Choose contact", -1)
    If res <> DialogResponse.CANCEL Then
        Dim name As String
        name = listOfNames.Get(res)
       
        'Dim c As Contact
        'find the original contact based on the chosen name
        For i = 0 To list1.Size
            c = list1.Get(i)
            If c.DisplayName = name Then Exit
        Next
        'Msgbox(c.GetPhones, "id")
                       
            Dim m As Map
            m = c.GetPhones

        'Dim cisla As List
        cisla.Initialize
            For index = 0 To m.Size-1
                cisla.Add(m.GetKeyAt(index))
            Next
       
        Dim res2 As Int
        res2 = InputList(cisla, "cisla", -1)
        EditText1.Text = cisla.Get(res2)
   

    End If
End Sub

Or, you can use a serch
B4X:
Sub button2_click
list1 = Contacts.GetAll

listofcontacts = Contacts.FindByName(edittext2.Text , False)
list2.Initialize
For i = 0 To listofcontacts.Size - 1

    Dim Contact As Contact
    Contact = listofcontacts.Get(i)

list2.Add(Contact.DisplayName)
Next


Dim res As Int
    res = InputList(list2, "Choose contact", -1)
    If res <> DialogResponse.CANCEL Then
        Dim name As String
        name = list2.Get(res)

        'find the original contact based on the chosen name
        For i = 0 To list1.Size - 1
            Contact = list1.Get(i)
            If Contact.DisplayName = name Then Exit
        Next
        Msgbox(Contact.GetPhones, "id")


    End If

            Dim m As Map
            m = Contact.GetPhones

        'Dim cisla As List
        cisla.Initialize
            For index = 0 To m.Size-1
                cisla.Add(m.GetKeyAt(index))
            Next
       
        Dim res2 As Int
        res2 = InputList(cisla, "cisla", -1)
        EditText1.Text = cisla.Get(res2)

End Sub
 
Upvote 0
Top