Example usage for android.content SyncResult hasError

List of usage examples for android.content SyncResult hasError

Introduction

In this page you can find the example usage for android.content SyncResult hasError.

Prototype

public boolean hasError() 

Source Link

Document

A convenience method for determining of the SyncResult indicates that an error occurred.

Usage

From source file:com.nextgis.mobile.datasource.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle bundle, String authority,
        ContentProviderClient contentProviderClient, SyncResult syncResult) {
    sendNotification(getContext(), SYNC_START, null);

    super.onPerformSync(account, bundle, authority, contentProviderClient, syncResult);

    if (isCanceled())
        sendNotification(getContext(), SYNC_CANCELED, null);
    else if (syncResult.hasError())
        sendNotification(getContext(), SYNC_CHANGES, mError);
    else/*w w  w  . ja v a 2  s  .  co m*/
        sendNotification(getContext(), SYNC_FINISH, null);
}

From source file:com.nextgis.ngm_clink_monitoring.adapters.FoclSyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle bundle, String authority,
        ContentProviderClient contentProviderClient, SyncResult syncResult) {
    // For service debug
    //        android.os.Debug.waitForDebugger();

    int syncStatus = FoclSyncAdapter.IS_OK;

    GISApplication app = (GISApplication) getContext().getApplicationContext();

    LogcatWriter logcatWriter = new LogcatWriter(app);
    try {/*from   w ww  .ja v  a2s . c  o  m*/
        logcatWriter.startLogcat();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        app.sendReportsOnServer(false, false);
    } catch (IOException e) {
        e.printStackTrace();
    }

    sendNotification(app, FoclSyncAdapter.IS_STARTED, null);
    app.setFullSync(bundle.getBoolean(FoclConstants.KEY_IS_FULL_SYNC, false));

    super.onPerformSync(account, bundle, authority, contentProviderClient, syncResult);

    if (isCanceled()) {
        syncStatus = FoclSyncAdapter.IS_CANCELED;
        sendNotification(app, FoclSyncAdapter.IS_CANCELED, app.getString(R.string.sync_canceled));
        Log.d(Constants.TAG, "FoclSyncAdapter - notification IS_CANCELED is sent");
    }

    if (syncResult.hasError() || null != mError && mError.length() > 0) {
        syncStatus = FoclSyncAdapter.IS_ERROR;
        sendNotification(app, FoclSyncAdapter.IS_ERROR, mError);
    }

    if (FoclSyncAdapter.IS_OK == syncStatus) {
        sendNotification(app, FoclSyncAdapter.IS_FINISHED, null);
    }

    try {
        String logcatFilePath;

        switch (syncStatus) {
        case FoclSyncAdapter.IS_OK:
            logcatFilePath = app.getSyncLogcatFilePath();
            break;
        case FoclSyncAdapter.IS_ERROR:
        case FoclSyncAdapter.IS_CANCELED:
        default:
            logcatFilePath = app.getSyncErrorLogcatFilePath();
            break;
        }

        logcatWriter.writeLogcat(logcatFilePath);
        logcatWriter.stopLogcat();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        app.sendReportsOnServer(false, false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:me.philio.ghost.sync.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider,
        SyncResult syncResult) {
    Log.d(TAG, "Sync started for " + account.name);

    Intent intent = new Intent(SyncConstants.ACTION_SYNC_STARTED);
    intent.putExtra(SyncConstants.EXTRA_ACCOUNT, account);
    getContext().sendBroadcast(intent);/*from w  ww.j a va2s  .  c o m*/

    try {
        // Refresh the access token
        refreshAccessToken(account);

        // Sync remote changes
        syncRemote(account, syncResult);
    } catch (AuthenticatorException | OperationCanceledException | IOException | RetrofitError
            | NoSuchAlgorithmException e) {
        Log.e(TAG, "Sync error: " + e.getMessage());
        syncResult.stats.numIoExceptions++;
    }

    Log.d(TAG, "Sync finished for " + account.name);
    Log.d(TAG, "Inserts: " + syncResult.stats.numInserts);
    Log.d(TAG, "Updates: " + syncResult.stats.numUpdates);
    Log.d(TAG, "Deletes: " + syncResult.stats.numDeletes);
    Log.d(TAG, "Errors: " + syncResult.hasError());

    intent.setAction(SyncConstants.ACTION_SYNC_FINISHED);
    intent.putExtra(SyncConstants.EXTRA_RESULT, syncResult);
    getContext().sendBroadcast(intent);
}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

@Override
public void getServerDiffs(SyncContext context, SyncData baseSyncData, SyncableContentProvider tempProvider,
        Bundle extras, Object syncInfo, SyncResult syncResult) {
    mPerformedGetServerDiffs = true;/*from   w w w .  ja  v a  2s  .c  o  m*/
    GDataSyncData syncData = (GDataSyncData) baseSyncData;

    ArrayList<String> feedsToSync = new ArrayList<String>();

    if (extras != null && extras.containsKey("feed")) {
        feedsToSync.add((String) extras.get("feed"));
    } else {
        feedsToSync.add(getGroupsFeedForAccount(getAccount()));
        addContactsFeedsToSync(getContext().getContentResolver(), getAccount(), feedsToSync);
        feedsToSync.add(getPhotosFeedForAccount(getAccount()));
    }

    for (String feed : feedsToSync) {
        context.setStatusText("Downloading\u2026");
        if (getPhotosFeedForAccount(getAccount()).equals(feed)) {
            getServerPhotos(context, feed, MAX_MEDIA_ENTRIES_PER_SYNC, syncData, syncResult);
        } else {
            final Class feedEntryClass = getFeedEntryClass(feed);
            if (feedEntryClass != null) {
                getServerDiffsImpl(context, tempProvider, feedEntryClass, feed, null, getMaxEntriesPerSync(),
                        syncData, syncResult);
            } else {
                if (Config.LOGD) {
                    Log.d(TAG, "ignoring sync request for unknown feed " + feed);
                }
            }
        }
        if (syncResult.hasError()) {
            break;
        }
    }
}