Android Question ContactUtils library - Not able to use SetNote to set a contact note

Eric H

Active Member
Licensed User
Longtime User
I am using the following code to try and create contacts and set a note for each one. The contacts are being created properly, but the notes are not being set. I don't get any compile or runtime errors, it just doesn't add a note to the contact:

B4X:
Sub Globals
    Dim btnAdd As Button
    Dim btnRemove As Button
    Dim etxQuantity As EditText
    Dim quant As Int
End Sub

Sub etxQuantity_TextChanged (Old As String, New As String)
    'limit EditText view to 3 digits
    If New.Length > 3 Then
        etxQuantity.Text = Old
        'move the cursor to the end of the view
        etxQuantity.SelectionStart = etxQuantity.Text.Length
    End If
    
    'make sure EditText view isn't blank, then set the value to the variable quant    
    If etxQuantity.Text <> "" Then
        quant = etxQuantity.Text
    Else
        quant = 0
    End If
End Sub

Sub btnAdd_Click
    Dim thisContactID As cuContact

    If quant > 0 Then
        Msgbox("Creating fake contacts! (please be patient)", "Nice!")
        For i = 1 To quant
            thisContactID = cu.InsertContact("#" & DateTime.Now, "")
            cu.SetNote(thisContactID.Id, "Fake contact")
        Next
    Else
        Msgbox("Enter a quantity first.", "Hey!")
    End If
End Sub

The reason I am setting a note is because I am using this code to delete certain contacts that contain the note that I set:

B4X:
Sub btnRemove_Click
   
    Msgbox("Deleting all fake contacts! (please be patient)", "Sweet!")
    Dim deleteTheseContacts As List = cu.FindContactsByNotes("Fake contact", True, False)
    For Each c As cuContact In deleteTheseContacts
        cu.DeleteContact(deleteTheseContacts)
    Next
   
End Sub

Why isn't my SetNote code working?
 

Eric H

Active Member
Licensed User
Longtime User
On a sorta related note... Is it possible to set the created contacts to not sync with the person's Google account? I am creating and deleting up to 999 contacts and when I delete that many contacts Google's contact sync freaks out and keeps asking if I am sure that I want to delete that many contacts.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try to create a unique phone number and email address for each of the contacts.

It is currently not possible with ContactsUtils. It is probably possible to do it. Try to find a Java solution and I will help you to port it to ContactsUtils.
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
i changed the behaviour of the program to add an email instead of a note (still not sure why adding an email would work but adding a note does not, but it doesn't matter anymore for my purposes here)

I replaced this:
B4X:
cu.SetNote(thisContactID.Id, "Fake contact")
with this:
B4X:
cu.AddEmail(thisContact.Id, "fake@contact.com", "home")

and changed my (broken) delete sub as follows:
B4X:
Sub btnRemove_Click
    Dim theContact As cuContact
   
    Msgbox("Deleting all fake contacts!" & CRLF & "(please be patient)", "Righteous!")
    Dim deleteTheseContacts As List = cu.FindContactsByMail("fake@contact.com", True, False)
    For Each c As cuContact In deleteTheseContacts
        cu.DeleteContact(c.Id)
    Next
   
End Sub

Everything is working as it should now. Thanks again Erel!
 
Upvote 0

Eric H

Active Member
Licensed User
Longtime User
-EricH

It is currently not possible with ContactsUtils. It is probably possible to do it. Try to find a Java solution and I will help you to port it to ContactsUtils.
-Erel

I did some searching and it looks like GoogleContactsSyncAdapter is what controls syncing the contacts. Contact sync can be disabled manually like this:

1. On your phone, go to "Settings".
2. Look for "Accounts & Sync".
3. Select your Google account.
4. Uncheck "Contacts".

I wonder if there is a way to temporarily disable GoogleContactsSyncAdapter programmatically...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…