Class SensorSessionOptions

java.lang.Object
com.codename1.health.sensors.SensorSessionOptions

public final class SensorSessionOptions extends Object
How a SensorSession should behave: reconnection, where samples go, and how stale a cached reading may be.
  • Constructor Details

    • SensorSessionOptions

      public SensorSessionOptions()
  • Method Details

    • setAutoReconnect

      public SensorSessionOptions setAutoReconnect(boolean autoReconnect)
    • isAutoReconnect

      public boolean isAutoReconnect()
      true when the session reconnects automatically.
    • setWriteToStore

      public SensorSessionOptions setWriteToStore(boolean writeToStore)

      Whether received samples are written through to the platform health store. Defaults to false, and that default is deliberate.

      During a workout on watchOS -- and on iOS 26 and later -- the operating system records heart rate into HealthKit itself. A strap that also writes its own heart-rate samples then produces two overlapping sets for the same minutes, and every downstream average, maximum and chart is computed over double-counted data.

      This release drives no live workout session, so that overlap comes from a workout the user started elsewhere -- in Apple's own Workout app, say -- rather than from one of yours. The default stays false regardless: turning it on is a decision about somebody else's data as much as your own.

      If you are recording a workout, attach the session to it with setWorkoutSession(WorkoutSession) instead: samples land in the workout's statistics and are persisted once, as part of the workout, when it ends.

      Turning this on is right when you are logging a standalone measurement the OS knows nothing about -- a weight from a scale, a body temperature from a thermometer, a glucose reading from a meter.

      Blood pressure is not among them on mobile in this release. It is two values in one reading, which HealthKit models as a correlation and Health Connect as its own record type, and neither is implemented here -- the sample line this API writes over carries a single value. A cuff reading routed to the store therefore fails with

      invalid reference
      HealthError#TYPE_NOT_SUPPORTED
      on both platforms rather than

      being quietly dropped, and the local and simulator stores keep it fine. Read it off the session and persist it yourself until the correlation paths land.

    • isWriteToStore

      public boolean isWriteToStore()
      true when samples are written through to the health store.
    • setStoreBatch

      public SensorSessionOptions setStoreBatch(Duration value)

      How long samples are batched before a store write.

      The

      invalid reference
      Duration
      form of setStoreBatchMillis(int), which is the type the rest of

      the framework speaks; the millis form stays for the ports and the wire format.

    • getStoreBatch

      public Duration getStoreBatch()

      How long samples are batched before a store write, as a

      invalid reference
      Duration
      .
    • setStoreBatchMillis

      public SensorSessionOptions setStoreBatchMillis(int storeBatchMillis)
    • getStoreBatchMillis

      public int getStoreBatchMillis()
      The store write-batch interval in milliseconds.
    • setWorkoutSession

      public SensorSessionOptions setWorkoutSession(WorkoutSession workoutSession)

      Attaches this sensor to a workout, so its samples become part of that workout's statistics and are persisted with it.

      This is the right way to feed a heart-rate strap into a recorded workout -- see the warning on setWriteToStore(boolean).

    • getWorkoutSession

      public WorkoutSession getWorkoutSession()
      The attached workout, or null.
    • setStaleSample

      public SensorSessionOptions setStaleSample(Duration value)

      How old a sample may be before it is dropped.

      The

      invalid reference
      Duration
      form of setStaleSampleMillis(int), which is the type the rest of

      the framework speaks; the millis form stays for the ports and the wire format.

    • getStaleSample

      public Duration getStaleSample()

      How old a sample may be before it is dropped, as a

      invalid reference
      Duration
      .
    • setStaleSampleMillis

      public SensorSessionOptions setStaleSampleMillis(int staleSampleMillis)
    • getStaleSampleMillis

      public int getStaleSampleMillis()
      The staleness threshold in milliseconds.