I want to sync my contacts from my app to native android contact app programmatically. Please help me. Thanks in advance.
Asked
Active
Viewed 4,613 times
1
-
"I want to sync my contacts from my app to....." How can you have contacts in your app?? – Santhosh Sep 24 '12 at 09:00
-
If you have some numbers to be stored in contacts... here is the answer.. http://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android – Santhosh Sep 24 '12 at 09:03
-
i have to sync my contacts with my selected ringtone – AndroidRaji Sep 24 '12 at 09:12
1 Answers
3
you can try below code for account syncing
public static void requestSyncNow(final Context context) {
new Thread(new Runnable() {
@Override
public void run() {
AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccounts();
boolean isMasterSyncOn = ContentResolver.getMasterSyncAutomatically();
for (Account account : accounts) {
Log.d(TAG, "account=" + account);
int isSyncable = ContentResolver.getIsSyncable(account,
ContactsContract.AUTHORITY);
boolean isSyncOn = ContentResolver.getSyncAutomatically(account,
ContactsContract.AUTHORITY);
Log.d(TAG, "Syncable=" + isSyncable + " SyncOn=" + isSyncOn);
if (isSyncable > 0 /* && isSyncOn */) {
Log.d(TAG, "request Sync");
Bundle bundle = new Bundle();
bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(account, ContactsContract.AUTHORITY, bundle);
}
}
}
}, "SyncLauncher").start();
}

Ruchit Mittal
- 312
- 1
- 9