List of usage examples for android.content ContentResolver setIsSyncable
public static void setIsSyncable(Account account, String authority, int syncable)
From source file:org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.java
protected void unsafeTransitionToStageEndpoints(String authServerEndpoint, String tokenServerEndpoint, String profileServerEndpoint) { try {/*from w w w . ja va 2s . co m*/ getReadingListPrefs().edit().clear().commit(); } catch (UnsupportedEncodingException | GeneralSecurityException e) { // Ignore. } try { getSyncPrefs().edit().clear().commit(); } catch (UnsupportedEncodingException | GeneralSecurityException e) { // Ignore. } State state = getState(); setState(state.makeSeparatedState()); accountManager.setUserData(account, ACCOUNT_KEY_IDP_SERVER, authServerEndpoint); accountManager.setUserData(account, ACCOUNT_KEY_TOKEN_SERVER, tokenServerEndpoint); accountManager.setUserData(account, ACCOUNT_KEY_PROFILE_SERVER, profileServerEndpoint); ContentResolver.setIsSyncable(account, BrowserContract.READING_LIST_AUTHORITY, 1); }
From source file:com.nononsenseapps.notepad.MainActivity.java
private void enableSync() { final Activity activity = this; // Get the first Google account on the device final Account[] accounts = AccountManager.get(activity).getAccountsByType("com.google"); if (accounts.length > 0) { final Account account = accounts[0]; // Request access AccountManager.get(activity).getAuthToken(account, SyncAdapter.AUTH_TOKEN_TYPE, null, activity, new AccountManagerCallback<Bundle>() { @Override//from ww w.j av a2 s. c o m public void run(AccountManagerFuture<Bundle> future) { // This is the callback class, it handles all the // steps // after requesting access try { String token = future.getResult().getString(AccountManager.KEY_AUTHTOKEN); if (token != null && !token.equals("") && account != null) { // Get preference editor Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit(); // Write account name to prefs editor.putString(SyncPrefs.KEY_ACCOUNT, account.name); // Set it syncable ContentResolver.setIsSyncable(account, NotePad.AUTHORITY, 1); // Write to pref editor.putBoolean(SyncPrefs.KEY_SYNC_ENABLE, true); // Commit prefs editor.commit(); // Then request sync requestSync(account.name); } } catch (OperationCanceledException e) { Log.e("SyncFix", "Error1"); // if the request was canceled for any reason } catch (AuthenticatorException e) { Log.e("SyncFix", "Error2"); // if there was an error communicating with the // authenticator or // if the authenticator returned an invalid // response } catch (IOException e) { Log.e("SyncFix", "Error3"); // if the authenticator returned an error // response that // indicates that it encountered an IOException // while // communicating with the authentication server } } }, null); } }