After some research with stachoverflow and android docs, The below code does the Trick
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
Tested on android version ics and above.
Courtesy : GENIUS
سؤال
I have built an account and the sync works fine . But the problem is I have to explicitly check the sync contacts
checkbox
to trigger the sync adapter
. Is there any way to automate it and have it checked automatically on account adding?
المحلول
After some research with stachoverflow and android docs, The below code does the Trick
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
Tested on android version ics and above.
Courtesy : GENIUS
نصائح أخرى
To sync automatically use:
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
To sync periodically use:
ContentResolver.addPeriodicSync(account, ContactsContract.AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL_IN_SECONDS);
Following documentation demonstrating different ways of running the sync: Running a Sync Adapter