Android Question Contact resolver problem

buras3

Active Member
Licensed User
Longtime User
hello all

I am trying to update a contact phone with this function
Nothing happen

Public Sub UpdatePhone(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))
cr.Update( rawContactUri,v, "contact_id = ?", Array As String(Id))
End Sub

but with this line it's updating all the contact's phones
SetData("vnd.android.cursor.item/phone_v2", v , Id,True)

anyone can help

tank you
 

buras3

Active Member
Licensed User
Longtime User
I am using ContactsUtils

I tried to delete and add phone with the original functions
and the wrong contacts was updated

'Adds a phone field to the given contact id.
'PhoneType - One of the phone types strings (see Initialize method).
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

'Deletes the given phone number.
Public Sub DeletePhone(Id As Long, PhoneNumber As String)
DeleteData("vnd.android.cursor.item/phone_v2", PhoneNumber, Id)
End Sub


then i tried to change to "true" for update without adding and deleting
SetData("vnd.android.cursor.item/phone_v2", v , Id,True)
and it's updating all the contact's phones (write over for all phone types)
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
I tried to look to your issue but without success... Can you post your demo project, I can help you somehow.
(I don't want to delete or overwrite all current contacts in my own phone's contacts list :)).
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
now I get error in add_phone function "no column name_raw_contact_id"
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

buras3

Active Member
Licensed User
Longtime User
Htc desire HD
I coped once from a forum to fix that but after the last update the error came again
and i didn't find the fix
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
the file is too big to post here
how can i send it ?

I would like to advise you to reproduce the error by creating a simple test project, and you can copy (from your original project) and paste only the sub you need to investigate to that test project. If you do so, you can isolate that suspect function away from other possible factors. I usually do that for myself.

Then you can use the "export as zip" function in the B4A to export the test project out. If you say your file is too big I think you likely have many other functions that may impact.
 
Upvote 0

buras3

Active Member
Licensed User
Longtime User
my project is not so big - 500k it's not alot
and it's really simple all I want is to update contact phone

Erel
I tryed again with add and delete and like I wrote before it's deleting but adding to different contact (the ID is the same)
why not fix this line ? the problem in this line only with multiply phones to 1 contact - overwrites all phones of the contact
but I can update 1 phone
B4X:
If Update Then
cr.Update(dataUri, Values, "mimetype = ? AND contact_id = ?", ArrayAsString(Mime, Id))

has someone try to update with this line contact with few phones?
 
Last edited:
Upvote 0

buras3

Active Member
Licensed User
Longtime User
**FIXED**
for updating only 1 specific phone No
B4X:
If Update Then
  cr.Update(dataUri,  Values, "mimetype = ? AND contact_id = ? and data1= ? and data2= ?", Array As String(Mime, Id,PhoneNumer,PhoneType))
 
Upvote 0
Top