Example usage for android.content Intent ACTION_SYNC

List of usage examples for android.content Intent ACTION_SYNC

Introduction

In this page you can find the example usage for android.content Intent ACTION_SYNC.

Prototype

String ACTION_SYNC

To view the source code for android.content Intent ACTION_SYNC.

Click Source Link

Document

Activity Action: Perform a data synchronization.

Usage

From source file:net.peterkuterna.android.apps.devoxxsched.service.CfpSyncService.java

@Override
protected void doSync(Intent intent) throws Exception {
    Log.d(TAG, "Start sync");

    Thread.sleep(5000);//from  w w w  . j a v  a  2 s .c  om

    final Context context = this;

    final SharedPreferences settings = Prefs.get(context);
    final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE);

    final long startLocal = System.currentTimeMillis();
    final boolean localParse = localVersion < VERSION_CURRENT;
    Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT);
    if (localParse) {
        // Parse values from local cache first
        mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler());
        mLocalExecutor.execute(R.xml.rooms, new RoomsHandler());
        mLocalExecutor.execute(R.xml.tracks, new TracksHandler());
        mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler());
        mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler());
        mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler());
        mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler());

        mLocalExecutor.execute(context, "cache-parleys-presentations.json", new ParleysPresentationsHandler());

        // Save local parsed version
        settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit();

        final ContentValues values = new ContentValues();
        values.put(Sessions.SESSION_NEW, 0);
        getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null);
    }
    Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms");

    final CfpSyncManager syncManager = new CfpSyncManager(context);
    if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) {
        Log.d(TAG, "Should perform remote sync");
        final long startRemote = System.currentTimeMillis();

        Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient);
        if (prefsEditor != null) {
            Log.d(TAG, "Remote content was changed");
            mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler());
            mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler());
            mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler());
            prefsEditor.commit();
        }
        Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms");
    } else {
        Log.d(TAG, "Should not perform remote sync");
    }

    final CfpDatabase database = new CfpDatabase(this);
    database.cleanupLinkTables();

    final NotifierManager notifierManager = new NotifierManager(this);
    notifierManager.notifyNewSessions();

    Log.d(TAG, "Sync finished");
}

From source file:org.wheelmap.android.fragment.POIsListWorkerFragment.java

protected void requestData() {
    final Intent intent = new Intent(Intent.ACTION_SYNC, null, getActivity(), SyncService.class);
    intent.putExtra(SyncService.EXTRA_WHAT, SyncService.WHAT_RETRIEVE_NODES);
    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mReceiver);
    intent.putExtra(SyncService.EXTRA_LOCATION, mLocation);
    intent.putExtra(SyncService.EXTRA_DISTANCE_LIMIT, mDistance);
    getActivity().startService(intent);/*from  ww  w.  j av a 2  s  .  co m*/
}

From source file:org.xbmc.android.app.ui.HomeActivity.java

@Override
public void onRefreshStarted(View view) {

    final long start = System.currentTimeMillis();
    startService(new Intent(Intent.ACTION_SYNC, null, this, SyncService.class)
            .putExtra(SyncService.EXTRA_SYNC_MOVIES, true).putExtra(SyncService.EXTRA_SYNC_MUSIC, true));
    Log.d(TAG, "Triggered refresh in " + (System.currentTimeMillis() - start) + "ms.");
}

From source file:com.heneryh.aquanotes.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")");

    /**//from w w w.j  a v  a2s . c  o m
     * Using the intent, we can tell why we are running this service
     */
    Cursor cursor = null;

    // This came from the timer expiring or from the gui, either way, push all controllers onto the queue.
    if (ACTION_UPDATE_ALL.equals(intent.getAction()) || Intent.ACTION_SYNC.equals(intent.getAction())) {
        try {
            Uri controllersQueryUri = Controllers.buildQueryControllersUri();
            cursor = dbResolverSyncSrvc.query(controllersQueryUri, ControllersQuery.PROJECTION, null, null,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                while (!cursor.isAfterLast()) {
                    Integer controllerId = cursor.getInt(ControllersQuery._ID);
                    requestUpdate(controllerId);
                    cursor.moveToNext();
                }
            }
        } catch (SQLException e) {
            Log.e(TAG, "getting controller list", e);
            // need a little more here!
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    } else if (ACTION_UPDATE_SINGLE.equals(intent.getAction())) { // This came from the a widget update, id is in the queue

    }

    /**
     *  Only start processing thread if not already running, if the thread was running it would
     *  grab the queue items
     */
    synchronized (sLock) {
        if (!sThreadRunning) {
            sThreadRunning = true;
            new SyncThread().execute();
        }
    }
}

From source file:edu.mit.mobile.android.livingpostcards.CardViewActivity.java

@Override
protected void onStart() {
    super.onStart();
    startService(new Intent(Intent.ACTION_SYNC, mCard));
}

From source file:org.wheelmap.android.fragment.POIsListWorkerFragment.java

public void executeSearch(Bundle extras) {
    if (!extras.containsKey(SearchManager.QUERY) && !extras.containsKey(SyncService.EXTRA_CATEGORY)
            && !extras.containsKey(SyncService.EXTRA_NODETYPE)
            && !extras.containsKey(SyncService.EXTRA_WHEELCHAIR_STATE))
        return;//www. j  ava 2s .  com

    final Intent intent = new Intent(Intent.ACTION_SYNC, null, getActivity(), SyncService.class);
    intent.putExtras(extras);
    if (!extras.containsKey(SyncService.EXTRA_WHAT)) {
        int what;
        if (extras.containsKey(SyncService.EXTRA_CATEGORY) || extras.containsKey(SyncService.EXTRA_NODETYPE))
            what = SyncService.WHAT_RETRIEVE_NODES;
        else
            what = SyncService.WHAT_SEARCH_NODES;

        intent.putExtra(SyncService.EXTRA_WHAT, what);
    }

    if (extras.containsKey(SyncService.EXTRA_DISTANCE_LIMIT))
        intent.putExtra(SyncService.EXTRA_LOCATION, mLocation);

    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mReceiver);
    getActivity().startService(intent);
}

From source file:edu.mit.mobile.android.locast.data.Sync.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
        if (Intent.ACTION_SYNC.equals(intent.getAction())) {
            if (intent.getBooleanExtra(EXTRA_EXPLICIT_SYNC, false)) {
                mNotifiedUserAboutNetworkStatus = true;
                mShouldAlertUserOnSuccess = true;
            }//from www .  j  a va  2 s  .  c  o  m
            startSync(intent.getData(), intent.getExtras());
        } else if (ACTION_CANCEL_SYNC.equals(intent.getAction())) {
            stopSync();
        }
    } else {
        // restarted by system.
        startSync();
    }

    return START_NOT_STICKY;
}

From source file:net.peterkuterna.android.apps.devoxxsched.ui.HomeActivity.java

private void triggerRefresh() {
    final Intent cfpIntent = new Intent(Intent.ACTION_SYNC, null, this, CfpSyncService.class);
    cfpIntent.putExtra(AbstractSyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiver);
    startService(cfpIntent);/*from w  ww .ja  v  a  2 s.  c o  m*/

    final Intent newsIntent = new Intent(Intent.ACTION_SYNC, null, this, NewsSyncService.class);
    startService(newsIntent);

    final Intent appEngineIntent = new Intent(Intent.ACTION_SYNC, null, this, AppEngineSyncService.class);
    startService(appEngineIntent);
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.HomeActivity.java

private void triggerRefresh() {
    final Intent cfpIntent = new Intent(Intent.ACTION_SYNC, null, this, CfpSyncService.class);
    cfpIntent.putExtra(AbstractSyncService.EXTRA_STATUS_RECEIVER, mSyncStatusUpdaterFragment.mReceiver);
    startService(cfpIntent);/*from w w  w .j  a  v  a  2s.c  o  m*/

    final Intent newsIntent = new Intent(Intent.ACTION_SYNC, null, this, NewsSyncService.class);
    newsIntent.putExtra(NewsSyncService.EXTRA_NO_NOTIFICATIONS, true);
    startService(newsIntent);
}

From source file:liqui.droid.activity.Base.java

private void triggerRefresh() {
    final Intent intent = new Intent(Intent.ACTION_SYNC, null, this, SyncService.class);
    intent.putExtra(SyncService.EXTRA_STATUS_RECEIVER, mReceiver);

    Bundle extras = new Bundle();
    extras.putString(Constants.Account.API_NAME, getAPIName());
    extras.putString(Constants.Account.API_URL, getAPIUrl());
    extras.putString(Constants.Account.MEMBER_ID, getMemberId());
    extras.putString(Constants.Account.SESSION_KEY, getSessionKey());
    intent.putExtras(extras);/* w  w w  .j  ava  2 s. c om*/

    startService(intent);
}