android.content.ContentResolver#getSyncAdapterTypes ( )源码实例Demo

下面列出了android.content.ContentResolver#getSyncAdapterTypes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mobly-bundled-snippets   文件: AccountSnippet.java
/**
 * Enables syncing of a SyncAdapter for a given content provider.
 *
 * <p>Adds the authority to a whitelist, and immediately requests a sync.
 *
 * @param username Username of the account (including @gmail.com).
 * @param authority The authority of a content provider that should be synced.
 */
@Rpc(description = "Enables syncing of a SyncAdapter for a content provider.")
public void startSync(String username, String authority) throws AccountSnippetException {
    if (!listAccounts().contains(username)) {
        throw new AccountSnippetException("Account " + username + " is not on the device");
    }
    // Add to the whitelist
    mLock.writeLock().lock();
    try {
        if (mSyncWhitelist.containsKey(username)) {
            mSyncWhitelist.get(username).add(authority);
        } else {
            mSyncWhitelist.put(username, new HashSet<String>(Arrays.asList(authority)));
        }
        // Update the Sync settings
        for (SyncAdapterType adapter : ContentResolver.getSyncAdapterTypes()) {
            // Find the Google account content provider.
            if (adapter.accountType.equals(GOOGLE_ACCOUNT_TYPE)
                    && adapter.authority.equals(authority)) {
                Account account = new Account(username, GOOGLE_ACCOUNT_TYPE);
                updateSync(account, authority, true);
            }
        }
    } finally {
        mLock.writeLock().unlock();
    }
}
 
源代码2 项目: mobly-bundled-snippets   文件: AccountSnippet.java
/**
 * Disables syncing of a SyncAdapter for a given content provider.
 *
 * <p>Removes the content provider authority from a whitelist.
 *
 * @param username Username of the account (including @gmail.com).
 * @param authority The authority of a content provider that should not be synced.
 */
@Rpc(description = "Disables syncing of a SyncAdapter for a content provider.")
public void stopSync(String username, String authority) throws AccountSnippetException {
    if (!listAccounts().contains(username)) {
        throw new AccountSnippetException("Account " + username + " is not on the device");
    }
    // Remove from whitelist
    mLock.writeLock().lock();
    try {
        if (mSyncWhitelist.containsKey(username)) {
            Set<String> whitelistedProviders = mSyncWhitelist.get(username);
            whitelistedProviders.remove(authority);
            if (whitelistedProviders.isEmpty()) {
                mSyncWhitelist.remove(username);
            }
        }
        // Update the Sync settings
        for (SyncAdapterType adapter : ContentResolver.getSyncAdapterTypes()) {
            // Find the Google account content provider.
            if (adapter.accountType.equals(GOOGLE_ACCOUNT_TYPE)
                    && adapter.authority.equals(authority)) {
                Account account = new Account(username, GOOGLE_ACCOUNT_TYPE);
                updateSync(account, authority, false);
            }
        }
    } finally {
        mLock.writeLock().unlock();
    }
}