Most visited

Recently visited

Added in API level 19

SyncRequest.Builder

public static class SyncRequest.Builder
extends Object

java.lang.Object
   ↳ android.content.SyncRequest.Builder


@link SyncRequest的生成器类。 在构建SyncRequest时,此类还将执行验证。

Summary

Public constructors

SyncRequest.Builder()

Public methods

SyncRequest build()

如果验证失败,则执行对请求的验证并引发运行时异常 IllegalArgumentException

SyncRequest.Builder setDisallowMetered(boolean disallow)

如果被调用并且 setIgnoreSettings(boolean)已被调用,将抛出 IllegalArgumentException

SyncRequest.Builder setExpedited(boolean expedited)

加速同步立即运行,并可以抢占其他非加速运行同步。

SyncRequest.Builder setExtras(Bundle bundle)

实际发生同步时,开发人员提供的附加功能会返回。

SyncRequest.Builder setIgnoreBackoff(boolean ignoreBackoff)

方便功能设置 SYNC_EXTRAS_IGNORE_BACKOFF

SyncRequest.Builder setIgnoreSettings(boolean ignoreSettings)

方便功能设置 SYNC_EXTRAS_IGNORE_SETTINGS

SyncRequest.Builder setManual(boolean isManual)

方便功能设置 SYNC_EXTRAS_MANUAL

SyncRequest.Builder setNoRetry(boolean noRetry)

方便功能设置 SYNC_EXTRAS_DO_NOT_RETRY

SyncRequest.Builder setRequiresCharging(boolean requiresCharging)

指定同步是否需要插入电话。

SyncRequest.Builder setSyncAdapter(Account account, String authority)

为此传输指定一个权限和帐户。

SyncRequest.Builder syncOnce()

请求立即发生同步。

SyncRequest.Builder syncPeriodic(long pollFrequency, long beforeSeconds)

建立一个定期同步。

Inherited methods

From class java.lang.Object

Public constructors

SyncRequest.Builder

Added in API level 19
SyncRequest.Builder ()

Public methods

build

Added in API level 19
SyncRequest build ()

如果此验证失败,则执行对请求的验证并引发运行时异常 IllegalArgumentException

Returns
SyncRequest a SyncRequest with the information contained within this builder.

setDisallowMetered

Added in API level 19
SyncRequest.Builder setDisallowMetered (boolean disallow)

如果被调用并且 setIgnoreSettings(boolean)已经被调用,将抛出 IllegalArgumentException

Parameters
disallow boolean: true to allow this transfer on metered networks. Default false.
Returns
SyncRequest.Builder

setExpedited

Added in API level 19
SyncRequest.Builder setExpedited (boolean expedited)

加速同步立即运行,并可以抢占其他非加速运行同步。 对于周期性同步无效, IllegalArgumentExceptionbuild()抛出build()

Parameters
expedited boolean: whether to run expedited. Default false.
Returns
SyncRequest.Builder

setExtras

Added in API level 19
SyncRequest.Builder setExtras (Bundle bundle)

实际发生同步时,开发人员提供的附加功能会返回。 该捆绑包被复制到由build()返回的build() 例:

   String[] syncItems = {"dog", "cat", "frog", "child"};
   SyncRequest.Builder builder =
     new SyncRequest.Builder()
       .setSyncAdapter(dummyAccount, dummyProvider)
       .syncOnce();

   for (String syncData : syncItems) {
     Bundle extras = new Bundle();
     extras.setString("data", syncData);
     builder.setExtras(extras);
     ContentResolver.sync(builder.build()); // Each sync() request creates a unique sync.
   }
 
Only values of the following types may be used in the extras bundle:
  • Integer
  • Long
  • Boolean
  • Float
  • Double
  • String
  • Account
  • null
If any data is present in the bundle not of this type, build() will throw a runtime exception.

Parameters
bundle Bundle: extras bundle to set.
Returns
SyncRequest.Builder

setIgnoreBackoff

Added in API level 19
SyncRequest.Builder setIgnoreBackoff (boolean ignoreBackoff)

方便功能设置SYNC_EXTRAS_IGNORE_BACKOFF 忽略退避将强制同步调度进程忽略任何由同步失败导致的delayUntil ,以及使可能由适配器设置的任何delayUntil值无效。 连续的失败不会兑现这个标志。 对于周期性同步无效, IllegalArgumentExceptionbuild()抛出build()

Parameters
ignoreBackoff boolean: ignore back off settings. Default false.
Returns
SyncRequest.Builder

setIgnoreSettings

Added in API level 19
SyncRequest.Builder setIgnoreSettings (boolean ignoreSettings)

方便功能设置SYNC_EXTRAS_IGNORE_SETTINGS 不适用于定期同步,将抛出IllegalArgumentExceptionbuild()

如果调用, setDisallowMetered(boolean)抛出 IllegalArgumentException ,并且 setDisallowMetered(boolean)已被设置。

Parameters
ignoreSettings boolean: true to ignore the sync automatically settings. Default false.
Returns
SyncRequest.Builder

setManual

Added in API level 19
SyncRequest.Builder setManual (boolean isManual)

方便功能设置SYNC_EXTRAS_MANUAL 对于周期性同步无效, IllegalArgumentExceptionbuild()抛出build()

Parameters
isManual boolean: User-initiated sync or not. Default false.
Returns
SyncRequest.Builder

setNoRetry

Added in API level 19
SyncRequest.Builder setNoRetry (boolean noRetry)

方便功能设置SYNC_EXTRAS_DO_NOT_RETRY 除非设置为false,否则失败的一次性同步操作将以指数回退重试。 对于定期同步无效,并会在build()中引发IllegalArgumentException

Parameters
noRetry boolean: true to not retry a failed sync. Default false.
Returns
SyncRequest.Builder

setRequiresCharging

Added in API level 24
SyncRequest.Builder setRequiresCharging (boolean requiresCharging)

指定同步是否需要插入电话。

Parameters
requiresCharging boolean: true if sync requires the phone to be plugged in. Default false.
Returns
SyncRequest.Builder

setSyncAdapter

Added in API level 19
SyncRequest.Builder setSyncAdapter (Account account, 
                String authority)

为此传输指定一个权限和帐户。

Parameters
account Account: Account to sync. Can be null unless this is a periodic sync, for which verification by the ContentResolver will fail. If a sync is performed without an account, the
authority String: A String identifying the content provider to be synced.
Returns
SyncRequest.Builder

syncOnce

Added in API level 19
SyncRequest.Builder syncOnce ()

请求立即发生同步。

     SyncRequest.Builder builder = (new SyncRequest.Builder()).syncOnce();
 

Returns
SyncRequest.Builder

syncPeriodic

Added in API level 19
SyncRequest.Builder syncPeriodic (long pollFrequency, 
                long beforeSeconds)

建立一个定期同步。 必须为此构建器调用this或syncOnce()。 同步由目标android.provider和附加软件包的内容标识。 在指定周期性同步后(通过调用此函数),您不能重复使用同一个构建器进行一次性同步。 如果你这样做, IllegalArgumentException将被抛出。

用于定期同步的软件包可以使用getPeriodicSyncs(Account, String)由具有正确权限的应用程序查询,因此不应在此传输敏感数据。 用法示例。

     Request a periodic sync every 5 hours with 20 minutes of flex.
     SyncRequest.Builder builder =
         (new SyncRequest.Builder()).syncPeriodic(5 * HOUR_IN_SECS, 20 * MIN_IN_SECS);

     Schedule a periodic sync every hour at any point in time during that hour.
     SyncRequest.Builder builder =
         (new SyncRequest.Builder()).syncPeriodic(1 * HOUR_IN_SECS, 1 * HOUR_IN_SECS);
 
N.B.: 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.

Parameters
pollFrequency long: the amount of time in seconds that you wish to elapse between periodic syncs. A minimum period of 1 hour is enforced.
beforeSeconds long: the amount of flex time in seconds before pollFrequency that you permit for the sync to take place. Must be less than pollFrequency and greater than MAX(5% of pollFrequency, 5 minutes)
Returns
SyncRequest.Builder

Hooray!