Example usage for android.content ContentResolver cancelSync

List of usage examples for android.content ContentResolver cancelSync

Introduction

In this page you can find the example usage for android.content ContentResolver cancelSync.

Prototype

public static void cancelSync(Account account, String authority) 

Source Link

Document

Cancel any active or pending syncs that match account and authority.

Usage

From source file:com.manning.androidhacks.hack023.MainActivity.java

public void refresh(View v) {
    Bundle extras = new Bundle();
    extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);

    Account account = ((HackApplication) getApplication()).getCurrentAccount();

    if (ContentResolver.isSyncPending(account, TodoContentProvider.AUTHORITY)) {
        ContentResolver.cancelSync(account, TodoContentProvider.AUTHORITY);
    }/*from w  ww  .j  a v  a  2  s . c  o  m*/

    ContentResolver.requestSync(account, TodoContentProvider.AUTHORITY, extras);
}

From source file:dev.drsoran.moloko.sync.util.SyncUtils.java

public final static void cancelSync(Context context) {
    final Account account = AccountUtils.getRtmAccount(context);

    if (account != null)
        ContentResolver.cancelSync(account, Rtm.AUTHORITY);
}

From source file:com.manning.androidhacks.hack023.authenticator.Authenticator.java

@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account)
        throws NetworkErrorException {
    Bundle result = super.getAccountRemovalAllowed(response, account);

    if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT)
            && !result.containsKey(AccountManager.KEY_INTENT)) {
        boolean allowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);

        if (allowed) {
            for (int i = 0; i < authoritiesToSync.length; i++) {
                ContentResolver.cancelSync(account, authoritiesToSync[i]);
            }//from w  ww.  ja v  a2  s  .co m

            mContext.deleteDatabase(DatabaseHelper.DATABASE_NAME);
        }
    }

    return result;
}

From source file:eu.alefzero.owncloud.ui.activity.FileDisplayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean retval = true;
    switch (item.getItemId()) {
    case R.id.createDirectoryItem: {
        showDialog(DIALOG_CREATE_DIR);/*from w  w w. java  2 s.  co  m*/
        break;
    }
    case R.id.startSync: {
        ContentResolver.cancelSync(null, "org.owncloud"); // cancel the current synchronizations of any ownCloud account
        Bundle bundle = new Bundle();
        bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
        ContentResolver.requestSync(AccountUtils.getCurrentOwnCloudAccount(this), "org.owncloud", bundle);
        break;
    }
    case R.id.action_upload: {
        Intent action = new Intent(Intent.ACTION_GET_CONTENT);
        action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(Intent.createChooser(action, "Upload file from..."), ACTION_SELECT_FILE);
        break;
    }
    case R.id.action_settings: {
        Intent settingsIntent = new Intent(this, Preferences.class);
        startActivity(settingsIntent);
        break;
    }
    case R.id.about_app: {
        showDialog(DIALOG_ABOUT_APP);
        break;
    }
    case android.R.id.home: {
        if (mCurrentDir != null && mCurrentDir.getParentId() != 0) {
            onBackPressed();
        }
        break;
    }
    default:
        retval = false;
    }
    return retval;
}

From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java

/**
 *
 * Called when response is received from the server for authentication request. See
 * onAuthenticationResult(). Sets the AccountAuthenticatorResult which is sent back to the
 * caller. Also sets the authToken in AccountManager for this account.
 *
 * @param userData//from  ww  w .j a  va2 s .  c  o  m
 *            TODO
 * @param the
 *            confirmCredentials result.
 */

protected void finishLogin(Bundle userData) {
    Log.i(TAG, "finishLogin()");
    // ensure that there isn't a demo account sticking around.

    // TODO this is NOT the place where this code belongs. Find it a better home
    if (Authenticator.isDemoMode(this)) {
        Log.d(TAG, "cleaning up demo mode account...");
        ContentResolver.cancelSync(Authenticator.getFirstAccount(this), MediaProvider.AUTHORITY);

        mAccountManager.removeAccount(
                new Account(Authenticator.DEMO_ACCOUNT, AuthenticationService.ACCOUNT_TYPE),
                new AccountManagerCallback<Boolean>() {

                    @Override
                    public void run(AccountManagerFuture<Boolean> arg0) {
                        try {
                            if (arg0.getResult()) {

                                final ContentValues cv = new ContentValues();
                                // invalidate all the content to force a sync.
                                // this is to ensure that items which were marked favorite get set as
                                // such.
                                cv.put(Cast._SERVER_MODIFIED_DATE, 0);
                                cv.put(Cast._MODIFIED_DATE, 0);
                                getContentResolver().update(Cast.CONTENT_URI, cv, null, null);
                                if (Constants.DEBUG) {
                                    Log.d(TAG, "reset all cast modified dates to force a reload");
                                }
                            }
                        } catch (final OperationCanceledException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (final AuthenticatorException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (final IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }, null);

    }
    final Account account = new Account(mUsername, AuthenticationService.ACCOUNT_TYPE);

    if (mRequestNewAccount) {
        mAccountManager.addAccountExplicitly(account, mPassword, userData);
        // Automatically enable sync for this account
        ContentResolver.setSyncAutomatically(account, MediaProvider.AUTHORITY, true);
    } else {
        mAccountManager.setPassword(account, mPassword);
    }
    final Intent intent = new Intent();
    mAuthtoken = mPassword;
    intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
    intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AuthenticationService.ACCOUNT_TYPE);
    if (mAuthtokenType != null && mAuthtokenType.equals(AuthenticationService.AUTHTOKEN_TYPE)) {
        intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken);
    }
    setAccountAuthenticatorResult(intent.getExtras());
    setResult(RESULT_OK, intent);
    finish();
}

From source file:com.odoo.MainActivity.java

/**
 * Cancel sync.//from w  w  w  .  j a v  a 2 s .  c  o  m
 * 
 * @param authority
 *            the authority
 */
public void cancelSync(String authority) {
    Account account = OdooAccountManager.getAccount(this, OUser.current(mContext).getAndroidName());
    ContentResolver.cancelSync(account, authority);
}

From source file:com.openerp.MainActivity.java

/**
 * Cancel sync.//from w ww  . j a va2  s . co m
 * 
 * @param authority
 *            the authority
 */
public void cancelSync(String authority) {
    Account account = OpenERPAccountManager.getAccount(this, OEUser.current(mContext).getAndroidName());
    ContentResolver.cancelSync(account, authority);
}

From source file:com.digitalarx.android.ui.activity.FileDisplayActivity.java

private void startSynchronization() {
    Log_OC.e(TAG, "Got to start sync");
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
        Log_OC.e(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.e(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority());
        ContentResolver.requestSync(getAccount(), MainApp.getAuthority(), bundle);
    } else {/*from   w w  w .java2  s  .  c  om*/
        Log_OC.e(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();
        SyncRequest request = builder.build();
        ContentResolver.requestSync(request);
    }
}

From source file:com.cerema.cloud2.ui.activity.FileDisplayActivity.java

private 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 {/*from   w  w w.  ja v  a2 s  . c om*/
        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);
    }
}

From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java

private void startSynchronization() {
    ContentResolver.cancelSync(null, AccountAuthenticator.AUTHORITY); // cancel
                                                                      // the
                                                                      // current
                                                                      // synchronizations
                                                                      // of
                                                                      // any
                                                                      // ownCloud
                                                                      // account
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getAccount(), AccountAuthenticator.AUTHORITY, bundle);

    shareDetailsSync();//from  www.j  a v a  2  s .  c o  m
}