Android :programmatically Updated Contact Is Not Syncing With Other Apps
Solution 1:
while updating contact information programmatically, you should also trigger sync so that all adapter can be synchronized.
This can be done as following:-
privatevoidrequestSync()
{
AccountManager am = AccountManager.get(context);
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);
}
}
}
This code will get the accounts which are added to contact app of the device such as "WhatsApp" and "Google" and will request to synchronize.
Permissions should be added as
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
Solution 2:
Whatsapp is not "contact-based" rather "phone-number-based" meaning that if you change Contact A's phone number, it will NOT change the existing conversation with that contact (as that conversation's "key" is the phone number).
Also note that you can have conversations with phone-numbers that are not stored in your local contacts at all.
Whatsapp has its SyncAdapter like most other apps that read/write to the Android Contacts DB, each app can decide whether it wants to be woken up and sync whenever a change happens. Whatsapp, as far as I'm aware, does not wake up and sync each change, it does that periodically instead, and can be triggered manually by the user (compose new message > menu > refresh)
So to sum if up your updated contact is syncing with other apps, but on their terms not yours.
Post a Comment for "Android :programmatically Updated Contact Is Not Syncing With Other Apps"