5

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.

dcarr622
  • 1,576
  • 4
  • 15
  • 23
  • Have you solved this problem maybe? – EyesClear Nov 09 '14 at 18:15
  • The sensors API, from my experiences with it, seems incredibly flaky. Hopefully I am doing something wrong and that isn't the case, but there seems to be a distinct lack of people who have had success on this front – Ben Pearson Apr 19 '15 at 14:14
  • See also my reply on a different thread http://stackoverflow.com/a/30947209/2029699 – Alexander K Jun 19 '15 at 21:03

6 Answers6

1

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?

beja80
  • 11
  • 1
  • I put uses-permission in AndroidManifest.xml, but can't get heart rate. SensorManager.getSensorList doesn't return Sensor.TYPE_HEART_RATE. – kazhik Oct 13 '14 at 20:41
  • @kazhik I have the newest SDK and it doesn't work for me. I don't see the heart rate sensor on the list. Could you help me? – EyesClear Nov 09 '14 at 18:14
  • @EyesClear To create a new project may fix your problem. http://stackoverflow.com/questions/26489281/how-to-access-heart-rate-sensor-in-android-wearable – kazhik Nov 11 '14 at 20:48
1

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.

Ben Pearson
  • 7,532
  • 4
  • 30
  • 50
1

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.

Igor
  • 11
  • 1
1

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...

mpkasp
  • 343
  • 3
  • 10
0

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 !!

0

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

liorlis
  • 216
  • 3
  • 14