android.content.ContentResolver#cancelSync ( )源码实例Demo

下面列出了android.content.ContentResolver#cancelSync ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mobly-bundled-snippets   文件: AccountSnippet.java
/**
 * 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 项目: narrate-android   文件: SyncHelper.java
public static boolean cancelPendingActiveSync(Account mChosenAccount) {
    boolean pending = ContentResolver.isSyncPending(mChosenAccount, Contract.AUTHORITY);
    if (pending) {
        LogUtil.log(TAG, "Warning: sync is PENDING. Will cancel.");
    }
    boolean active = ContentResolver.isSyncActive(mChosenAccount, Contract.AUTHORITY);
    if (active) {
        LogUtil.log(TAG, "Warning: sync is ACTIVE. Will cancel.");
    }

    if (pending || active) {
        LogUtil.log(TAG, "Cancelling previously pending/active sync.");
        ContentResolver.cancelSync(mChosenAccount, Contract.AUTHORITY);
        return true;
    }

    return false;
}
 
源代码3 项目: attendee-checkin   文件: GutenbergApplication.java
public boolean requestSync(boolean onlyCheckins) {
    if (!isUserLoggedIn()) {
        return false;
    }
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    extras.putString(SyncAdapter.EXTRA_AUTH_TOKEN, mAuthToken);
    extras.putBoolean(SyncAdapter.EXTRA_ONLY_CHECKINS, onlyCheckins);
    ContentResolver.setSyncAutomatically(mAccount, Table.AUTHORITY, true);
    ContentResolver.setIsSyncable(mAccount, Table.AUTHORITY, 1);
    if (ContentResolver.isSyncPending(mAccount, Table.AUTHORITY) ||
            ContentResolver.isSyncActive(mAccount, Table.AUTHORITY)) {
        ContentResolver.cancelSync(mAccount, Table.AUTHORITY);
    }
    ContentResolver.requestSync(mAccount, Table.AUTHORITY, extras);
    return true;
}
 
源代码4 项目: moVirt   文件: AccountManagerHelper.java
/**
 * Helper method to trigger an immediate sync ("refreshAccounts").
 * <p>
 * <p>This should only be used when we need to preempt the normal sync schedule. Typically, this
 * means the user has pressed the "refreshAccounts" button.
 * <p>
 * Note that SYNC_EXTRAS_MANUAL will cause an immediate sync, without any optimization to
 * preserve battery life. If you know new data is available (perhaps via a GCM notification),
 * but the user is not actively waiting for that data, you should omit this flag; this will give
 * the OS additional freedom in scheduling your sync request.
 */
public void triggerRefresh(MovirtAccount account) {
    Account acc = account.getAccount();
    Bundle b = new Bundle();
    // Disable sync backoff and ignore sync preferences. In other words...perform sync NOW!
    b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);

    // cancel sync because account will not sync if similar sync is already in progress
    if (ContentResolver.isSyncPending(acc, OVirtContract.CONTENT_AUTHORITY) ||
            ContentResolver.isSyncActive(acc, OVirtContract.CONTENT_AUTHORITY)) {
        ContentResolver.cancelSync(acc, OVirtContract.CONTENT_AUTHORITY);
    }

    ContentResolver.requestSync(acc, OVirtContract.CONTENT_AUTHORITY, b);
}
 
源代码5 项目: Cirrus_depricated   文件: FileActivity.java
protected void startSynchronization() {
    Log_OC.d(TAG, "Got to start sync");
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
        Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority());
        ContentResolver.cancelSync(null, MainApp.getAuthority());
        // cancel the current synchronizations of any ownCloud account
        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
                MainApp.getAuthority());
        ContentResolver.requestSync(
                getAccount(),
                MainApp.getAuthority(), bundle);
    } else {
        Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
                MainApp.getAuthority() + " with new API");
        SyncRequest.Builder builder = new SyncRequest.Builder();
        builder.setSyncAdapter(getAccount(), MainApp.getAuthority());
        builder.setExpedited(true);
        builder.setManual(true);
        builder.syncOnce();

        // Fix bug in Android Lollipop when you click on refresh the whole account
        Bundle extras = new Bundle();
        builder.setExtras(extras);

        SyncRequest request = builder.build();
        ContentResolver.requestSync(request);
    }
}
 
源代码6 项目: mytracks   文件: SyncUtils.java
/**
 * Syncs now for the current account.
 * 
 * @param context the context
 */
public static void syncNow(Context context) {
  Account[] accounts = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE);
  String googleAccount = PreferencesUtils.getString(
      context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
  for (Account account : accounts) {
    if (account.name.equals(googleAccount)) {
      ContentResolver.cancelSync(account, SYNC_AUTHORITY);
      ContentResolver.requestSync(account, SYNC_AUTHORITY, new Bundle());
      break;
    }
  }
}
 
源代码7 项目: mytracks   文件: SyncUtils.java
/**
 * Disables sync for all accounts.
 * 
 * @param context the context
 */
private static void disableSyncForAll(Context context) {
  Account[] accounts = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE);
  for (Account account : accounts) {
    ContentResolver.cancelSync(account, SYNC_AUTHORITY);
    ContentResolver.setIsSyncable(account, SYNC_AUTHORITY, 0);
    ContentResolver.setSyncAutomatically(account, SYNC_AUTHORITY, false);
  }
}
 
源代码8 项目: Woodmin   文件: WoodminSyncAdapter.java
public static void disablePeriodSync(Context context){
    Log.e(LOG_TAG, "disablePeriodSync");

    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    ContentResolver.cancelSync(account, authority);

    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    accountManager.removeAccount(account, null, null);
}
 
源代码9 项目: Woodmin   文件: WoodminSyncAdapter.java
public static void disablePeriodSync(Context context){
    Log.e(LOG_TAG, "disablePeriodSync");

    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    ContentResolver.cancelSync(account, authority);

    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    accountManager.removeAccount(account, null, null);
}
 
源代码10 项目: android_gisapp   文件: SettingsFragment.java
public static void moveMap(
        Activity activity,
        File path)
{
    MainApplication application = (MainApplication) activity.getApplication();
    if (null == application) {
        return;
    }

    ContentResolver.cancelSync(null, application.getAuthority());

    BackgroundMoveTask moveTask = new BackgroundMoveTask(activity, application.getMap(), path);
    moveTask.execute();
}
 
源代码11 项目: hr   文件: SyncUtils.java
public void cancelSync(String authority) {
    Account account = mUser.getAccount();
    ContentResolver.cancelSync(account, authority);
}
 
源代码12 项目: framework   文件: SyncUtils.java
public void cancelSync(String authority) {
    Account account = mUser.getAccount();
    ContentResolver.cancelSync(account, authority);
}
 
源代码13 项目: BatteryFu   文件: MainFunctions.java
/**
    * Start the scheduling process
    */
   public static void startScheduler(Context context, boolean syncFirst) {
      Log.i("BatteryFu", "Starting scheduler");

      Settings settings = Settings.getSettings(context);
      MainFunctions.showNotification(context, settings, context.getString(R.string.starting));

      // cancel account syncs
      ContentResolver.cancelSync(null, null);
      
      // let our widget know we're up
      Intent active = new Intent(context, ToggleWidget.class);
      active.setAction(ToggleWidget.ACTION_WIDGET_RECEIVER);
      active.setData(Uri.parse("batteryfu://enabled"));
      context.sendBroadcast(active);

      // if user has disabled fiddling with mobile data, restore APN type
//      if (!settings.isMobileDataEnabled()) {
//         APNSwitcher.enableMobileData(context, settings);
//      }

      // set up default flag values
      settings.setDataStateOn(true);
      settings.setSyncOnData(false);
      settings.setIsNightmode(false);
      settings.setIsTravelMode(false);
      settings.setDisconnectOnScreenOff(false);

      Settings.getSettings(context).setLastWakeTime(System.currentTimeMillis());
      AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      setupNightMode(context, settings, am);

      if (settings.isNightmodeOnly()) {
         // for nightmode only, no need for normal data alarms
         MainFunctions.showNotification(context, settings, context.getString(R.string.data_enabled_until_next_night_mode_start));
         // make sure data is infact on
         DataToggler.enableData(context, false);
      } else {
         setupDataAlarms(context, am, syncFirst);

         // go to sleep now
         if (DataToggler.disableData(context, true)) {
            MainFunctions.showNotificationWaitingForSync(context, settings);
         } else {
            // data being left on for some reason (e.g. data while screen on), make sure it is infact on
            DataToggler.enableData(context, false);
         }
      }
   }
 
源代码14 项目: v2ex   文件: SyncHelper.java
public static void requestManualSync(Context context, Bundle args) {
    Account account = AccountUtils.getActiveAccount(context);
    if (account != null) {
        LOGD(TAG, "Requesting manual sync for account " + account.name
                +" args=" + args.toString());

        args.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        args.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
        args.putBoolean(SyncAdapter.EXTRA_SYNC_REMOTE, false);

        AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
        accountManager.addAccountExplicitly(account, null, null);

        // Inform the system that this account is eligible for auto sync when the network is up
        ContentResolver.setSyncAutomatically(account, V2exContract.CONTENT_AUTHORITY, true);

        // Inform the system that this account supports sync
        ContentResolver.setIsSyncable(account, V2exContract.CONTENT_AUTHORITY, 1);

        boolean pending = ContentResolver.isSyncPending(account,
                V2exContract.CONTENT_AUTHORITY);
        if (pending) {
            LOGD(TAG, "Warning: sync is PENDING. Will cancel.");
        }
        boolean active = ContentResolver.isSyncActive(account,
                V2exContract.CONTENT_AUTHORITY);
        if (active) {
            LOGD(TAG, "Warning: sync is ACTIVE. Will cancel.");
        }

        if (pending || active) {
            LOGD(TAG, "Cancelling previously pending/active sync.");
            ContentResolver.cancelSync(account, V2exContract.CONTENT_AUTHORITY);
        }

        LOGD(TAG, "Requesting sync now.");
        ContentResolver.requestSync(account, V2exContract.CONTENT_AUTHORITY, args);
    } else {
        LOGD(TAG, "Can't request manual sync -- no chosen account.");
    }
}