Andrej
Andrej

Reputation: 3235

Wear OS HealthServices only return HeartRate when requesting supported capabilities

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

Upvotes: 0

Views: 32

Answers (1)

Breana
Breana

Reputation: 381

MeasureClient 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.

Upvotes: 0

Related Questions