Android - query if synchronization account is synchronized for synchronization

How can I execute the request if the synchronization account is synchronized for synchronization?

+3
source share
1 answer

User does not control account selection for synchronization. Instead, pairs (acount, contentAuthority) are selected. For example, your gmail account can be verified to synchronize contacts, but not calendar events.

Here is the code to check if the first "com.google-type" account is synced with google contacts. (Please note that "com.google" is the type of account, not the actual contents of the username. Perhaps you have a Google Apps account with your own domain name)

import android.provider.ContactsContract;

AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.google");        
boolean syncEnabled = ContentResolver.getSyncAutomatically(accounts[0], ContactsContract.AUTHORITY);

This code obviously will not succeed if the [] accounts are of size 0 (no accounts are registered) and are meaningless if there are multiple accounts. You will need to make some reasonable choice for the account. There are other ways to access your account.

, , , . : (./.), . ContentResolver .

+4

Source: https://habr.com/ru/post/1756194/


All Articles