使用“Health Connect”API(android java应用程序)读取健康数据

问题描述 投票:0回答:1

我目前正在开发一个健康应用程序,我希望能够使用 Health Connect SDK 读取和显示健康数据信息(已通过手机/智能手表传感器存储)。 一些教程可用(https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-startedhttps://developer.android.com/codelabs/health-connect #0)但不幸的是它们是用 Kotlin 编写的,而我正在用 Java 语言编写我的应用程序。还有其他资源可以帮助我使用 Java 吗?

我正在努力解决 ReadRecordsRequest (https://developer.android.com/reference/androidx/health/connect/client/request/ReadRecordsRequest)和 ReadRecords(https://developer.android.com/reference/) androidx/health/connect/client/HealthConnectClient#readRecords(androidx.health.connect.client.request.ReadRecordsRequest) ) 方法,因为我尝试未成功初始化其输入参数(在我的情况下为 T ),但它不是正确的类型。 .

这是我的代码的一部分:

androidx.health.connect.client.request.ReadRecordsRequest<T> request = new androidx.health.connect.client.request.ReadRecordsRequest<T>(
                        TimeRangeFilter.between(start,end),
                        emptySet(),
                        false,
                        1000,
                        null
                );

                // Call the readRecords method on the HealthConnectClient
                Continuation<? super ReadRecordsResponse<T>> cont = new Continuation<T>() {
                    @NonNull
                    @Override
                    public CoroutineContext getContext() {
                        return null;
                    }

                    @Override
                    public void resumeWith(@NonNull Object o) {

                    }
                };
                List<Record> response = healthConnectClient.readRecords(request,cont);
                return filterOxygenRecords(response);

这些是我得到的错误: “androidx.health.connect.client.HealthConnectClient”中的“readRecords(androidx.health.connect.client.request.ReadRecordsRequest, kotlin.coroutines.Continuation)”无法应用于“(androidx.health.connect.client.request” .ReadRecordsRequest, kotlin.coroutines.Continuation>)'

未知类别:'T'

Picture of the Expected required type vs required one

提前谢谢您。

java android build.gradle health-monitoring healthconnect
1个回答
0
投票

我建议您配置您的项目,以便您只有 Kotlin 中的 Health Connect 特定代码。这样您就不需要完全重构您的项目。

© www.soinside.com 2019 - 2024. All rights reserved.