Android Question ContactsUtils lib cannot add pnone

Discussion in 'Android Questions' started by hzytsoft, Dec 10, 2013.

  1. hzytsoft

    hzytsoft Member Licensed User

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

    link:http://www.basic4ppc.com/android/fo...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)

     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    1. It is difficult to read your post. Please use normal font.
    2. You should use File - Export as zip when uploading projects

    It works fine here. Which device are you using? What is the full error?
     
  3. hzytsoft

    hzytsoft Member Licensed 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
     

    Attached Files:

    • 123.JPG
      123.JPG
      File size:
      40.3 KB
      Views:
      123
    Last edited by a moderator: Dec 10, 2013
  4. hzytsoft

    hzytsoft Member Licensed 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
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You should use File - Export as zip when uploading files. Please upload it again.
     
  6. hzytsoft

    hzytsoft Member Licensed User

    tks Erel
    i just use your sample only add code
    Code:
    Sub Button1_Click
    Dim c As cuContact

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

    Erel Administrator Staff Member Licensed User

    You are still not uploading the files correctly. You should use File - Export as zip from the IDE.

    Are you testing it on a real device?
     
  8. hzytsoft

    hzytsoft Member Licensed 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
     

    Attached Files:

  9. Erel

    Erel Administrator Staff Member Licensed User

  10. hzytsoft

    hzytsoft Member Licensed 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
     
  11. hzytsoft

    hzytsoft Member Licensed User

    o my god
    i fix
    Code:
    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, IdFalse)
    End Sub
    to
    Code:
    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, IdTrue)
    End Sub
    work well .........
     
  12. hzytsoft

    hzytsoft Member Licensed User

    sorry itis not end
    in this way
    if i use code
    Code:
    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
     
  13. hzytsoft

    hzytsoft Member Licensed User

    it means
    Code:
    Private Sub SetData(Mime As String, Values As ContentValuesId 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
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    V1.10 includes the fix of v1.05. You will need to workaround the HTC 2.3 issues.
     
  15. hzytsoft

    hzytsoft Member Licensed User

    i real phone is zte not htc
    and i test in emulator got same error
     
  16. hzytsoft

    hzytsoft Member Licensed 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")
     
  17. hzytsoft

    hzytsoft Member Licensed User

    maybe
    ContactsUtils lib
    not fit
    android 2.1
    android 2.2
    android 2.3
    ?
     
  18. hzytsoft

    hzytsoft Member Licensed User

    hi Erel
    can you test my code
    just test addphone Button

    itis code
    Code:
    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
     

    Attached Files:

  19. Erel

    Erel Administrator Staff Member Licensed User

    What did you change in the code?
     
  20. hzytsoft

    hzytsoft Member Licensed User

    i chande nothing just add a Button1
    with this code
    Code:
    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
     
Loading...
  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