當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。