Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Android Heart Rate Sensor RAW DATA? (reflected light, not the heart beat)

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?

like image 763
tcboy88 Avatar asked May 30 '16 23:05

tcboy88


People also ask

Is there an app on my phone that can check my heartbeat?

Instant Heart Rate for Android and iOS is an app built entirely for the purpose of measuring your heart rate on your phone. If you want to aggregate the readings to your other health and fitness data, you can sync the platform with Google Fit or Apple Health.

How do I check my heart rate sensor?

To use this device, the user must turn on the device and then place his finger correctly on the sensors and press the start button. Then, the heart rate is measured in 15 seconds and displayed on the Seven Segment.


2 Answers

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.

like image 143
Kaamel Avatar answered Nov 15 '22 19:11

Kaamel


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.

like image 35
DzungPV Avatar answered Nov 15 '22 19:11

DzungPV