Android Wear: How to get raw PPG data?
Asked Answered
R

1

2

I am able to access Heart Rate of User using Optical Heart rate Sensor using SensorEventListener:

sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE),
                SensorManager.SENSOR_DELAY_NORMAL);

What I need is to get raw PPG data like: https://ars.els-cdn.com/content/image/1-s2.0-S0960077915001344-gr1.jpg

Through Google Fit or any other means can I get this data?

I looked into Google Fit API usage: https://developers.google.com/fit/android/sensors

It gives TYPE_HEART_RATE_BPM and HEART_RATE_SUMMARY , but not PPG raw data.

Reactant answered 22/11, 2017 at 21:42 Comment(1)
Only on devices that give you an explicit PPG API: https://mcmap.net/q/912069/-is-it-possible-to-get-ppg-photoplethysmogram-data-from-a-smart-watch-via-android/295004Monosome
B
12

I spent some time figuring out if it's feasible to get the raw PPG signal from android API, and contrary to what some may say, it is definitely possible to do that. And here is how to do it:

1- Get the sensor type (represented by a number) of your PPG sensor (it is a constant that describes the sensor). This can be done by listing all the available sensors on your device:

List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
        for (Sensor currentSensor : sensorList) {
            Log.d("List sensors", "Name: "+currentSensor.getName() + " /Type_String: " +currentSensor.getStringType()+ " /Type_number: "+currentSensor.getType());
        }

2- Then, try to find the sensorType of your PPG sensor. In your output, you will find one of the sensors containing the word ppg in it's type. For instance here is what the ppg sensor of my Huawei watch 2 looks like:

Name: AFE4405 light Sensor /Type_String:  com.huawei.watch.ppg /Type_Number: 65537

3-Register your listener using the the type_number of your ppg sensor, mine is 65537 so I would do this:

sensorManager.registerListener(this,sensorManager.getDefaultSensor(65537),SensorManager.SENSOR_DELAY_NORMAL);

4-Listen to changes in your sensor data:

public void onSensorChanged(SensorEvent event) {

       if (event.sensor.getType() == 65537) {
            String msg = "PPG " + (int) event.values[0];
            //Do something with your PPG signal

        } 

}

And you are all set. Hope it works for you.

Boggers answered 14/9, 2018 at 17:54 Comment(11)
I made this into a plugin: pub.dev/packages/ppg Also, there were actually 2 channels on the devices I used (Fossil Sport and Fossil Gen 5) and your code only grabs the first channel (event.values[0])Narbada
Once I start listening to the PPG sensor, it doesn't shut off and drains the battery even after the app is closed. Did you have this issue?Narbada
If you want to stop listening to PPG events when the app is backgrounded, you can unregister your listener in onPause method and register it back in onResume method of your app.Boggers
I know it has been a while since the last comment, but have any of you prototyped in iOS? I'm trying to achieve the same goal, but the Swift Sensors SDK is still experimental and I'm attempting to do that using only raw Bluetooth Standards Thank you for the guidance, helped me a lot already!Massengale
@MehdiBoukhechba sir I have tried this method in galaxy watch 4, but when I’m trying to retrieve the data from this sensor no data is generated.Unexampled
@MehdiBoukhechba sir can you please guide me on how to get ppg data from the smartwatch I have tried this method but it's not workingUnexampled
@Unexampled did u manage to get the sensor data? I tried on Samsung Galaxy Watch 4 but can not retrieve the data types which is not part of Android sensors. All the data which are part of com.samsung.sensor are not retrievableLepido
@Lepido Yes I did, I applied for Samsung Privileged Health SDK partnership programme and by using that SDK I was able to extract raw PPG values.Unexampled
@Unexampled Thanks. after your help, I had applied for Samsung Privileged Health SDK partnership program and app got approved. I received the email and However I did not get the SDK yet. Do they provide SDK or Key ... from where/Who do we get it.In the Samsung approval dash board there is no option of downloading the SDK......how did they (Samsung)the shared the SDK with you after approve. Again, thanks a lot for the help.Lepido
@gauranga after approval from Samsung team you will get a link to download SDK. Check your mail somewhere it will mentioned for downloading the SDK.Unexampled
@gauranga it's already in there website i think you can download it from there and follow the documentation to implement it in appUnexampled

© 2022 - 2024 — McMap. All rights reserved.