Skip to content Skip to sidebar Skip to footer

Caller_is_syncadapter Uses In Insert,update And Delete Uri Android Contacts, Provide Direction

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 synci

Solution 1:

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

Case 1: INSERT WITH CALLER_IS_SYNCADAPTER:

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

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());

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

            UrimyContactUri= res[0].uri;

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

Case 2: UPDATE WITH CALLER_IS_SYNCADAPTER:

ArrayList ops = new ArrayList();

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

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

            UrimyContactUri= res[0].uri;

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

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());

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

            UrimyContactUri= 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 :)

Post a Comment for "Caller_is_syncadapter Uses In Insert,update And Delete Uri Android Contacts, Provide Direction"