Android Question ContactsUtils lib cannot add pnone

hzytsoft

Member
Licensed User
Longtime User
i use
[class] ContactsUtils - Provides read / write access to the stored contacts

link:http://www.b4x.com/android/forum/th...ad-write-access-to-the-stored-contacts.30824/

but
i use this code
Dim c As cuContact

c=cu.InsertContact("jim","1234567890")
ToastMessageShow(c.Id, False)
cu.AddPhone(c.Id,"87909877","home")
but got wrong
then i use this code
cu.AddPhone(c.Id,"87909877","1")

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

ps
logs show
error in
contactsutils_setdata (java line: 709)

 

Attachments

  • useContactsUtils.zip
    366.9 KB · Views: 506

hzytsoft

Member
Licensed User
Longtime User
maybe android 2.x ‘s datebase in not same as above ver
this is my contacts2.db
 

Attachments

  • contacts2.zip
    19.9 KB · Views: 362
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
issue not with AddPhone
juest with SetData(Mime As String, Values As ContentValues, Id As Long, Update As Boolean)
B4X:
Private Sub SetData(Mime As String, Values As ContentValues, Id As Long, Update As Boolean)
    If Update Then
        cr.Update(dataUri, Values, "mimetype = ? AND contact_id = ?", Array As String(Mime, Id))
    Else
        Dim crsr As Cursor = cr.Query(contactUri, Array As String("name_raw_contact_id"), _
            "_id = ?", Array As String(Id), "")
        If crsr.RowCount = 0 Then
            Log("Error getting raw_contact_id")
            crsr.Close
            Return
        End If
        crsr.Position = 0
        Values.PutString("raw_contact_id", crsr.GetString("name_raw_contact_id"))
        crsr.Close
        Values.PutString("mimetype", Mime)
        cr.Insert(dataUri, Values)
    End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this updated sub:
B4X:
Private Sub SetData(Mime As String, Values As ContentValues, id As Long, Update As Boolean)
   If Update Then
     cr.Update(dataUri, Values, "mimetype = ? AND contact_id = ?", Array As String(Mime, id))
   Else
     Try
       Dim crsr As Cursor = cr.Query(contactUri, Array As String("name_raw_contact_id"), _
         "_id = ?", Array As String(id), "")
       If crsr.RowCount = 0 Then
         Log("Error getting raw_contact_id")
         crsr.Close
         Return
       End If
       crsr.Position = 0
       Values.PutString("raw_contact_id", crsr.GetString("name_raw_contact_id"))
       crsr.Close
     Catch
       Values.PutString("raw_contact_id", id)
     End Try
     Values.PutString("mimetype", Mime)
     cr.Insert(dataUri, Values)
   End If
End Sub
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
it is work well
very tks

ps .
if this code also fit Android 2.X OR fit all ver?
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
Perfect!
U means this code can fit all devices both Android 2.X OR Android 4.X or Android 3.X
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…