当前位置: 首页>>代码示例>>Java>>正文


Java ContentResolver.getSyncAdapterTypes方法代码示例

本文整理汇总了Java中android.content.ContentResolver.getSyncAdapterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java ContentResolver.getSyncAdapterTypes方法的具体用法?Java ContentResolver.getSyncAdapterTypes怎么用?Java ContentResolver.getSyncAdapterTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.ContentResolver的用法示例。


在下文中一共展示了ContentResolver.getSyncAdapterTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setSyncActivated

import android.content.ContentResolver; //导入方法依赖的package包/类
public void setSyncActivated(boolean enabled) {
	
       ContentResolver.setMasterSyncAutomatically(enabled);
       
       if (enabled) {
       	SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
       	AccountManager accmgr = AccountManager.get(mContext);
       	for (SyncAdapterType type : types) {
       		
       		Account[] accounts = accmgr.getAccountsByType(type.accountType);
       		for (Account account : accounts) {
       			
       			if (Constants.DEBUG) {
       				Log.d(TAG, "synching account, name:" + account.name  + ", type: " + account.type);
       			}
       			
       			enabled = ContentResolver.getSyncAutomatically(account, type.authority);
       			if (enabled) {
       				// trigger update for next account
       				ContentResolver.requestSync(account, type.authority, new Bundle());
       			}
       		}
       	}
       }
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:26,代码来源:SyncControl20.java

示例2: startSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:35,代码来源:AccountSnippet.java

示例3: stopSync

import android.content.ContentResolver; //导入方法依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:37,代码来源:AccountSnippet.java


注:本文中的android.content.ContentResolver.getSyncAdapterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。