本文整理汇总了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());
}
}
}
}
}
示例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();
}
}
示例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();
}
}