Damian Ugalde Damian Ugalde - 1 year ago 137
Android Question

How to read Heart rate from Android Wear

I need to read the heart rate of the user at that instant. I tried using this code located in my main activity in the Wear project.

public class MainActivity extends WearableActivity implements SensorEventListener {

private static final String TAG = "MainActivity";
private TextView mTextViewHeart;
SensorManager mSensorManager;
Sensor mHeartRateSensor;
SensorEventListener sensorEventListener;

protected void onCreate(Bundle savedInstanceState) {

mTextViewHeart = (TextView) findViewById(R.id.heart);
mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);
mTextViewHeart.setText("Something here");

mSensorManager.registerListener(sensorEventListener, mHeartRateSensor, mSensorManager.SENSOR_DELAY_FASTEST);

public void onResume(){

public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d(TAG, "onAccuracyChanged - accuracy: " + accuracy);

public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
String msg = "" + (int)event.values[0];
Log.d(TAG, msg);
Log.d(TAG, "Unknown sensor type");


This code is simply not working, giving me an error saying:

E/SensorManager´╣Ľ sensor or listener is null

It works fine if I use anything else but the heart rate sensor.

I am using:

  • LG G4 with android API level 23

  • LG Urbane watch (Which I know has a heart rate sensor) with Wear API level 23

Thank you for your help.

Answer Source

I faced the same problem as you can see in this question. We have the same wear devices, so I'm almost sure that you have missed this on your wear AndroidManifest.xml:

<uses-permission android:name="android.permission.BODY_SENSORS" />

Also, your should go to Permissions in Settings in order to check if that permission is enabled.

You can check my project on GitHub, which is working for now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download