Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,8 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
endTime.toEpochMilli()
)
).build().find()


healthConnectData.addAll(items.map {
mapOf<String, Any>(
"value" to
Expand Down Expand Up @@ -2576,6 +2578,7 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
"requestAuthorization" -> requestAuthorization(call, result)
"revokePermissions" -> revokePermissions(call, result)
"requestBackgroundFetchIfAvailable" -> requestBackgroundFetchIfAvailable(call, result)
"backgroundFetchPermissionGranted" -> backgroundFetchPermissionGranted(call, result)
"getData" -> getData(call, result)
"getIntervalData" -> getIntervalData(call, result)
"writeData" -> writeData(call, result)
Expand Down Expand Up @@ -2614,6 +2617,27 @@ class HealthPlugin(private var channel: MethodChannel? = null) :
result.success(false)
}

@OptIn(ExperimentalFeatureAvailabilityApi::class)
private fun backgroundFetchPermissionGranted(call: MethodCall, result: Result) {
if (healthConnectClient
.features
.getFeatureStatus(
HealthConnectFeatures.FEATURE_READ_HEALTH_DATA_IN_BACKGROUND
) == HealthConnectFeatures.FEATURE_STATUS_AVAILABLE
) {

scope.launch {
val grantedPermissions =
healthConnectClient.permissionController.getGrantedPermissions()

result.success(PERMISSION_READ_HEALTH_DATA_IN_BACKGROUND in grantedPermissions)
}
return
}

result.success(false)
}


private fun isForegroundServiceRunning(context: Context, serviceClass: Class<*>): Boolean {
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
Expand Down
4 changes: 4 additions & 0 deletions packages/health/lib/src/health_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class Health {
}
}

Future<bool?> backgroundFetchPermissionGranted() async {
return await _channel.invokeMethod('backgroundFetchPermissionGranted');
}

/// Disconnect from Google fit.
///
/// Not supported on iOS and Google Health Connect, and the method does nothing.
Expand Down
Loading