Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
766 views
in Technique[技术] by (71.8m points)

android - Heart Rate Sensor not found (LG Watch Urbane)

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:

03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Accelerometer: 1
03-14 02:56:43.221 2936-2936/? I/Sensor?list: AK8963 Magnetometer: 2
03-14 02:56:43.221 2936-2936/? I/Sensor?list: AK8963 Magnetometer     Uncalibrated: 14
03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Gyroscope: 4
03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Gyroscope Uncalibrated: 16
03-14 02:56:43.221 2936-2936/? I/Sensor?list: HSPPAD038 Pressure: 6
03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Accelerometer -Wakeup Secondary: 1
03-14 02:56:43.221 2936-2936/? I/Sensor?list: AK8963 Magnetometer -Wakeup Secondary: 2
03-14 02:56:43.221 2936-2936/? I/Sensor?list: AK8963 Magnetometer Uncalibrated -Wakeup Secondary: 14
03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Gyroscope -Wakeup Secondary: 4
03-14 02:56:43.221 2936-2936/? I/Sensor?list: MPU6515 Gyroscope Uncalibrated -Wakeup Secondary: 16
03-14 02:56:43.221 2936-2936/? I/Sensor?list: HSPPAD038 Pressure -Wakeup Secondary: 6
03-14 02:56:43.221 2936-2936/? I/Sensor?list: Gravity: 9
03-14 02:56:43.221 2936-2936/? I/Sensor?list: Linear Acceleration: 10
03-14 02:56:43.221 2936-2936/? I/Sensor?list: Rotation Vector: 11
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Step Detector: 18
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Step Counter: 19
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Significant Motion Detector: 17
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Game Rotation Vector: 15
03-14 02:56:43.222 2936-2936/? I/Sensor?list: GeoMagnetic Rotation Vector: 20
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Orientation: 3
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Tilt Detector: 22
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Gravity -Wakeup Secondary: 9
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Linear Acceleration -Wakeup Secondary: 10
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Rotation Vector -Wakeup Secondary: 11
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Step Detector -Wakeup Secondary: 18
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Step Counter -Wakeup Secondary: 19
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Game Rotation Vector -Wakeup Secondary: 15
03-14 02:56:43.222 2936-2936/? I/Sensor?list: GeoMagnetic Rotation Vector -Wakeup Secondary: 20
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Orientation -Wakeup Secondary: 3
03-14 02:56:43.222 2936-2936/? I/Sensor?list: Wrist Tilt Gesture: 26

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...