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

耗尽温柔 提交于 2019-11-30 10:02:28

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?

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.

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.

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!