0

我正在使用一个AbstractThreadedSyncAdapter与我的服务器同步一些数据。我SyncResult用来指示执行同步时是否出现错误:

syncResult.stats.numParseExceptions++;

我像这样初始化 SyncAdapter:

Bundle params = new Bundle();
params.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false);
params.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
ContentResolver.addPeriodicSync(account, CONTENT, params, 3600);
ContentResolver.setSyncAutomatically(account, CONTENT, true);
ContentResolver.requestSync(account, CONTENT, new Bundle());

如果同步失败,我希望它在 5 分钟后重试(定期同步时间为 1 小时)。我以为我必须使用syncResult.delayUntil,但没有重试同步。

我该怎么做?

4

1 回答 1

0

Documentation say's: (http://developer.android.com/reference/android/content/ContentResolver.html#addPeriodicSync(android.accounts.Account, java.lang.String, android.os.Bundle, long))

Periodic syncs are not allowed to have any of SYNC_EXTRAS_DO_NOT_RETRY, SYNC_EXTRAS_IGNORE_BACKOFF, SYNC_EXTRAS_IGNORE_SETTINGS, SYNC_EXTRAS_INITIALIZE, SYNC_EXTRAS_FORCE, SYNC_EXTRAS_EXPEDITED, SYNC_EXTRAS_MANUAL set to true. If any are supplied then an IllegalArgumentException will be thrown.

Maybe that's the problem. Try remove this params - may work. Write if it helps.

Or You forgot permissions:

<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
于 2013-04-30T07:52:18.210 回答