Reading Heart Rate Data from Samsung Gear Live

Here’s a quick tutorial on how to get data from the heart rate sensor in your Samsung Gear Live watch.

First, declare this permission in your manifest:

then get an instance of SensorManager and an instance of the Sensor that we want to use, the HR sensor in this case.

I initially tried to use Sensor.TYPE_HEART_RATE which was added in API Level 20 but I always end up getting accuracy = 1 which is the lowest sensor accuracy. Then I found out that the demo app loaded in Samsung Gear Live was actually using a different value for the sensor type:

This produces accuracy = 3 which is what we really need. This isn’t documented elsewhere (as far as I know) so maybe in the future, they’ll update the official documentation or they will fix it in future OS updates.

After that, you can now register a listener for sensor data by calling:

In this case, we let our activity be the listener for sensor data so we must implement SensorEventListener and override these two methods:

Lastly, we need to make sure that we unregister our listener when we exit our application.

Grabe the source code of the sample app here. Enjoy!