在Android Wear上获取心率传感器数据

时间:2018-10-30 00:04:26

标签: android wear-os android-sensors android-wear-2.0 moto-360

我正在尝试在Android Wear设备(Moto 360)上获取心率传感器数据。但是我不知道为什么无法识别TYPE_HEART_RATE,并且应用程序显示sensor registered: no。其他类型,例如STEP_COUNTER返回yes

出什么问题了?!

public void onCreate() {
        super.onCreate();
        // register us as a sensor listener
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
        boolean res = mSensorManager.registerListener(this, mHeartRateSensor,  SensorManager.SENSOR_DELAY_UI);
        Log.d(LOG_TAG, " sensor registered: " + (res ? "yes" : "no"));

        mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
        mGoogleApiClient.connect();
    }

1 个答案:

答案 0 :(得分:0)

我们应该转到智能手表的Settings-->Apps-->[App Name]-->Permissions,以检查该权限是否已启用。默认情况下它是禁用的!