List of usage examples for android.content ContentResolver requestSync
public static void requestSync(Account account, String authority, Bundle extras)
From source file:eu.masconsult.bgbanking.activity.HomeActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuItem refreshItem = menu.add(R.string.menu_item_refresh); refreshItem.setIcon(R.drawable.ic_menu_refresh); refreshItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); refreshItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override// w w w . j a v a 2s . c om public boolean onMenuItemClick(MenuItem item) { AccountManager accountManager = AccountManager.get(HomeActivity.this); if (accountManager == null) { return false; } long cnt = 0; Bank[] banks = Bank.values(); for (Bank bank : banks) { for (Account account : accountManager .getAccountsByType(bank.getAccountType(HomeActivity.this))) { Log.v(TAG, String.format("account: %s, %s, %s", account.name, account.type, ContentResolver.getIsSyncable(account, BankingContract.AUTHORITY))); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(account, BankingContract.AUTHORITY, bundle); cnt++; } } EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "refresh", cnt); return true; } }); MenuItem addAccountItem = menu.add(R.string.menu_item_add_account); addAccountItem.setIcon(R.drawable.ic_menu_add); addAccountItem .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); addAccountItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { addAccount(); EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "add_account", 1l); return true; } }); MenuItem sendFeedback = menu.add(R.string.menu_item_send_feedback); sendFeedback.setIcon(R.drawable.ic_menu_start_conversation); sendFeedback.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); sendFeedback.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { PackageInfo manager; try { manager = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { manager = new PackageInfo(); manager.versionCode = 0; manager.versionName = "undef"; } try { startActivity(new Intent(Intent.ACTION_SEND).setType("plain/text") .putExtra(Intent.EXTRA_EMAIL, new String[] { "bgbanks@masconsult.eu" }) .putExtra(Intent.EXTRA_SUBJECT, "BG Banks v" + manager.versionName + "-" + manager.versionCode + " feedback")); EasyTracker.getTracker().trackEvent("ui_action", "menu_item_click", "send_feedback", 1l); } catch (ActivityNotFoundException e) { Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } return true; } }); return true; }
From source file:org.codarama.haxsync.activities.WelcomeActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.nav_home: { // Create fragment and give it an argument specifying the article it should show HomeFragment newFragment = new HomeFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit();//from w w w. jav a 2s.c om return true; } case R.id.nav_settings: { Intent preferences = new Intent(getApplicationContext(), PreferencesActivity.class); startActivity(preferences); return true; } // as per https://developer.android.com/training/sync-adapters/running-sync-adapter.html // we might want to reconsider allowing manual sync - the basic flaw in this design is // that the user could not be trusted to know when it is the best time to sync case R.id.nav_manual_sync: { Log.d(TAG, "User requested manual sync"); SyncAccount syncAccount = new SyncAccount(AccountManager.get(WelcomeActivity.this)); Account account = syncAccount.getHaxSyncAccount(getResources().getString(R.string.ACCOUNT_TYPE)); // Pass the settings flags by inserting them in a bundle Bundle settingsBundle = new Bundle(); settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(account, "com.android.contacts", settingsBundle); ContentResolver.requestSync(account, "com.android.calendar", settingsBundle); return true; } default: { // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. return super.onOptionsItemSelected(item); } } }
From source file:org.sufficientlysecure.keychain.service.ContactSyncAdapterService.java
public static void requestContactsSync() { // if user has disabled automatic sync, do nothing boolean isSyncEnabled = ContentResolver.getSyncAutomatically( new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE), ContactsContract.AUTHORITY); if (!isSyncEnabled) { return;//www .ja v a2s. c o m } Bundle extras = new Bundle(); // no need to wait, do it immediately extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); ContentResolver.requestSync(new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE), ContactsContract.AUTHORITY, extras); }
From source file:org.level28.android.moca.ui.schedule.ScheduleActivity.java
/** * Perform a manual synchronization/* w w w . java 2 s.com*/ */ private void triggerRefresh() { Bundle extras = new Bundle(); extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync( new Account(MocaAuthenticator.HARDCODED_USERNAME, MocaAuthenticator.ACCOUNT_TYPE), ScheduleContract.CONTENT_AUTHORITY, extras); }
From source file:org.ohmage.fragments.HomeFragment.java
@Override public void onRefreshStarted(View view) { Account[] accounts = am.getAccountsByType(AuthUtil.ACCOUNT_TYPE); for (Account account : accounts) { Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(account, OhmageContract.CONTENT_AUTHORITY, bundle); }//from w ww. ja v a 2s. c o m }
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);//ww w. j a v a 2 s . c o 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:com.ntsync.android.sync.activities.KeyPasswordActivity.java
/** * Called when KeyPassword was set./*from w w w.j a v a 2 s.c o m*/ * * @param result * the confirmCredentials result. */ private void finishSetKeyPassword() { Log.i(TAG, "finishSetKeyPassword()"); final Intent intent = new Intent(); intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername); intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE); setResult(RESULT_OK, intent); Account account = new Account(mUsername, Constants.ACCOUNT_TYPE); ContentResolver.requestSync(account, Constants.CONTACT_AUTHORITY, new Bundle()); // Remove notification clearNotification(account.name); finish(); }
From source file:p1.nd.khan.jubair.mohammadd.popularmovies.sync.MovieSyncAdapter.java
/** * Helper method to have the sync adapter immediately * * @param context The context used to access the account service *//* w w w.j av a2 s .co m*/ public static void syncImmediately(Context context) { Log.v("LOG_TAG", "===[called syncImmediately ]: "); Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }
From source file:p1.nd.khan.jubair.mohammadd.popularmovies.sync.MovieSyncAdapter.java
/** * Helper method to have the sync adapter immediately * * @param context The context used to access the account service * @param movieId The Movie to be sync/*w w w . j a v a2 s. c om*/ */ public static void syncMovieDetails(Context context, String movieId) { Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); if (null != movieId) { bundle.putString(Constants.DETAIL_SYNC_MOVIE_ID, movieId); } ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle); }
From source file:com.ntsync.android.sync.activities.PaymentVerificationService.java
private void processResult(Context context, AccountManager acm, Account account, PayPalConfirmationResult result) { boolean removePayment = false; int msg = -1; Class<? extends Activity> activityClass = ShopActivity.class; LogHelper.logI(TAG, "PaymentVerification Result: " + result); switch (result) { case SUCCESS: removePayment = true;/*w w w. j av a2 s. c o m*/ msg = R.string.shop_activity_paymentsuccess; Bundle extras = new Bundle(); extras.putBoolean(Constants.PARAM_GETRESTRICTIONS, true); ContentResolver.requestSync(account, Constants.CONTACT_AUTHORITY, extras); activityClass = ViewAccountsActivity.class; break; case INVALID_PRICE: removePayment = true; msg = R.string.shop_activity_invalidprice; break; case INVALID_SYNTAX: removePayment = true; msg = R.string.shop_activity_invalidsyntax; break; case CANCELED: removePayment = true; msg = R.string.shop_activity_paymentcanceled; break; case NOT_APPROVED: case SALE_NOT_COMPLETED: case VERIFIER_ERROR: case NETWORK_ERROR: case AUTHENTICATION_FAILED: // Don't show message -> try again later break; case ALREADY_PROCESSED: removePayment = true; break; case UNKNOWN_PAYMENT: removePayment = true; msg = R.string.shop_activity_verificationfailed; break; default: removePayment = true; LogHelper.logE(TAG, "Unknown PaymentVerificationResult:" + result, null); // Unknown State msg = R.string.shop_activity_verificationfailed; break; } if (removePayment) { SyncUtils.savePayment(account, acm, null, null); } if (msg > 0) { sendNotification(context, account, msg, activityClass, true); } }