Android Question Get Phone Contacts Number

Douglas Farias

Expert
Licensed User
Longtime User
hi all, its my first time with contacts *-*
how can i get a list of contacts only name and numbers?

i have many contacts without numbers *-* how can i make a list name/number only if contacts have a number?

and later get this list how can i edit one contact?
 
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
yes already done!

here is the my code if help someone

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim cu As ContactsUtils
End Sub

Sub Globals
    Dim lstContacts As ListView
    Dim ImageView1 As ImageView
    Dim EditText1 As EditText
    Private Button1 As Button
    Private valor As Int
    Dim p As Contacts2
    p
End Sub

Sub Activity_Create(FirstTime As Boolean)

    If FirstTime Then
        cu.Initialize
    End If
    Activity.LoadLayout("1")

    For Each c As cuContact In cu.FindContactsByPhone("", False, False)
        For Each phone As cuPhone In cu.GetPhones(c.Id)
            lstContacts.AddTwoLines2(c.DisplayName,  phone.Number, c)
        Next
    Next
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub lstContacts_ItemClick (Position As Int, Value As Object)
    Dim c As cuContact = Value
    Dim sb As StringBuilder
    sb.Initialize
    For Each phone As cuPhone In cu.GetPhones(c.Id)
        sb.Append(phone.Number)
    Next
    Log(c.Id)
    valor = c.Id
    EditText1.Text = sb.ToString
End Sub

Sub lstContacts_ItemLongClick (Position As Int, Value As Object)
End Sub

Sub Button1_Click
    cu.AddPhone(valor, EditText1.Text, "mobile")
End Sub


but i dont find in the forum how to edit one contact *-*
how can i? i need remove and add or have a option only to set new number?
 
Last edited:
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Look for ContactUtils samples by Erel in the forum, you can edit a contact without deleting the existing and creating a new one.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…