Android Question How to update contacts numbers

Marco Gioia

Member
Licensed User
Hi all,

to update the displayname I used this link: https://www.b4x.com/android/forum/threads/update-contact-displayname.76313/#post-484270

B4X:
Public Sub SetDisplayName(Id As Long, Name As String)
   Dim values As ContentValues
   values.Initialize
   values.PutString("data1", Name)
   SetData("vnd.android.cursor.item/name", values, Id, True)
End Sub
Is there something similar for phone?

I guess I can't use "vnd.android.cursor.item/phone" due to "numbers"
 

klaus

Expert
Licensed User
Add this routine to the ContactUtils Class:
B4X:
'PhoneTypeIndex = the index number of the phone type
'"1" = "home"
'"2" = "mobile"
'"3" = "work"
'("4" = "fax_work"
'"5" = "fax_home"
'"6" = "pager"
'"7" = "other"
'"8" = "callback"
'"9" = "car"
'"10" = "company_main"
'"11" = "isdn"
'"12" = "main"
'"13" = "other_fax"
'"14" = "radio"
'"15" = "telex"
'"16" = "tty_tdd"
'"17" = "work_mobile"
'"18" = "work_pager"
'"19" = "assistant"
'"20" = "mms")
Public Sub SetPhone(Id As Long, PhoneNumber As String, PhoneTypeIndex As String)
    Dim values As ContentValues
    values.Initialize
    values.PutString("data1", PhoneNumber)
    values.PutString("data2", PhoneTypeIndex)
    SetData("vnd.android.cursor.item/phone_v2", values, Id, True)
End Sub
Calling example:
"1" for "home"
B4X:
cu.SetPhone(CurrentID, edtPhoneNumber.Text, "1")
Information source:
https://www.dev2qa.com/android-contacts-fields-data-table-columns-and-data-mimetype-explain/
 
Last edited:
Top