Alain75
Member
I used ContactsUtils 1.20 to explore my contacts but I was surprised not to found FirstName and LastName. I had difficulties to found references about it except an EREL's post (of course ) on android constants for Contacts
Finally I add the 2 attributes in the type definition of cuContact :
and modify the function which retrieves data :
And export the sort option in the public method FindAllContacts, other public ones not sorting :
I hope it may help others developers
Finally I add the 2 attributes in the type definition of cuContact :
New fields:
Sub Class_Globals
Type cuContact (Id As Long, DisplayName As String, FirstName As String, LastName As String)
Type cuEmail (Email As String, EmailType As String)
Type cuPhone (Number As String, PhoneType As String)
...
and modify the function which retrieves data :
FindContactsIdFromData:
Private Sub FindContactsIdFromData (Mime As String, DataColumn As String, Value As String, Operator As String, _
Exact As Boolean, VisibleOnly As Boolean, SortColumn As String) As List
If Not(Exact) Then
Operator = "LIKE"
Value = "%" & Value & "%"
End If
Dim selection As String = "mimetype = ? AND " & DataColumn & " " & Operator & " ? "
If VisibleOnly Then selection = selection & " AND in_visible_group = 1"
'Dim crsr As Cursor = cr.Query(dataUri, Array As String("contact_id", "display_name"), selection, _
Dim crsr As Cursor = cr.Query(dataUri, Array As String("contact_id", "display_name","data2","data3"), selection, _
Array As String(Mime, Value), SortColumn)
Dim res As List
res.Initialize
Dim m As Map
m.Initialize
For i = 0 To crsr.RowCount - 1
crsr.Position = i
Dim cu As cuContact
cu.Initialize
cu.Id = crsr.GetLong("contact_id")
cu.DisplayName = crsr.GetString("display_name")
cu.FirstName = IIf(crsr.GetString("data2")<>Null,crsr.GetString("data2"),"")
cu.LastName = IIf(crsr.GetString("data3")<>Null,crsr.GetString("data3"),"")
...
And export the sort option in the public method FindAllContacts, other public ones not sorting :
Public methods:
...
'Returns the starred contacts.
Public Sub FindContactsByStarred(Starred As Boolean) As List
Dim value As String
If Starred Then value = "1" Else value = "0"
Return FindContactsIdFromData("vnd.android.cursor.item/name", "starred", value,"=", True, True,"")
End Sub
'Returns all contacts.
Public Sub FindAllContacts(VisibleOnly As Boolean, Sort As String) As List
Return FindContactsIdFromData("vnd.android.cursor.item/name", "data1", "null", "<>", True, VisibleOnly,Sort)
End Sub
'Returns all contacts with a photo.
Public Sub FindContactsWithPhotos As List
Return FindContactsIdFromData("vnd.android.cursor.item/photo", "data15", "null", "<>", True, False,"")
End Sub
...
I hope it may help others developers