Android Question How do you get the name of a contact's phone number?

NeoTechni

Well-Known Member
Licensed User
Longtime User
ie: Home, mobile, mom, dad from the screenshot

screenshot.png
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Are you sure? That looks to be doing something different...

When I pull phone numbers out of a contact, I want the name of the phone number itself, not the name of the contact.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I checked, it's close to what I need. It will return Android's built in names (mobile, work), but not ones I set myself (mom, dad) as they show up as null

Also, it would be nice if B4A would warn you that you're missing a library, and even better if it'd link you to a central repository to get it.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Got it, I changed this sub

B4X:
'I changed phonetypes to a list since it uses less resources
  phoneTypes.Initialize
   phoneTypes.Add("custom")
   phoneTypes.Add("home")
   phoneTypes.Add("mobile")
   phoneTypes.Add("work")
   phoneTypes.Add("fax_work")
   phoneTypes.Add("fax_home")
   phoneTypes.Add("pager")
   phoneTypes.Add("other")
   phoneTypes.Add("callback")
   phoneTypes.Add("car")
   phoneTypes.Add("company_main")
   phoneTypes.Add("isdn")
   phoneTypes.Add("main")
   phoneTypes.Add("other_fax")
   phoneTypes.Add("radio")
   phoneTypes.Add("telex")
   phoneTypes.Add("tty_tdd")
   phoneTypes.Add("work_mobile")
   phoneTypes.Add("work_pager")
   phoneTypes.Add("assistant")
   phoneTypes.Add("mms")

'Returns a List with cuPhone items.
Public Sub GetPhones(id As Long) As List
    Dim res As List
    res.Initialize
    For Each obj() As Object In GetData("vnd.android.cursor.item/phone_v2", Array As String("data1", "data2", "data3"), id, Null)
        Dim p As cuPhone
        p.Initialize
        p.Number = obj(0)
        p.PhoneType = phoneTypes.Get(obj(1))
        If obj(1) = "0" Then p.PhoneType = obj(2)
        res.Add(p)
    Next
    Return res
End Sub
 
Upvote 0
Top