Android Question [solved] Get phone number of a contact

sirjo66

Well-Known Member
Licensed User
Longtime User
Hi,
I need to get the phone number of a contact.
I use wmContactsUtils version 1.2 by @walt61 from here: wmContactsUtils

I use this code:
B4X:
Private cu As wmContactsUtils

cu.Initialize
Dim lst As List = cu.FindContactsByName("User Name", True, False)
If lst.Size > 0 Then
    Dim Number As String = lst.Get(0).As(Contact).PhoneNumber
End If

But the error on highlight line is:
java.lang.RuntimeException: Field: PhoneNumber not found in: sjs.sendmsg.wmcontactsutils$_cucontact

I tried also with
B4X:
Dim Numbers As Map = lst.Get(0).As(Contact).GetPhones
but the error is the same

How can I solve it ??

Thanks
Sergio
 
Last edited:
Solution
B4X:
Dim lstContacts As List

lstContacts = mContactsUtils.FindContactsByName("a", False, False)

For Each Contact As cuContact In lstContacts
    Log(Contact.DisplayName)

    Dim lstPhones As List
    lstPhones = mContactsUtils.GetPhones(Contact.Id)
    
    For Each PhoneNum As cuPhone In lstPhones
        Log(TAB & PhoneNum.PhoneType & TAB & PhoneNum.Number)
    Next
Next

LucaMs

Expert
Licensed User
Longtime User
B4X:
Dim lstContacts As List

lstContacts = mContactsUtils.FindContactsByName("a", False, False)

For Each Contact As cuContact In lstContacts
    Log(Contact.DisplayName)

    Dim lstPhones As List
    lstPhones = mContactsUtils.GetPhones(Contact.Id)
    
    For Each PhoneNum As cuPhone In lstPhones
        Log(TAB & PhoneNum.PhoneType & TAB & PhoneNum.Number)
    Next
Next
 
Upvote 0
Solution
Top