Class SubscriptionRequest
Describes a standing subscription to changes in the health store.
The id must never change
The identifier keys the persisted cursor that says how far the app has
already read. Reuse it across launches and app updates and you resume
exactly where you left off; change it -- even to fix a typo -- and the
framework treats it as a brand-new subscription and resynchronizes from
scratch. Hard-code it as a constant, and version it deliberately
("steps-v1") if you ever need a clean start.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default cap on how many samples one change batch carries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddType(HealthDataType type) Adds a type to watch.getId()The stable identifier for this subscription.intThe per-batch sample cap.intThe requested minimum delivery interval in seconds, 0 for none.getTypes()The types being watched.booleantruewhen batches carry samples.booleantruewhen deletions are reported.setDeliverSamples(boolean deliverSamples) Whether batches carry the changed samples themselves.setIncludeDeletions(boolean includeDeletions) Whether deletions are reported alongside additions.setMaxSamplesPerBatch(int maxSamplesPerBatch) Caps how many samples one batch carries.setMinIntervalSeconds(int minIntervalSeconds) Asks the platform not to deliver more often than this.voidvalidate()Validates the request.
-
Field Details
-
DEFAULT_MAX_SAMPLES_PER_BATCH
public static final int DEFAULT_MAX_SAMPLES_PER_BATCHThe default cap on how many samples one change batch carries.- See Also:
-
-
Constructor Details
-
SubscriptionRequest
Creates a request under a stable identifier.
Throws
IllegalArgumentException: ifidis null or blank.
-
-
Method Details
-
getId
The stable identifier for this subscription. -
addType
Adds a type to watch. At least one is required. -
getTypes
The types being watched. -
setIncludeDeletions
Whether deletions are reported alongside additions. Defaults totrue; turn it off only if your app genuinely never needs to un-count something a user removed. -
isIncludeDeletions
public boolean isIncludeDeletions()truewhen deletions are reported. -
setDeliverSamples
Whether batches carry the changed samples themselves. Defaults totrue. Setfalsefor a notify-only subscription -- cheaper when all you want is a signal to refresh a screen. -
isDeliverSamples
public boolean isDeliverSamples()truewhen batches carry samples. -
setMinIntervalSeconds
Asks the platform not to deliver more often than this. A hint only: iOS honours a coarse frequency per type and Android polls whenever the app asks it to, so neither treats this as a guarantee. -
getMinIntervalSeconds
public int getMinIntervalSeconds()The requested minimum delivery interval in seconds, 0 for none. -
setMaxSamplesPerBatch
Caps how many samples one batch carries. Batches beyond the cap are reported through
HealthChangeBatch.hasMore().The default exists because a background delivery has only a few seconds of wall clock before the OS suspends the process; handing the listener fifty thousand samples guarantees it does not finish.
-
getMaxSamplesPerBatch
public int getMaxSamplesPerBatch()The per-batch sample cap. -
validate
Validates the request.
Throws
HealthException:HealthError.INVALID_ARGUMENTwhen no type is named or the batch cap is not positive.
- Throws:
HealthException
-