13

The android sdk on heart rate sensor only returns the calculated bpm which I have no interest.

I need to access to android heart rate sensor RAW data, e.g. in terms of intensity of reflected value would be great. (because basically heart rate sensor uses led and measures the reflectance over time)

If possible, access the the raw image collected by the whatever image sensor would be greater. thanks.

Related SO question: Read underlying color/light data from Android Wear heart rate sensor?

3

2 Answers 2

5
+25

You can use Google Fit's Sensor API to get the raw heartbeat data, if Google Fit is an option. See Google Fit Guide for details.

private void trackHeartRate() {
    SensorsApi.findDataSources(mClient, new DataSourcesRequest.Builder()
            .setDataTypes(DataType.TYPE_HEART_RATE_BPM)
            // Can specify whether data type is raw or derived.
            .setDataSourceTypes(DataSource.TYPE_RAW)
            .build())
            .setResultCallback(new ResultCallback<DataSourcesResult>() {
                @Override
                public void onResult(DataSourcesResult dataSourcesResult) {
                    Log.i(TAG, "Result: " + dataSourcesResult.getStatus().toString());
                    for (DataSource dataSource : dataSourcesResult.getDataSources()) {
                        Log.i(TAG, "Data source found: " + dataSource.toString());
                        Log.i(TAG, "Data Source type: " + dataSource.getDataType().getName());

                        if (dataSource.getDataType().equals(DataType.TYPE_HEART_RATE_BPM)
                                && mListener == null) {
                            Log.i(TAG, "Data source for heart rate found!  Registering.");
                            registerFitnessDataListener(dataSource,
                                    DataType.TYPE_HEART_RATE_BPM);
                        }
                    }
                }
            });
    mListener = new OnDataPointListener() {
        @Override
        public void onDataPoint(DataPoint dataPoint) {
            for (Field field : dataPoint.getDataType().getFields()) {
                Value val = dataPoint.getValue(field);
                Log.i(TAG, "Detected DataPoint field: " + field.getName());
                Log.i(TAG, "Detected DataPoint value: " + val);
            }
        }
    };
}

private void registerFitnessDataListener(DataSource dataSource, DataType dataType) {
    Fitness.SensorsApi.add(
            mClient,
            new SensorRequest.Builder()
                    .setDataSource(dataSource) // Optional but recommended for custom data sets.
                    .setDataType(dataType) // Can't be omitted.
                    .setSamplingRate(10, TimeUnit.SECONDS)
                    .build(),
            mListener)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Listener registered!");
                    } else {
                        Log.i(TAG, "Listener not registered.");
                    }
                }
            });
}

Hope this helps.

3
  • This is very helpful but is still not what I needed. I don't need the heart beating rate, even if it is "RAW" heart rate. I need to access the reflected light that are used to calculate the heart beat. Sorry for not being clear enough.
    – tcboy88
    Jun 11, 2016 at 23:21
  • Your comment and the edited question make it clearer. Unless I am missing something, such digitized waveform data is not available through the Android framework, although it might be part of a device driver level API (I doubt even that). But even in that case, it would be only exposed and available to the manufacturers and OEMs. My recommendation is to search for a standalone device that does what you are looking for, that has some sort of API through BT or WiFi, ideally with some sample code for Android. Good luck!
    – Kaamel
    Jun 12, 2016 at 6:50
  • Thanks, I knew it is not available through API. That's why I was expecting that with Root or modified kernel it might be possible, and was hoping someone knew about it.
    – tcboy88
    Jun 13, 2016 at 4:36
2

This question is old, but for Samsung device you can access raw heart rate sensor like red signal or ir signal (Note 4, Note 5, S6, S7), please check Sensor Extension http://developer.samsung.com/galaxy/sensor-extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.