dcarr622
dcarr622

Reputation: 1706

Having trouble reading heart rate sensor from Moto 360 - Android Wear

Has anyone successfully read the heart rate sensor from the Moto 360?

mSensorManager = ((SensorManager)getSystemService(SENSOR_SERVICE));
mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

I am getting an error that states "SensorManager﹕ sensor or listener is null"

I know the Gear Live uses a different ID other than Sensor.TYPE_HEART_RATE...I'm wondering if that's the case with the Moto 360.

I tried a sensor value of 65538 which reports itself as a "Wellness Sensor" but that does not appear to return data either.

Any advice would be appreciated.

Upvotes: 5

Views: 6483

Answers (6)

liorlis
liorlis

Reputation: 216

From android M you need to make sure that the user is enabling the permission at the first time the applications runs OR going manually to the app permission and enable it

Upvotes: 0

mpkasp
mpkasp

Reputation: 383

Along with making sure permissions are set for BODY_SENSORS in your manifest, make sure, after you install your app, that permissions are enabled:

https://support.google.com/androidwear/answer/6321353?hl=en

This one got me for a while...

Upvotes: 1

Mihir Thakkar
Mihir Thakkar

Reputation: 61

I had same issue with Moto360 and hers how I solved it.

I tried all the solutions listed - re installing the app, upgrading the SDK but it dint work for me. I included permissions for body sensors in Manifest file. I couldn't see heart rate sensor in my list of available sensors. So I believe it was a permissions issue. API 23 onwards android uses a new permissions model.

From this link : https://developer.android.com/training/articles/wear-permissions.html It says - "Note: For an app to use the new permissions model, it must specify a value of 23 for both uses-sdk-element and compileSdkVersion."

I changed my gradel scripts to use both minsdk and compliledsdk as 23. Also added following to my app manifiest.

<uses-sdk android:minSdkVersion="23"
            android:targetSdkVersion="23"
             /> 

And Now its working !!

Upvotes: 0

Igor
Igor

Reputation: 11

Sensor.TYPE_HEART_RATE is actually the correct ID. I had the same issue: the sensor was null even though I had the BODY_SENSORS permission in the manifest. I fixed it by removing the app, restarting the watch and by requesting the BODY_SENSORS permission at runtime (see https://developer.android.com/training/articles/wear-permissions.html). After that I got the system dialogue for the body sensor permission and I then started receiving updates from the sensor. I hope this helps.

Upvotes: 1

Ben Pearson
Ben Pearson

Reputation: 7752

I was having the same problem while trying to poll the heart rate from a Moto 360, the sensor was null. Did the same as you to work out that the sensor available was the wellness sensor:

sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

if (sensor == null) {
  List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL);
  for (Sensor sensor1 : sensors) {
    Log.i(TAG, sensor1.getName() + ": " + availableSensor.getType());
  }
}

65538 seemed to be the correct type to use, so I used that.

Wellness Passive Sensor 65538

A Reddit thread I found suggested this was the correct route to go. I seemed to get readings from it, but they weren't reliable.

With a little bit more research, I discovered an open source project that polls sensor data and displays it. This seems to only work sometimes, so I am treating the sensor APIs as unreliable and have temporarily parked my project. I'll revisit this again in a couple of months and update my answer if I believe the sensor APIs to be any more reliable.

Upvotes: 2

beja80
beja80

Reputation: 11

I am doing the same on my Moto 360 and I get the sensor and the heart rate. Did you put the permission for the body data:

uses-permission android:name="android.permission.BODY_SENSORS"

in your Manifest.xml?

Upvotes: 1

Related Questions