Java Code Examples for android.content.ContentResolver#getSyncAdapterTypes()
The following examples show how to use
android.content.ContentResolver#getSyncAdapterTypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccountSnippet.java From mobly-bundled-snippets with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 2
Source File: AccountSnippet.java From mobly-bundled-snippets with Apache License 2.0 | 5 votes |
/** * 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(); } }