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)
      Whether the session re-establishes a dropped link on its own. Defaults to true, which is almost always right -- chest straps drop out routinely as the wearer moves.
    • 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 is already recording heart rate into HealthKit itself. A strap that also writes its own heart-rate samples produces two overlapping sets for the same minutes, and every downstream average, maximum and chart is then computed over double-counted data.

      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 blood-pressure reading from a cuff.

    • isWriteToStore

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

      public SensorSessionOptions setStoreBatchMillis(int storeBatchMillis)
      How long samples are batched before being written to the store. Defaults to one minute. Writing every notification individually would mean a store round trip per second per sensor.
    • 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.
    • setStaleSampleMillis

      public SensorSessionOptions setStaleSampleMillis(int staleSampleMillis)

      How long a cached reading stays current, for SensorSession.getLatest(com.codename1.health.HealthDataType). Defaults to ten seconds.

      Past this age getLatest returns null rather than a stale value, so a UI bound to it shows a dash instead of silently displaying the heart rate from before the strap fell off.

    • getStaleSampleMillis

      public int getStaleSampleMillis()
      The staleness threshold in milliseconds.