添加联系人信息时出现问题

发布于 2024-12-06 02:13:30 字数 1885 浏览 0 评论 0原文

我正在尝试从已使用简单 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我还不会笑 2024-12-13 02:13:30

感谢聊天室的@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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文