@@ -352,7 +352,56 @@ class HealthDataWriter(
352
352
}
353
353
}
354
354
355
- // ---------- Private Methods ----------
355
+ /* *
356
+ * Writes speed/velocity data with multiple samples to Health Connect.
357
+ * Creates a SpeedRecord containing time-series speed measurements captured during
358
+ * activities like running, cycling, or walking. Each sample represents the user's
359
+ * instantaneous speed at a specific moment within the recording period.
360
+ *
361
+ * @param call Method call containing startTime, endTime, recordingMethod,
362
+ * samples: List<Map<String, Any>> List of speed measurements, each
363
+ * containing: time, speed (m/s)
364
+ *
365
+ * @param result Flutter result callback returning boolean success status
366
+ */
367
+ fun writeMultipleSpeedData (call : MethodCall , result : Result ) {
368
+ val startTime = call.argument<Long >(" startTime" )!!
369
+ val endTime = call.argument<Long >(" endTime" )!!
370
+ val samples = call.argument<List <Map <String , Any >>>(" samples" )!!
371
+ val recordingMethod = call.argument<Int >(" recordingMethod" )!!
372
+
373
+ scope.launch {
374
+ try {
375
+ val speedSamples = samples.map { sample ->
376
+ SpeedRecord .Sample (
377
+ time = Instant .ofEpochMilli(sample[" time" ] as Long ),
378
+ speed = Velocity .metersPerSecond(sample[" speed" ] as Double )
379
+ )
380
+ }
381
+
382
+ val speedRecord = SpeedRecord (
383
+ startTime = Instant .ofEpochMilli(startTime),
384
+ endTime = Instant .ofEpochMilli(endTime),
385
+ samples = speedSamples,
386
+ startZoneOffset = null ,
387
+ endZoneOffset = null ,
388
+ metadata = Metadata (recordingMethod = recordingMethod),
389
+ )
390
+
391
+ healthConnectClient.insertRecords(listOf (speedRecord))
392
+ result.success(true )
393
+ Log .i(
394
+ " FLUTTER_HEALTH::SUCCESS" ,
395
+ " Successfully wrote ${speedSamples.size} speed samples"
396
+ )
397
+ } catch (e: Exception ) {
398
+ Log .e(" FLUTTER_HEALTH::ERROR" , " Error writing speed data: ${e.message} " )
399
+ result.success(false )
400
+ }
401
+ }
402
+ }
403
+
404
+ // ---------- Private Methods ----------
356
405
357
406
/* *
358
407
* Creates appropriate Health Connect record objects based on data type.
@@ -549,6 +598,20 @@ class HealthDataWriter(
549
598
zoneOffset = null ,
550
599
metadata = Metadata (recordingMethod = recordingMethod),
551
600
)
601
+
602
+ SPEED -> SpeedRecord (
603
+ startTime = Instant .ofEpochMilli(startTime),
604
+ endTime = Instant .ofEpochMilli(endTime),
605
+ samples = listOf (
606
+ SpeedRecord .Sample (
607
+ time = Instant .ofEpochMilli(startTime),
608
+ speed = Velocity .metersPerSecond(value),
609
+ )
610
+ ),
611
+ startZoneOffset = null ,
612
+ endZoneOffset = null ,
613
+ metadata = Metadata (recordingMethod = recordingMethod),
614
+ )
552
615
553
616
BLOOD_PRESSURE_SYSTOLIC -> {
554
617
Log .e(" FLUTTER_HEALTH::ERROR" , " You must use the [writeBloodPressure] API" )
@@ -630,6 +693,7 @@ class HealthDataWriter(
630
693
private const val BLOOD_PRESSURE_DIASTOLIC = " BLOOD_PRESSURE_DIASTOLIC"
631
694
private const val WORKOUT = " WORKOUT"
632
695
private const val NUTRITION = " NUTRITION"
696
+ private const val SPEED = " SPEED"
633
697
634
698
// Sleep types
635
699
private const val SLEEP_ASLEEP = " SLEEP_ASLEEP"
0 commit comments