How to access heart rate sensor in Android Wearable?
Asked Answered
F

4

13

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.

Findley answered 21/10, 2014 at 14:32 Comment(4)
Have you tried updating the SDK? linkNeurocoele
I agree with Kent, make sure your SDK is up to date, someone had a similar issue fixed: #25821271Bullins
@Neurocoele Is project somehow tied to the SDK? As I had latest SDK and it did not work. But when I created new project it start working.Findley
I had same problem. I got som values for a short periode of time, then it returned the same values for a minute or so, then giving me a few different values, before it again stopped. seams like it´s a general problem for Moto 360.Giuseppinagiustina
F
1

As @Kent and @Murphy suggested, updated SDK was the solution. In my case I needed to drop the project and create new from scratch as even with updated SDK old one did not work.

Findley answered 23/10, 2014 at 5:7 Comment(4)
Can you accept this answer? This way everyone knows it's been resolved.Bullins
I believe the trick is to uninstall the app from the watch. Here is a sample command: adb -s localhost:4444 uninstall com.example.android.wearable.jumpingjackDiatonic
I also have: android:minSdkVersion="20" android:targetSdkVersion="20" And SDK version of watch is 4.4W.2, and in my SDK Manager it is rev.2 for SDK Platform, rev. 3 for sample, rev. 4 for Wear images and rev. 1 for sources.Diatonic
With these changes, I now have Heart Rate Sensor and am able to get reading from it.Diatonic
D
6

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.

Diatonic answered 19/6, 2015 at 21:1 Comment(0)
A
2

I had quite a similar problem on the Moto 360. The sensor always returned 0.0f as a value.

Then I waited for two minutes, and suddenly values!=0 came in. It seems that this sensor needs a "warmup" before showing anything. Not really astonishing if you take into account that it measures something happening roughly once a second with the unit "beats per minute". It cannot be reliable before one or two minutes have passed. And each app has its own measurement: It doesn't matter if another heartbeat app is also running (like the Moto Body thing).

This also means that you must create a service to listen to the sensor (and a binder to pass the sensor's value to your activity or your phone).

Have a look at the demo project I shared on github: https://github.com/upost/MyHeartbeat

Anjelicaanjou answered 1/4, 2015 at 15:54 Comment(0)
F
1

As @Kent and @Murphy suggested, updated SDK was the solution. In my case I needed to drop the project and create new from scratch as even with updated SDK old one did not work.

Findley answered 23/10, 2014 at 5:7 Comment(4)
Can you accept this answer? This way everyone knows it's been resolved.Bullins
I believe the trick is to uninstall the app from the watch. Here is a sample command: adb -s localhost:4444 uninstall com.example.android.wearable.jumpingjackDiatonic
I also have: android:minSdkVersion="20" android:targetSdkVersion="20" And SDK version of watch is 4.4W.2, and in my SDK Manager it is rev.2 for SDK Platform, rev. 3 for sample, rev. 4 for Wear images and rev. 1 for sources.Diatonic
With these changes, I now have Heart Rate Sensor and am able to get reading from it.Diatonic
P
0

So, I came here, with the same problem and the simple solution is to remove the application from the watch using the adb:

adb -s localhost:4444 uninstall com.*packagename*

Then simply reinstall it using android studio, eclipse or whatever you used originally.

Thanks to Alexander K for this solution

Parvis answered 26/11, 2015 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.