How to synchronize Android native contacts into Google account using Google API. Provide some useful links.
To access personal contacts: https://www.googleapis.com/auth/contacts. To access directory information: https://www.googleapis.com/auth/directory.readonly.
The syncing happens automatically. You can add or delete contacts programatically. But the syncing is handled by the OS automatically if and only if the user has enabled 'sync conatcts' option in phone settings.
You can, however run a sync routine that can call the syncing process if syncing is enabled by the user using something like this:
private void requestSync()
{
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccounts();
for (Account account : accounts)
{
int isSyncable = ContentResolver.getIsSyncable(account, ContactsContract.AUTHORITY);
if (isSyncable > 0)
{
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(accounts[0], ContactsContract.AUTHORITY, extras);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With