Android 14 HealthConnectException: Conflict found, but couldn't read the entry

44 Views Asked by At

I am testing the health connect integration of my app on Android 14.

When I try to insert a weight, hydration or nutrition record I get the following errors:

Caused by: android.health.connect.HealthConnectException: android.health.connect.HealthConnectException: Conflict found, but couldn't read the entry.
    at android.health.connect.aidl.HealthConnectExceptionParcel$1.createFromParcel(HealthConnectExceptionParcel.java:33)
    at android.health.connect.aidl.HealthConnectExceptionParcel$1.createFromParcel(HealthConnectExceptionParcel.java:29)
    at android.os.Parcel.readTypedObject(Parcel.java:4055)
    at android.health.connect.aidl.IInsertRecordsResponseCallback$Stub.onTransact(IInsertRecordsResponseCallback.java:106)
    at android.os.Binder.execTransactInternal(Binder.java:1392)
    at android.os.Binder.execTransact(Binder.java:1299)

This same code runs fine on Android 13 where the HealthConnect app is installed as a separate application and is not part of the OS.

Any help how to figure out whats the problem here would be appreciated.

EIDT: minimal reproducible example

val time = ZonedDateTime.parse("2024-03-16T00:00:00+02:00[Europe/Sofia]")

val r = WeightRecord(
    time = time.toInstant(),
    zoneOffset = time.offset,
    weight = 60.kilograms,
    metadata = Metadata(
        clientRecordId = "weight_dummy_id", clientRecordVersion = 0
    )
)

healthConnectClient.insertRecords(listOf(r)) // this throws the error

Before executing the code above I made sure that the following conditions are true: healthConnectClient.getSdkStatus(context) == HealthConnectClient.SDK_AVAILABLE healthConnectClient.permissionController.getGrantedPermissions().contains("android.permission.health.WRITE_WEIGHT")

I am using: androidx.health.connect:connect-client:1.1.0-alpha07

In AndroidManifest.xml I have:

<manifest>
    ...
    <queries>
        <package android:name="com.google.android.apps.healthdata" />

        <intent>
            <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
        </intent>
    </queries>
    ...
    <uses-permission android:name="android.permission.health.WRITE_HYDRATION" />
    ...
    <application>
        ...
        <activity android:enabled="true" android:exported="true"
            android:name=".ui.healthconnect.HealthConnectPermissionsRationaleActivity">

            <intent-filter>
                <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
                <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
            </intent-filter>
        </activity>
    </application>
</manifest>

EDIT 2: package name

I noticed that if I change the package name of the app I no longer observe this error and the record is successfully inserted in HealthConnect. My guess is that HC has some data cached for this particular package which is causing the issue.

0

There are 0 best solutions below