admin管理员组文章数量:1296300
I'm trying to read the number of steps in the last day on Wear OS using Java. My goal is to reward the user if they achieve a certain number of steps.
To achieve this I tried using HealthServices
. I followed this guide from the official Android Developers website. I added the required ACTIVITY_RECOGNITION
permission to my AndroidManifest
file and requested it at runtime in my Java code.
The problem is that when I try to get the list of supported capabilities (data types) I get a set which only contains one DataType
, heart rate. I tested both on an Wear OS emulator (API 34) and physical Wear OS device (Galaxy Watch 5 Pro). When testing on the emulator I updated to the latest version of Android Studio which has the Wear Health Services option for Wear OS devices. I enabled all available capabilities and still nothing changed.
What could be causing the problem? Is this even the correct approach to getting the number of steps in the last day?
public void setupMeasureClient() {
measureClient = HealthServices.getClient(context).getMeasureClient();
}
public void loadSupportedDataTypes() {
if (measureClient == null) return;
if (!permissionHandler.hasPermission(ACTIVITY_RECOGNITION_PERMISSION)) return;
try {
ListenableFuture<MeasureCapabilities> future = measureClient.getCapabilitiesAsync();
future.addListener(() -> {
try {
MeasureCapabilities measureCapabilities = future.get();
Set<DeltaDataType<?, ?>> dataTypes = measureCapabilities.getSupportedDataTypesMeasure();
System.out.println("[HealthServices] Available data types:");
for (final DeltaDataType<?, ?> dataType: dataTypes) {
System.out.println("[HealthServices] Data type: " + dataType.getName());
}
setDataTypes(dataTypes);
} catch (Exception e) {
System.err.println("[HealthServices] Error occurred while resolving future: " + e.getMessage());
}
}, Executors.newSingleThreadExecutor());
} catch (Exception e) {
System.out.println("[HealthServices] Couldn't get list of capabilities: " + e.getMessage());
}
}
I'm trying to read the number of steps in the last day on Wear OS using Java. My goal is to reward the user if they achieve a certain number of steps.
To achieve this I tried using HealthServices
. I followed this guide from the official Android Developers website. I added the required ACTIVITY_RECOGNITION
permission to my AndroidManifest
file and requested it at runtime in my Java code.
The problem is that when I try to get the list of supported capabilities (data types) I get a set which only contains one DataType
, heart rate. I tested both on an Wear OS emulator (API 34) and physical Wear OS device (Galaxy Watch 5 Pro). When testing on the emulator I updated to the latest version of Android Studio which has the Wear Health Services option for Wear OS devices. I enabled all available capabilities and still nothing changed.
What could be causing the problem? Is this even the correct approach to getting the number of steps in the last day?
public void setupMeasureClient() {
measureClient = HealthServices.getClient(context).getMeasureClient();
}
public void loadSupportedDataTypes() {
if (measureClient == null) return;
if (!permissionHandler.hasPermission(ACTIVITY_RECOGNITION_PERMISSION)) return;
try {
ListenableFuture<MeasureCapabilities> future = measureClient.getCapabilitiesAsync();
future.addListener(() -> {
try {
MeasureCapabilities measureCapabilities = future.get();
Set<DeltaDataType<?, ?>> dataTypes = measureCapabilities.getSupportedDataTypesMeasure();
System.out.println("[HealthServices] Available data types:");
for (final DeltaDataType<?, ?> dataType: dataTypes) {
System.out.println("[HealthServices] Data type: " + dataType.getName());
}
setDataTypes(dataTypes);
} catch (Exception e) {
System.err.println("[HealthServices] Error occurred while resolving future: " + e.getMessage());
}
}, Executors.newSingleThreadExecutor());
} catch (Exception e) {
System.out.println("[HealthServices] Couldn't get list of capabilities: " + e.getMessage());
}
}
Share
Improve this question
asked Feb 11 at 21:26
AndrejAndrej
3,2353 gold badges19 silver badges37 bronze badges
1 Answer
Reset to default 0MeasureClient
is for use cases that need brief access to the sensors. A common scenario might be showing the user their Heart Rate in the moment.
PassiveMonitoringClient
is well-suited for your use case. This will allow you to receive updates about the user's daily metrics like steps, distance, and floors climbed. It might also be helpful to take a look at this sample, which demonstrates tracking daily steps.
版权声明:本文标题:java - Wear OS HealthServices only return HeartRate when requesting supported capabilities - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741633974a2389531.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论