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());
}
}