List of usage examples for android.content ContentResolver setSyncAutomatically
public static void setSyncAutomatically(Account account, String authority, boolean sync)
From source file:edu.mit.mobile.android.locast.accounts.Authenticator.java
/** * Adds an account that acts as a placeholder to allow the sync to work properly. The sync * framework always requires an account. * * @param context/*from ww w.j av a 2 s. c o m*/ */ public static void addDemoAccount(Context context) { final Account[] accounts = Authenticator.getAccounts(context); if (accounts.length > 0) { // if there's already a demo account, we don't want to add another. // if there isn't, we're not going to delete the actual account. return; } final AccountManager am = AccountManager.get(context); final Account account = new Account(DEMO_ACCOUNT, AuthenticationService.ACCOUNT_TYPE); am.addAccountExplicitly(account, null, null); ContentResolver.setSyncAutomatically(account, MediaProvider.AUTHORITY, true); }
From source file:com.murrayc.galaxyzoo.app.LoginUtils.java
static void setAutomaticAccountSync(final Context context, final Account account) { final ContentResolver resolver = context.getContentResolver(); if (resolver == null) { return;// w w w . ja va2 s . c o m } ContentResolver.setSyncAutomatically(account, Item.AUTHORITY, true); }
From source file:com.gaba.alex.trafficincidents.MainActivity.java
private Account createSyncAccount() { Account appAccount = new Account(mAccountName, mAccountType); AccountManager accountManager = AccountManager.get(this); if (accountManager.addAccountExplicitly(appAccount, null, null)) { ContentResolver.setMasterSyncAutomatically(true); ContentResolver.setSyncAutomatically(appAccount, AUTHORITY, true); }//from w w w . ja v a 2s . c o m return appAccount; }
From source file:pt.up.mobile.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. 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. * /* ww w . j ava 2 s . c o m*/ * @param result * the confirmCredentials result. */ @TargetApi(8) private void finishLogin(final User user) { Log.i(TAG, "finishLogin()"); new Thread(new Runnable() { @Override public void run() { final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { final ContentValues values = new ContentValues(); values.put(SigarraContract.Users.CODE, user.getUserCode()); values.put(SigarraContract.Users.TYPE, user.getType()); values.put(SigarraContract.Users.ID, account.name); getContentResolver().insert(SigarraContract.Users.CONTENT_URI, values); // Set contacts sync for this account. if (!mAccountManager.addAccountExplicitly(account, mPassword, Bundle.EMPTY)) { getContentResolver().delete(SigarraContract.Users.CONTENT_URI, SigarraContract.Users.PROFILE, SigarraContract.Users.getUserSelectionArgs(account.name)); finish(); } String syncIntervalValue = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()) .getString(getString(R.string.key_sync_interval), Integer.toString(getResources().getInteger(R.integer.default_sync_interval))); String syncNotIntervalValue = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()) .getString(getString(R.string.key_notifications_sync_interval), Integer.toString(getResources().getInteger(R.integer.default_sync_interval))); ContentResolver.setSyncAutomatically(account, SigarraContract.CONTENT_AUTHORITY, true); ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { ContentResolver.addPeriodicSync(account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY, Integer.parseInt(syncIntervalValue) * 3600); ContentResolver.addPeriodicSync(account, SigarraContract.CONTENT_AUTHORITY, SigarraSyncAdapterUtils.getNotificationsPeriodicBundle(), Integer.parseInt(syncNotIntervalValue) * 3600); } else { PeriodicSyncReceiver.cancelPreviousAlarms(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY); PeriodicSyncReceiver.addPeriodicSync(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, Bundle.EMPTY, Integer.parseInt(syncIntervalValue) * 3600); PeriodicSyncReceiver.addPeriodicSync(getApplicationContext(), account, SigarraContract.CONTENT_AUTHORITY, SigarraSyncAdapterUtils.getNotificationsBundle(), Integer.parseInt(syncNotIntervalValue) * 3600); } } else { mAccountManager.setPassword(account, user.getPassword()); } final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); } }).start(); }
From source file:p1.nd.khan.jubair.mohammadd.popularmovies.sync.MovieSyncAdapter.java
/** * Method to Sync data after account creation. * * @param newAccount instance of new account * @param context The context used to access the account service. *//* w ww. j a v a 2 s . c o m*/ private static void onAccountCreated(Account newAccount, Context context) { MovieSyncAdapter.configurePeriodicSync(context, Constants.SYNC_INTERVAL, Constants.SYNC_FLEXTIME); ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true); syncImmediately(context); }
From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java
private static void onAccountCreated(Account newAccount, Context context) { Log.d(LOG_TAG, "CREATED NEW ACCOUNT"); SyncAdapter.configurePeriodicSync(context, SYNC_INTERVAL, FLEX_TIME); ContentResolver.setSyncAutomatically(newAccount, context.getString(R.string.content_authority), true); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences.edit().putLong(context.getString(R.string.last_update), System.currentTimeMillis()).apply(); SyncAdapter.syncImmediately(context); }
From source file:org.gots.ui.BaseGotsActivity.java
protected void onRefresh(String AUTHORITY) { if (AUTHORITY == null || "".equals(AUTHORITY)) { Log.d(TAG, "You call onRefresh without Content Resolver Authority"); return;//from w w w . j ava 2s.c o m } Account userAccount = gotsPrefs.getUserAccount(); ContentResolver.setSyncAutomatically(userAccount, AUTHORITY, true); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(userAccount, AUTHORITY, bundle); }
From source file:com.gaba.alex.trafficincidents.MainActivity.java
private void configurePeriodicSync(Account appAccount) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); int hourlySyncInterval = Integer .parseInt(preferences.getString(getString(R.string.pref_auto_refresh_key), "6")); if (hourlySyncInterval == 0) { ContentResolver.setSyncAutomatically(appAccount, AUTHORITY, false); } else {/*from www . ja v a2 s . com*/ long syncInterval = hourlySyncInterval * SECONDS_PER_HOUR; ContentResolver.setSyncAutomatically(appAccount, AUTHORITY, true); ContentResolver.addPeriodicSync(appAccount, AUTHORITY, Bundle.EMPTY, syncInterval); } }
From source file:com.sintef_energy.ubisolar.activities.DrawerActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); if (requestCode == LOGIN_CALL_ID) { if (resultCode == Activity.RESULT_OK) { Log.v(TAG, "Login was successful. Starting to attain session data."); startFacebookLogin(null);//from www . jav a 2 s .c om // Find the account Account[] accounts = getAccounts(getApplicationContext(), ACCOUNT_TYPE); for (Account account : accounts) { if (account.name.equals(data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME))) { mAccount = account; break; } } if (mAccount == null) { Log.e(TAG, "Account creation somehow failed to make an account."); return; } /* The same as ticking allow sync */ ContentResolver.setSyncAutomatically(mAccount, AUTHORITY_PROVIDER, true); /* Request a sync operation */ Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); //Do sync regardless of settings bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); //Force sync immediately ContentResolver.requestSync(mAccount, AUTHORITY_PROVIDER, bundle); /* Update all -1 users to the current user id. */ AccountManager accountManager = (AccountManager) getApplicationContext() .getSystemService(ACCOUNT_SERVICE); String facebookUID = accountManager.getUserData(mAccount, Global.DATA_FB_UID); ContentValues values = new ContentValues(); values.put(DeviceModel.DeviceEntry.COLUMN_USER_ID, facebookUID); values.put(DeviceModel.DeviceEntry.COLUMN_LAST_UPDATED, System.currentTimeMillis() / 1000L); getContentResolver().update(EnergyContract.Devices.CONTENT_URI, values, EnergyContract.Devices.COLUMN_USER_ID + "=?", new String[] { "-1" }); //Publish a post saying you started using Wattitude RequestManager.getInstance().doFriendRequest().createWallPost( new NewsFeedPost(0, Long.valueOf(facebookUID), 1, System.currentTimeMillis() / 1000), null); } else { Log.v(TAG, "Login failed"); } } }
From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
/** * /*from ww w . ja v a 2 s. c o m*/ * 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 the confirmCredentials result. */ protected void finishLogin() { Log.i(tag, "finishLogin()"); final Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); if (mRequestNewAccount) { mAccountManager.addAccountExplicitly(account, mPassword, null); mAccountManager.setUserData(account, Constants.PHONE_NUMBER_KEY, countryCode + mPhone); // Set contacts sync for this account. ContentResolver.setSyncAutomatically(account, ContactsContract.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, Constants.ACCOUNT_TYPE); if (mAuthtokenType != null && mAuthtokenType.equals(Constants.AUTHTOKEN_TYPE)) intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAuthtoken); Db.deleteServerData(getApplicationContext()); setAccountAuthenticatorResult(intent.getExtras()); setResult(RESULT_OK, intent); finish(); }