B4A Library [class] ContactsUtils - Provides read / write access to the stored contacts

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 7, 2013.

  1. hzytsoft

    hzytsoft Member Licensed User

    hi Erel

    i use this code
    Dim c As cuContact

    ToastMessageShow(c.Id, False)
    but got wrong
    then i use this code

    also got wrong
    logs show:
    java.lang.IllegalArgumentException: Invalid column name_raw_contact_id

  2. hzytsoft

    hzytsoft Member Licensed User

    logs show
    error in
    contactsutils_setdata (java line: 709)
  3. hzytsoft

    hzytsoft Member Licensed User

    Sub Button1_Click
    Dim c As cuContact

    ToastMessageShow(c.Id, False)
    End Sub
  4. shaffnert03

    shaffnert03 Member Licensed User

    Don't mean to jump in front of hzytsoft's question, but have one for after his is answered.

    Trying to use the new getevents() function (thanks so much for adding that BTW!), and having some issues getting the information out. If I put the result into a cuEvents object I can get data out when it's populated, but if the contact has no event data I can't seem to check for that.

    IsInitialized doesn't work since I had to initialize the variable before pulling it (didn't work if I tried not to), and if try to check and see if "EventType" is <> "" then the program bombs out. Log shows "Error occurred on line: 118 (contactsutils) importcontactsafterFirstLayout (java line: 98)"

    As an alternative I tried to put the getevents result in a normal list. I could then put the items from that into an object, but nothing I put in the get function on the object seemed to get the data out.

    Any help with this? Here's a few lines that I'm trying as a visual:

    Dim EventList As cuEvent
    EventList = cu.GetEvents(
    If EventList.EventType = "birthday" Then lbl2.Text = EventList.DateString
    Also, more generally, this is like the third or fourth question I've had on just getting data out of various data types, is there somewhere particular you'd recommend I go for more information on this? I've got both user manuals and the Kindle book on B4A, anywhere in particular I should look to understand this better?
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for each of these questions. I'm sorry but this thread is too "messed".
  6. HARRY

    HARRY Active Member Licensed User


    I use this class with pleasure, it works very well. However, it does not do all things I need. I have to extract the postal address of a contact from which I know the iD.

    In the first post Erel says:It should be pretty simple to extend this class and retrieve or modify other fields based on the existing code.

    For me, however, it is not "pretty simple"; whatever I try, based on studying various sources on internet, I do not reach my goal.

    Can somebody give me some help?

  7. Erel

    Erel Administrator Staff Member Licensed User

    You can use this sub (add it to ContactsUtils):
    Public Sub GetAddress(id As Long) As String
    Dim raw As List = GetData("vnd.android.cursor.item/postal-address_v2"Array As String("data1"), idNull)
    If raw.Size = 0 Then Return ""
    Dim obj() As Object = raw.Get(0)
    Return obj(0)
    End Sub
  8. HARRY

    HARRY Active Member Licensed User

    Hi Erel,

    Thanks very much. It works without problems. I was looking in the same direction, but did not know how to handle raw.

  9. aklisiewicz

    aklisiewicz Active Member Licensed User

    Using Android 4.3+
    I would like to know how can I use this LIB to display Contacts in my Application based on the selected contact group.
    I do not see any GROUP property in the lib referenced...

    I would like to have a SIPNNER which allows the user to select a GROUP, then use ListView (or alike) to display contacts based on that group.

  10. Erel

    Erel Administrator Staff Member Licensed User

    Note that this is not a library, it is a class module.

    ContactsUtils currently doesn't provide access to contacts groups.
  11. derez

    derez Expert Licensed User

    The names of the contacts are cut when their length exceeds ~12-14 characters. It comes like this from the cr.Query - crsr.GetString("display_name").
    Any reason for this ?
  12. Erel

    Erel Administrator Staff Member Licensed User

    I don't see this behavior here. Tried it with a 19 characters name.

    You can try to fetch the name from this uri: vnd.android.cursor.item/name

    data1 will return the display name.
    data2 will return the given name.
  13. derez

    derez Expert Licensed User

    I get the same thing with the above , both on nexus 5 and samsung 2.
  14. Erel

    Erel Administrator Staff Member Licensed User

    Not sure. You can try to fetch all of the columns in this uri and see whether the full name is available.
  15. derez

    derez Expert Licensed User

    I guess the problem is from transfering the contacts to and from sim cards. I'll check later with a new contact.
    Edit: it is like I wrote above. If I update the contact it shows in full.
    Last edited: Jan 9, 2014
  16. aklisiewicz

    aklisiewicz Active Member Licensed User

    any chance to get groups support in a near future ?
    Is there any other way to filter through groups ?
  17. Erel

    Erel Administrator Staff Member Licensed User

    Please do not post duplicate questions.
  18. Gennaro Frungillo

    Gennaro Frungillo Member Licensed User

    Hi Erel, i've a question:
    it's possible to load all contact into a listview inside an async operation?
    Let me explain, I need to load all the address book contacts in a listview with their images, but the operation takes enough time, it would be nice to load the contacts in the list asynchronously in order to give the user the possibility of immediate access to the form that contains the listview, without having to wait for loading of all contacts.
    With visual studio I used the component BackGroundWorker or threading class.
  19. Erel

    Erel Administrator Staff Member Licensed User

  20. CapReed

    CapReed Member Licensed User

    I have spent several hours this item, It is very rare ...

    I added this sub to update the contact name.

    Public Sub PonNombre(Id As Long, Name As String)
    Dim v As ContentValues
    "data1", Name)
    "vnd.android.cursor.item/name", v, IdTrue)
    End Sub
    Works fine, but there is one detail that I do not understand.
    Suppose that the contact old name was MiNameIs Anthony
    Suppose that the contact new name is Ama
    Well, the result after executing the subroutine is that Ama Anthony appears in the address book :confused:
    I do not understand ...

    Can you help me????
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice