Heart Rate Sensor not found (LG Watch Urbane)

匿名 (未验证) 提交于 2019-12-03 02:35:01

问题:

I'm trying to access to the heart rate sensor of my LG Watch Urbane using this code on MainActivity.java:

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE); boolean sensorRegistered = mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL); Log.d("Sensor Status:", " Sensor registered: " + (sensorRegistered ? "yes" : "no")); 

The problem is that I get this error:

E/SensorManager: sensor or listener is null 

That error happens because there isn't a sensor with TYPE_HEART_RATE associated. So, I wrote some code in order to get the full list of sensors with the method .getSensorList(Sensor.TYPE_ALL) and I got this:

I don't see any heart rate sensor there, so I don't know what type number I have to use in order to get data from it.

Anyone knows what am I doing wrong?

Thanks in advance.

回答1:

Ensure that your application has defined and granted the Body Sensors permission.

Verify that:

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

is present in your AndroidManifest.xml

Also, ensure that the permission has been granted by checking the Permissions settings on the watch: Settings -> Permissions -> Your app



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