添加联系人信息时出现问题
我正在尝试从已使用简单 xml 框架序列化的 xml 文件添加一些联系人,但出现一个奇怪的错误:
ERROR/ContentProviderOperation(10727): mType: 1, mUri: content://com.android .contacts/data,mSelection:空,mExpectedCount:空,mYieldAllowed:假,mValues:data1 =卡尔科菲马克思安托万卡特mimetype=vnd.android.cursor.item/name,mValuesBackReferences:raw_contact_id = 1,mSelectionArgsBackReferences:null
这是代码
ContactList contactList = serializer.read(ContactList.class, xmlFile);
int nbreContacts = contactList.contact.length;
for(int i=0;i<nbreContacts;i++)
{
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
id = contactList.contact[i].getId();
name = contactList.contact[i].getName();
addName(Integer.parseInt(id), name);
flush(c);
}
private void addName(int contactId, String displayName)
{
if(displayName != null)
{
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, contactId)
.withValueData.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
.build());
}
}
private void flush(Context c)
{
ContentResolver cr = c.getContentResolver();
try
{
cr.applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (RemoteException e)
{
Log.e("Writing", "Remote Error writting data ", e);
}
catch (OperationApplicationException e)
{
Log.e("Writing", "OAE Error writting data", e);
}
}
任何帮助将不胜感激。
I'm trying to add some contacts from an xml file which have been serialize with Simple xml framework and there is a weird error :
ERROR/ContentProviderOperation(10727): mType: 1, mUri: content://com.android.contacts/data, mSelection: null, mExpectedCount: null, mYieldAllowed: false, mValues: data1=Karl Koffi Marx Antoine Carter mimetype=vnd.android.cursor.item/name, mValuesBackReferences: raw_contact_id=1, mSelectionArgsBackReferences: null
This is the code
ContactList contactList = serializer.read(ContactList.class, xmlFile);
int nbreContacts = contactList.contact.length;
for(int i=0;i<nbreContacts;i++)
{
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
.build());
id = contactList.contact[i].getId();
name = contactList.contact[i].getName();
addName(Integer.parseInt(id), name);
flush(c);
}
private void addName(int contactId, String displayName)
{
if(displayName != null)
{
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, contactId)
.withValueData.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
.withValue(CommonDataKinds.StructuredName.DISPLAY_NAME, displayName)
.build());
}
}
private void flush(Context c)
{
ContentResolver cr = c.getContentResolver();
try
{
cr.applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (RemoteException e)
{
Log.e("Writing", "Remote Error writting data ", e);
}
catch (OperationApplicationException e)
{
Log.e("Writing", "OAE Error writting data", e);
}
}
Any help would be appreciate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢聊天室的@Reno。
withValueBackReference(Data.RAW_CONTACT_ID, contactId)
更改为.withValueBackReference(Data.RAW_CONTACT_ID, 0)
我首先认为 RAW_CONTACT_ID 指的是联系人 ID,这就是我错的原因。问题已解决,希望对其他人有帮助:)
Thanks to @Reno on the chat room.
withValueBackReference(Data.RAW_CONTACT_ID, contactId)
changed to.withValueBackReference(Data.RAW_CONTACT_ID, 0)
I first thought RAW_CONTACT_ID was refering to the contact id that's why I was wrong. Problem solved and hope that will help someone else :)