Android framework version
net10.0-android
Affected platform version
Xamarin.AndroidX.Health.Connect.ConnectClient 1.1.0.2
Description
The generated .NET bindings for Xamarin.AndroidX.Health.Connect.ConnectClient appear to expose the Health Connect record base/interface incorrectly.
The official AndroidX Health Connect docs show androidx.health.connect.client.records.Record as the common interface shared by Health Connect records:
https://developer.android.com/reference/androidx/health/connect/client/records/Record
The package docs list concrete classes such as StepsRecord, SleepSessionRecord, DistanceRecord, TotalCaloriesBurnedRecord, RestingHeartRateRecord, and WeightRecord under the same androidx.health.connect.client.records package:
https://developer.android.com/reference/androidx/health/connect/client/records/package-summary
In the .NET binding, there is an AndroidX.Health.Connect.Client.Records.IRecord, but concrete record classes such as SleepSessionRecord, RestingHeartRateRecord, and WeightRecord are not assignable to it from C#.
This prevents writing shared helper code against the common record abstraction, e.g. for accessing common metadata/data-origin fields.
Example that does not compile:
using AndroidX.Health.Connect.Client.Records;
static string GetPackageName(IRecord record) =>
record.Metadata.DataOrigin.PackageName;
void Test(SleepSessionRecord record)
{
var packageName = GetPackageName(record);
}
Compiler error:
error CS1503: Argument 1: cannot convert from
'AndroidX.Health.Connect.Client.Records.SleepSessionRecord'
to 'AndroidX.Health.Connect.Client.Records.IRecord'
The same issue occurs with other Health Connect record types.
Expected behavior:
Concrete Health Connect record classes should be assignable to the generated common record interface/base type, matching the AndroidX API model documented by Google.
Actual behavior:
Concrete record types expose common properties such as Metadata, but cannot be passed as IRecord.
Steps to Reproduce
- Create a .NET Android project targeting
net10.0-android36.0.
- Add
Xamarin.AndroidX.Health.Connect.ConnectClient version 1.1.0.2.
- Add code like:
using AndroidX.Health.Connect.Client.Records;
static string GetPackageName(IRecord record) =>
record.Metadata.DataOrigin.PackageName;
void Test(SleepSessionRecord record)
{
var packageName = GetPackageName(record);
}
- Build.
Did you find any workaround?
Yes. Use explicit overloads for each concrete Health Connect record type:
static string GetPackageName(StepsRecord record) => record.Metadata.DataOrigin.PackageName;
static string GetPackageName(SleepSessionRecord record) => record.Metadata.DataOrigin.PackageName;
static string GetPackageName(DistanceRecord record) => record.Metadata.DataOrigin.PackageName;
static string GetPackageName(TotalCaloriesBurnedRecord record) => record.Metadata.DataOrigin.PackageName;
static string GetPackageName(RestingHeartRateRecord record) => record.Metadata.DataOrigin.PackageName;
static string GetPackageName(WeightRecord record) => record.Metadata.DataOrigin.PackageName;
This works, but it is a binding workaround and does not match the official AndroidX API shape.
Relevant log output
Android framework version
net10.0-android
Affected platform version
Xamarin.AndroidX.Health.Connect.ConnectClient 1.1.0.2
Description
The generated .NET bindings for
Xamarin.AndroidX.Health.Connect.ConnectClientappear to expose the Health Connect record base/interface incorrectly.The official AndroidX Health Connect docs show
androidx.health.connect.client.records.Recordas the common interface shared by Health Connect records:https://developer.android.com/reference/androidx/health/connect/client/records/Record
The package docs list concrete classes such as
StepsRecord,SleepSessionRecord,DistanceRecord,TotalCaloriesBurnedRecord,RestingHeartRateRecord, andWeightRecordunder the sameandroidx.health.connect.client.recordspackage:https://developer.android.com/reference/androidx/health/connect/client/records/package-summary
In the .NET binding, there is an
AndroidX.Health.Connect.Client.Records.IRecord, but concrete record classes such asSleepSessionRecord,RestingHeartRateRecord, andWeightRecordare not assignable to it from C#.This prevents writing shared helper code against the common record abstraction, e.g. for accessing common metadata/data-origin fields.
Example that does not compile:
Compiler error:
The same issue occurs with other Health Connect record types.
Expected behavior:
Concrete Health Connect record classes should be assignable to the generated common record interface/base type, matching the AndroidX API model documented by Google.
Actual behavior:
Concrete record types expose common properties such as
Metadata, but cannot be passed asIRecord.Steps to Reproduce
net10.0-android36.0.Xamarin.AndroidX.Health.Connect.ConnectClientversion1.1.0.2.Did you find any workaround?
Yes. Use explicit overloads for each concrete Health Connect record type:
This works, but it is a binding workaround and does not match the official AndroidX API shape.
Relevant log output