I am able to access Heart Rate of User using Optical Heart rate Sensor using SensorEventListener
:
sensorManager.registerListener(this,
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.