0

在 Android 穿戴项目中,我在访问 Moto 360 上的心跳传感器时遇到了一些问题。使用代码:

    for (Sensor sensor : mSensorManager.getSensorList(Sensor.TYPE_ALL)) {
        Log.e("HB Service", sensor.getName() + ": " + sensor.getType());
    }

我发现心跳传感器和健康传感器都没有出现在这个列表中。我也尝试过使用 Sensor.TYPE_HEART_RATE,但无论哪种方式,注册侦听器都表示传感器为空。有人有建议让这个工作吗?

4

1 回答 1

0

Make sure that you put the permission below for the body data in your Manifest.xml:

uses-permission android:name="android.permission.BODY_SENSORS"

Another workaround in this thread is:

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.

Also make sure that you have the latest SDK. Hope this helps!

于 2016-11-17T15:32:48.573 回答