Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

wear os - How to access heart rate sensor in Android Wearable?

I am having problems accessing heart rate sensor on Moto 360.

I tried following things :

Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
mSensorManager.registerListener(this, mHeartRateSensor, SensorManager.SENSOR_DELAY_NORMAL);

and then implement SensorEventListener interface :

@Override
public void onSensorChanged(SensorEvent event) {

        String TAG = "tag";
        Log.i(TAG, "--------------------------");
        Log.i(TAG, msg);
        Log.i(TAG, ""+ event.sensor.getType());
        Log.i("live","--------------");

And what is strange to me I do not get any messages at all (not only heart rate).

Also I tried listing all sensors and it does not show Heart rate sensor on the list.

Of course I've added persmissions

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.watchtest" >

<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.BODY_SENSORS" />

Any ideas ?

thanks.

w.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Started to work for me after I did the following:

  1. Uninstalled my app from the watch with

    adb -s localhost:4444 uninstall com.example.android.wearable.jumpingjack
    
  2. Added permissions to get the heart rate sensor

    <uses-permission android:name="android.permission.BODY_SENSORS"/>
    
  3. Set the min and target SDK version to match the watch

    android:minSdkVersion="20" android:targetSdkVersion="20"
    

Started the app again. I received the heart rate sensor with Sensor.TYPE_HEART_RATE and I started to receive its readings. Although they were far from good. There were a lot of readings, but they were just the same, limited to these 5 values:

heartRate onSensorChanged values = [0.0], accuracy = 0, sensor = {Sensor name="Heart Rate Sensor", vendor="Motorola", version=1, type=21, maxRange=65535.0, resolution=1.0, power=0.45, minDelay=0}
heartRate onSensorChanged values = [53.0], accuracy = 2, sensor = {Sensor name="Heart Rate Sensor", vendor="Motorola", version=1, type=21, maxRange=65535.0, resolution=1.0, power=0.45, minDelay=0}
heartRate onSensorChanged values = [54.0], accuracy = 2, sensor = {Sensor name="Heart Rate Sensor", vendor="Motorola", version=1, type=21, maxRange=65535.0, resolution=1.0, power=0.45, minDelay=0}
heartRate onSensorChanged values = [55.0], accuracy = 2, sensor = {Sensor name="Heart Rate Sensor", vendor="Motorola", version=1, type=21, maxRange=65535.0, resolution=1.0, power=0.45, minDelay=0}
heartRate onSensorChanged values = [77.0], accuracy = 1, sensor = {Sensor name="Heart Rate Sensor", vendor="Motorola", version=1, type=21, maxRange=65535.0, resolution=1.0, power=0.45, minDelay=0}

Most of the time I was getting the same 53.0 value which doesn't seem to be my real heart rate. 77 could have been the one.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...