From 218ea143c4a206d313c8e605b8e119bf097ebb69 Mon Sep 17 00:00:00 2001 From: Mo'men amin Date: Tue, 15 Jul 2025 00:03:24 +0200 Subject: [PATCH] Update HealthPlugin.kt --- .../kotlin/cachet/plugins/health/HealthPlugin.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt index b51e83afa..a99d69ea0 100644 --- a/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt +++ b/packages/health/android/src/main/kotlin/cachet/plugins/health/HealthPlugin.kt @@ -2504,8 +2504,20 @@ class HealthPlugin(private var channel: MethodChannel? = null) : } private fun stopStepSensorBackgroundService(call: MethodCall, result: Result) { - val serviceIntent = Intent(activity!!, StepCounterService::class.java) - activity!!.stopService(serviceIntent) + try { + if (activity == null || context == null) { + result.success(false) + return + } + val serviceIntent = Intent(activity!!, StepCounterService::class.java) + val stopped = activity!!.stopService(serviceIntent) + + result.success(stopped) + } catch (e: Exception) { + Log.e("FLUTTER_HEALTH::ERROR", "Failed to stop step sensor service: ${e.message}") + Log.e("FLUTTER_HEALTH::ERROR", e.stackTrace.toString()) + result.success(false) + } } private fun startStepSensorBackgroundService(call: MethodCall, result: Result) {