我正在尝试使用MainActivity.java上的代码访问我的LG Watch Urbane的心率传感器:
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"));
问题是我收到了这个错误:
E/SensorManager: sensor or listener is null
发生该错误是因为没有关联TYPE_HEART_RATE的传感器。所以,我写了一些代码,以便使用方法.getSensorList(Sensor.TYPE_ALL)获取传感器的完整列表,我得到了这个:
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
我没有看到任何心率传感器,所以我不知道为了从中获取数据我必须使用什么类型的数字。
任何人都知道我做错了什么?
提前致谢。
答案 0 :(得分:4)
确保您的应用已定义并授予Body Sensors权限。
验证:
<uses-permission android:name="android.permission.BODY_SENSORS"/>
出现在您的AndroidManifest.xml
中此外,请检查手表上的权限设置,确保已授予权限:设置 - &gt;权限 - &gt;你的应用