List of usage examples for android.content ContentResolver setIsSyncable
public static void setIsSyncable(Account account, String authority, int syncable)
From source file:net.sf.diningout.content.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult result) {//from w w w . ja va 2 s . c o m Account selected = Accounts.selected(); if (!account.equals(selected)) { if (selected != null) { // never going to sync this account that wasn't selected ContentResolver.setIsSyncable(account, AUTHORITY, 0); } return; } if (extras.containsKey(SYNC_EXTRAS_INITIALIZE)) { return; // will initialise on first normal sync } Context context = getContext(); SharedPreferences prefs = Prefs.get(context, APP); try { if (!prefs.getBoolean(ACCOUNT_INITIALISED, false)) { // first run, log the user in initUser(context, provider); } if (extras.getBoolean(SYNC_EXTRAS_CONTACTS_ONLY)) { refreshContacts(context, provider); uploadContacts(context, provider); return; } if (!prefs.getBoolean(ONBOARDED, false)) { return; // don't sync yet } long now = System.currentTimeMillis(); // full upload and download daily boolean dailySync = now - prefs.getLong(LAST_SYNC, 0L) >= DAY_IN_MILLIS; if (dailySync || extras.containsKey(SYNC_EXTRAS_MANUAL)) { extras.putBoolean(SYNC_EXTRAS_UPLOAD, true); extras.putBoolean(SYNC_EXTRAS_DOWNLOAD, true); refreshContacts(context, provider); } if (extras.containsKey(SYNC_EXTRAS_UPLOAD) || extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) { uploadContacts(context, provider); uploadRestaurants(provider); uploadReviews(provider); uploadReviewDrafts(provider); } if (extras.containsKey(SYNC_EXTRAS_DOWNLOAD)) { download(provider); prefs.edit().putLong(LAST_SYNC, now).apply(); if (dailySync) { refreshRestaurants(context, provider); geofenceRestaurants(context, provider); } Notifications.sync(context); } if (!prefs.contains(CLOUD_ID)) { // get GCM registration ID and user notification key String id = uploadCloudId(context); if (!TextUtils.isEmpty(id)) { prefs.edit().putString(CLOUD_ID, id).apply(); // todo service returns HTTP 401, probably should decouple this from cloud_id // String key = getCloudNotificationKey(context, selected, id); // if (!TextUtils.isEmpty(key)) { // prefs.edit().putString(CLOUD_NOTIFICATION_KEY, key).apply(); // } } } } catch (RemoteException e) { result.databaseError = true; Log.e(TAG, "syncing the ContentProvider", e); exception(e); } }
From source file:org.klnusbaum.udj.auth.AuthActivity.java
/** * Called when response is received from the server for authentication * request. See onAuthenticationResult(). Sets the * AccountAuthenticatorResult which is sent back to the caller. We store the * authToken that's returned from the server as the 'password' for this * account - so we're never storing the user's actual password locally. * * @param result the confirmCredentials result. *//*w w w. j a va 2 s.c om*/ private void finishLogin(ServerConnection.AuthResult authResult) { Log.i(TAG, "finishLogin()"); final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, null); ContentResolver.setIsSyncable(account, Constants.AUTHORITY, 0); } else { mAccountManager.setPassword(account, mPassword); } mAccountManager.setUserData(account, Constants.USER_ID_DATA, authResult.userId); mAccountManager.setUserData(account, Constants.LAST_PLAYER_ID_DATA, Constants.NO_PLAYER_ID); mAccountManager.setUserData(account, Constants.PLAYER_STATE_DATA, Integer.toString(Constants.NOT_IN_PLAYER)); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); intent.putExtra(Constants.ACCOUNT_EXTRA, account); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:org.voidsink.anewjkuapp.activity.KusssAuthenticatorActivity.java
private void finishLogin(Intent intent) { String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountPassword = intent.getStringExtra(PARAM_USER_PASS); String accountType = intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE); Log.i(TAG, "finish login to " + accountName); Account account;/*from w w w.ja v a 2 s. com*/ boolean addNewAccount; final Account oldAccount = AppUtils.getAccount(this); if (oldAccount != null) { if (oldAccount.name.equals(accountName)) { account = oldAccount; addNewAccount = false; } else { AppUtils.removeAccout(mAccountManager, oldAccount); account = new Account(accountName, accountType); addNewAccount = true; } } else { account = new Account(accountName, accountType); addNewAccount = true; } if (addNewAccount) { String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN); String authtokenType = mAuthTokenType; // Creating the account on the device and setting the auth token we // got // (Not setting the auth token will cause another call to the server // to authenticate the user) mAccountManager.addAccountExplicitly(account, accountPassword, null); mAccountManager.setAuthToken(account, authtokenType, authtoken); mAccountManager.setPassword(account, accountPassword); // Turn on periodic syncing long interval = PreferenceWrapper.getSyncInterval(this) * 60 * 60; ContentResolver.addPeriodicSync(account, CalendarContractWrapper.AUTHORITY(), new Bundle(), interval); ContentResolver.addPeriodicSync(account, KusssContentContract.AUTHORITY, new Bundle(), interval); // Inform the system that this account supports sync ContentResolver.setIsSyncable(account, CalendarContractWrapper.AUTHORITY(), 1); ContentResolver.setIsSyncable(account, KusssContentContract.AUTHORITY, 1); // Inform the system that this account is eligible for auto sync // when the network is up ContentResolver.setSyncAutomatically(account, CalendarContractWrapper.AUTHORITY(), true); ContentResolver.setSyncAutomatically(account, KusssContentContract.AUTHORITY, true); // Recommend a schedule for automatic synchronization. The system // may modify this based // on other scheduled syncs and network utilization. } else { mAccountManager.setPassword(account, accountPassword); } // Kalender aktualisieren CalendarUtils.createCalendarsIfNecessary(this, account); // Sync NOW KusssAuthenticator.triggerSync(this); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }
From source file:com.dogar.geodesic.map.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_CANCELED) this.finish(); switch (requestCode) { case REQUEST_ACCOUNT_PICKER: if (data != null && data.getExtras() != null) { String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME); if (accountName != null) { SharedPreferences.Editor editor = settings.edit(); editor.putString("ACCOUNT_NAME", accountName); editor.commit();// ww w.j a v a 2 s . c om setAccountName(accountName); if (mAdapter != null) { mAdapter.setHeaderTitle(accountName, 0); mAdapter.notifyDataSetChanged(); mDrawerList.setAdapter(mAdapter); } ContentResolver.setIsSyncable(credential.getSelectedAccount(), AUTHORITY, 1); setGMFragment(); } } break; } }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.custom.data.DTHelper.java
/** * Enable auot sync for the activity life-cycle * //from w w w.j a v a2 s.com * @throws NameNotFoundException * @throws DataException */ public static void activateAutoSync() { try { String authority = Constants.getAuthority(mContext); Account account = new Account(eu.trentorise.smartcampus.ac.Constants.getAccountName(mContext), eu.trentorise.smartcampus.ac.Constants.getAccountType(mContext)); ContentResolver.setIsSyncable(account, authority, 1); ContentResolver.setSyncAutomatically(account, authority, true); ContentResolver.addPeriodicSync(account, authority, new Bundle(), Constants.SYNC_INTERVAL * 60); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.odoo.MainActivity.java
/** * Sets the sync periodic.// w ww .j a v a 2 s. com * * @param authority * the authority * @param interval_in_minute * the interval_in_minute * @param seconds_per_minute * the seconds_per_minute * @param milliseconds_per_second * the milliseconds_per_second */ public void setSyncPeriodic(String authority, long interval_in_minute, long seconds_per_minute, long milliseconds_per_second) { Account account = OdooAccountManager.getAccount(this, OUser.current(mContext).getAndroidName()); Bundle extras = new Bundle(); this.setAutoSync(authority, true); ContentResolver.setIsSyncable(account, authority, 1); final long sync_interval = interval_in_minute * seconds_per_minute * milliseconds_per_second; ContentResolver.addPeriodicSync(account, authority, extras, sync_interval); }
From source file:org.ohmage.authenticator.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. * /*from w ww .java 2 s . c om*/ * @param the confirmCredentials result. */ protected void createAccount() { Log.v(TAG, "finishLogin()"); final Account account = new Account(mUsername, OhmageApplication.ACCOUNT_TYPE); Bundle userData = new Bundle(); userData.putString(KEY_OHMAGE_SERVER, ConfigHelper.serverUrl()); mAuthtoken = mHashedPassword; if (TextUtils.isEmpty(mAuthtoken)) { Log.w(TAG, "Trying to create account with empty password"); return; } if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, userData); mAccountManager.setAuthToken(account, OhmageApplication.AUTHTOKEN_TYPE, mAuthtoken); // Set sync for this account. ContentResolver.setIsSyncable(account, DbContract.CONTENT_AUTHORITY, 1); ContentResolver.setSyncAutomatically(account, DbContract.CONTENT_AUTHORITY, true); ContentResolver.addPeriodicSync(account, DbContract.CONTENT_AUTHORITY, new Bundle(), 3600); } else { mAccountManager.setPassword(account, mPassword); } final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, OhmageApplication.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(OhmageApplication.AUTHTOKEN_TYPE)) { intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); } setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); mPreferencesHelper.edit().putLoginTimestamp(System.currentTimeMillis()).commit(); if (UserPreferencesHelper.isSingleCampaignMode()) { // Download the single campaign showDialog(DIALOG_DOWNLOADING_CAMPAIGNS); getSupportLoaderManager().restartLoader(0, null, this); } else { finishLogin(); } }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.AccountActivity.java
private void finishSetup() { ContentResolver.setIsSyncable(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY, 1); ContentResolver.setSyncAutomatically(mChosenAccount, ScheduleContract.CONTENT_AUTHORITY, true); SyncHelper.requestManualSync(mChosenAccount); PrefUtils.markSetupDone(this); if (mFinishIntent != null) { // Ensure the finish intent is unique within the task. Otherwise, if the task was // started with this intent, and it finishes like it should, then startActivity on // the intent again won't work. mFinishIntent.addCategory(POST_AUTH_CATEGORY); startActivity(mFinishIntent);//from w w w . j a v a 2s. c o m } finish(); }
From source file:org.mozilla.gecko.fxa.authenticator.AndroidFxAccount.java
public void setAuthoritiesToSyncAutomaticallyMap(Map<String, Boolean> authoritiesToSyncAutomaticallyMap) { if (authoritiesToSyncAutomaticallyMap == null) { throw new IllegalArgumentException("authoritiesToSyncAutomaticallyMap must not be null"); }/* ww w. j av a2 s. c o m*/ for (String authority : DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.keySet()) { boolean authorityEnabled = DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.get(authority); final Boolean enabled = authoritiesToSyncAutomaticallyMap.get(authority); if (enabled != null) { authorityEnabled = enabled.booleanValue(); } // Accounts are always capable of being synced ... ContentResolver.setIsSyncable(account, authority, 1); // ... but not always automatically synced. ContentResolver.setSyncAutomatically(account, authority, authorityEnabled); } }
From source file:com.openerp.MainActivity.java
/** * Sets the sync periodic./*from w w w . ja va2s .c o m*/ * * @param authority * the authority * @param interval_in_minute * the interval_in_minute * @param seconds_per_minute * the seconds_per_minute * @param milliseconds_per_second * the milliseconds_per_second */ public void setSyncPeriodic(String authority, long interval_in_minute, long seconds_per_minute, long milliseconds_per_second) { Account account = OpenERPAccountManager.getAccount(this, OEUser.current(mContext).getAndroidName()); Bundle extras = new Bundle(); this.setAutoSync(authority, true); ContentResolver.setIsSyncable(account, authority, 1); final long sync_interval = interval_in_minute * seconds_per_minute * milliseconds_per_second; ContentResolver.addPeriodicSync(account, authority, extras, sync_interval); }