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: 429

hzytsoft

Member
Licensed User
Longtime User
my real phone is android 2.37
and my emulator use sdk v8

anyway
if i only use InsertContact
c=cu.InsertContact("jim","1234567890")


work well
but if i use
c=cu.InsertContact("jim","1234567890")
cu.AddPhone(c.Id,"87909877","home")


i got wrong
 

Attachments

  • 123.JPG
    123.JPG
    40.3 KB · Views: 344
Last edited by a moderator:
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
this is logs


** Activity (main) Create, isFirst = true **
jim


jim
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
Mike Tester
** Activity (main) Resume **
contactsutils_setdata (java line: 709)


java.lang.IllegalArgumentException: Invalid column name_raw_contact_id
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:144)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
at android.content.ContentProviderProxy.bulkQueryInternal(ContentProviderNative.java:330)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
at android.content.ContentResolver.query(ContentResolver.java:266)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Query(ContentResolverWrapper.java:43)
at b4a.example.contactsutils._setdata(contactsutils.java:709)
at b4a.example.contactsutils._addphone(contactsutils.java:125)
at b4a.example.main._button1_click(main.java:280)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)


at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:63)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9081)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
at dalvik.system.NativeStart.main(Native Method)
java.lang.IllegalArgumentException: Invalid column name_raw_contact_id
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
tks Erel
i just use your sample only add code
B4X:
Sub Button1_Click
Dim c As cuContact

  c=cu.InsertContact("jim","1234567890")
  cu.AddPhone(c.Id,"87909877","home")
End Sub
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
sorry i know y say
i have Export as zip from the IDE.

yes i testing it on a real device
also i testing it on a real device emulator

but i got a same wrong
 

Attachments

  • phoneadd.zip
    10.7 KB · Views: 310
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
i think maybe the same resons
i saw u wrtit
V1.10 - Adds GetEvents method.
V1.05 - Fixes an issue with InsertContact on HTC devices.
but i download
ContactsUtils.zip
only v1.10
can not find v1.05
can u tell me where can download v1.05
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
o my god
i fix
B4X:
Public Sub AddPhone(Id As Long, PhoneNumber As String, PhoneType As String)
    Dim v As ContentValues
    v.Initialize
    v.PutString("data1", PhoneNumber)
    v.PutInteger("data2", GetKeyFromValue(phoneTypes, PhoneType, 7))
    SetData("vnd.android.cursor.item/phone_v2", v, Id, False)
End Sub
to
B4X:
Public Sub AddPhone(Id As Long, PhoneNumber As String, PhoneType As String)
    Dim v As ContentValues
    v.Initialize
    v.PutString("data1", PhoneNumber)
    v.PutInteger("data2", GetKeyFromValue(phoneTypes, PhoneType, 7))
    SetData("vnd.android.cursor.item/phone_v2", v, Id, True)
End Sub

work well .........
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
sorry itis not end
in this way
if i use code
B4X:
  c=cu.InsertContact("jim","1234567890")
  cu.AddPhone(c.Id,"87909877","home")
  cu.AddPhone(c.Id,"87909811","other")
  cu.AddPhone(c.Id,"87909833","mobile")

only add "87909833","mobile"

@Erel pls give me some help
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
it means
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
if not update
just add new
will use name_raw_contact_id
if use name_raw_contact_id wile error
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
i use another phone alcatel to test aosl
cannot use
c=cu.InsertContact("jim","1234567890")
cu.AddPhone(c.Id,"87909877","home")

only can
c=cu.InsertContact("jim","1234567890")
work well
can not use
cu.AddPhone(c.Id,"87909877","home")
 
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
hi Erel
can you test my code
just test addphone Button

itis code
B4X:
Sub Button1_Click

Dim c As cuContact

c=cu.InsertContact("jim","1234567890")
'cu.SetNote(c.Id ,"qwqwqw")
cu.AddPhone(c.Id,"87909877","home")
cu.AddPhone(c.Id,"879098117","work")
End Sub
 

Attachments

  • testadd.zip
    11 KB · Views: 283
Upvote 0

hzytsoft

Member
Licensed User
Longtime User
i chande nothing just add a Button1
with this code
B4X:
Sub Button1_Click

Dim c As cuContact

c=cu.InsertContact("jim","1234567890")
'cu.SetNote(c.Id ,"qwqwqw")
cu.AddPhone(c.Id,"87909877","home")
cu.AddPhone(c.Id,"879098117","work")
End Sub
 
Upvote 0
Top