本文整理匯總了Java中android.content.ContentResolver.cancelSync方法的典型用法代碼示例。如果您正苦於以下問題:Java ContentResolver.cancelSync方法的具體用法?Java ContentResolver.cancelSync怎麽用?Java ContentResolver.cancelSync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.ContentResolver
的用法示例。
在下文中一共展示了ContentResolver.cancelSync方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateSync
import android.content.ContentResolver; //導入方法依賴的package包/類
/**
* Updates ContentResolver sync settings for an Account's specified SyncAdapter.
*
* <p>Sets an accounts SyncAdapter (selected based on authority) to sync/not-sync automatically
* and immediately requests/cancels a sync.
*
* <p>updateSync should always be called under {@link AccountSnippet#mLock} write lock to avoid
* flapping between the getSyncAutomatically and setSyncAutomatically calls.
*
* @param account A Google Account.
* @param authority The authority of a content provider that should (not) be synced.
* @param sync Whether or not the account's content provider should be synced.
*/
private void updateSync(Account account, String authority, boolean sync) {
if (ContentResolver.getSyncAutomatically(account, authority) != sync) {
ContentResolver.setSyncAutomatically(account, authority, sync);
if (sync) {
ContentResolver.requestSync(account, authority, new Bundle());
} else {
ContentResolver.cancelSync(account, authority);
}
Log.i(
"Set sync to "
+ sync
+ " for account "
+ account
+ ", adapter "
+ authority
+ ".");
}
}
示例2: disableSync
import android.content.ContentResolver; //導入方法依賴的package包/類
public static void disableSync(Context context) {
Account account = makeAccount(context);
ContentResolver.cancelSync(account, GigApplication.getSyncAuthority());
ContentResolver.setIsSyncable(account, GigApplication.getSyncAuthority(), 0);
}
示例3: updateSync
import android.content.ContentResolver; //導入方法依賴的package包/類
static public void updateSync(Context context) {
String accountType = context.getResources().getString(R.string.account_type);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
String syncFreq = pref.getString(context.getResources().getString(R.string.pref_sync_frequency),
context.getResources().getString(R.string.pref_sync_frequency_default_value));
assert(syncFreq != null);
int syncInterval = Integer.parseInt(syncFreq);
Logger logger = Logger.getInstance(context);
for (Account account : AccountManager.get(context).getAccountsByType(accountType)) {
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL,true);
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver.cancelSync(account, CalendarContract.AUTHORITY);
if (syncInterval == 0) {
continue;
}
// Schedule periodic sync based on current configuration
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// we can enable inexact timers in our periodic sync
SyncRequest request = new SyncRequest.Builder()
.syncPeriodic(syncInterval, syncInterval / 3)
.setSyncAdapter(account, CalendarContract.AUTHORITY)
.setExtras(new Bundle()).build();
ContentResolver.requestSync(request);
logger.info(TAG, "Scheduled periodic sync for account %s using requestSync, interval: %d",
account.name, syncInterval);
} else {
ContentResolver.addPeriodicSync(account, CalendarContract.AUTHORITY, new Bundle(), syncInterval);
logger.info(TAG, "Scheduled periodic sync for account %s using addPeriodicSync, interval: %d",
account.name, syncInterval);
}
}
}