本文介绍了CALLER_IS_SYNCADAPTER 用于插入、更新和删除 URI Android 联系人,提供方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:谁能建议我如何在 android 中的插入、更新和删除 URI 中附加标志 caller_is_syncadapter(示例).在使用 android 联系人同步 (SyncAdpater) 期间.感谢您的帮助.提前致谢.

Problem:Can any one suggest me that how to append the flag caller_is_syncadapter in insert, update and delete URIs in android(Example).During working with android contacts syncing(SyncAdpater). Your help will be appreciated.Thanks in advance.

推荐答案

在研究过程中我找到了上述问题的答案,希望对你有用.

During Research I found answer of the above question,Hope it would useful for you.

案例 1: INSERT WITH CALLER_IS_SYNCADAPTER:

Case 1: INSERT WITH CALLER_IS_SYNCADAPTER:

在使用内容提供商操作插入您的联系信息时,必须附加在工作 uri 中.例如:

while inserting your contact info with your content provider operation one must append in the working uri. for example:

ArrayList ops = new ArrayList();

ArrayList ops = new ArrayList();

ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type).withValue(RawContacts.ACCOUNT_NAME, account.name).build());

ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, account.type) .withValue(RawContacts.ACCOUNT_NAME, account.name).build());

ContentProviderResult[] res = mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);

            Uri myContactUri = res[0].uri;

            myContactUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

案例 2: UPDATE WITH CALLER_IS_SYNCADAPTER:

Case 2: UPDATE WITH CALLER_IS_SYNCADAPTER:

ArrayList ops = new ArrayList();

ArrayList ops = new ArrayList();

ops.add(ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI).withSelection(selectPhone, phoneArgs).withValue(RawContacts.DIRTY, 0).build());

ops.add(ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI).withSelection(selectPhone, phoneArgs) .withValue(RawContacts.DIRTY, 0).build());

ContentProviderResult[] res = mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);

            Uri myContactUri = res[0].uri;

            myContactUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

情况 3: DELETE WITH CALLER_IS_SYNCADAPTER:ArrayList ops = new ArrayList();

Case 3: DELETE WITH CALLER_IS_SYNCADAPTER: ArrayList ops = new ArrayList();

ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(ContactsContract.RawContacts.CONTACT_ID + "=? AND " + ContactsContract.Groups.ACCOUNT_NAME+ "=? AND " + ContactsContract.Groups.ACCOUNT_TYPE + "=?",new String[] { o.getPhoneContactId() + "", account.name, account.type }) .build());

ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(ContactsContract.RawContacts.CONTACT_ID + "=? AND " + ContactsContract.Groups.ACCOUNT_NAME + "=? AND " + ContactsContract.Groups.ACCOUNT_TYPE + "=?", new String[] { o.getPhoneContactId() + "", account.name, account.type }) .build());

ContentProviderResult[] res = mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);

            Uri myContactUri = res[0].uri;

            myContactUri.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();

如果有人在做这件事时遇到任何问题,请在评论中告诉我:)谢谢,(:快乐编码 :)

Let me know in comments, if some face any problem in doing this thing :) thanks , (: Happy Coding :)

这篇关于CALLER_IS_SYNCADAPTER 用于插入、更新和删除 URI Android 联系人,提供方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 06:43