修改本机接触编程 [英] Modify native contact programmatically
问题描述
我试图以编程方式修改联系人的名字和姓氏。
我已经为了做这项工作中使用的code段是下列之一:
I'm trying to modify contact first name and last name programmatically. The code snippet that I've used in order to do the job is the following one:
operations.add( ContentProviderOperation.newUpdate( Data.CONTENT_URI )
.withSelection( RawContacts._ID + "=?",
new String[] { String.valueOf( mSmartphoneContactKey) } )
.withValue( ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME,
mContactName.getEditableText().toString() )
.withValue( ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
mContactLastName.getEditableText().toString() )
.build() );
的 mSmartphoneContactKey
与包含在列中的数据填充
The mSmartphoneContactKey
is filled in with the data contained in the column
ContactsContract.Contacts._ID
这是坐在我的投影矩阵,当我读到使用内容提供商联系。
which is sitting in my projection array when I read contacts using content provider.
的问题是,对于某些联系人的名字和姓不被修改,并在电话类型代替改性。
其实我没有关于原因的线索。
任何的建议是AP preciated。
The problem is that for some contacts the name and last name are not modified and the phone type is modified instead. Actually I don't have any clue about the cause. Any advice is appreciated.
我读过进一步的文档数据表是一个我必须使用。
我修改如下code ...仍无法正常工作
I've read further the documentation the Data table is the one I have to use. I've modified the code as below...still not working
operations.add( ContentProviderOperation.newUpdate( Data.CONTENT_URI )
.withSelection( Data._ID + " = ? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'",
new String[] { String.valueOf( mSmartphoneContactId ) } )
.withValue( ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, mContactName.getEditableText().toString() )
.withValue( ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, mContactLastName.getEditableText().toString() )
.build() );
请帮帮我!
推荐答案
好解决了!
错误ID通过。
需要从数据表中检索沿着数据的ID。
Ok Solved! Wrong ID passed. Need to retrieve the ID along the data from the DATA table.
这篇关于修改本机接触编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!