4

As far as I know , moto360 doesn't have a sensor of type : TYPE_HEART_RATE, it's called passive wellness sensor.

The problem is that this wellness sensor is not giving me any data, as opposed to every other sensor that I've tried (like gravity, accelerometer...)

I've been waiting for more than 5 min but this sensor gives me data only when I start the app.

I've tried sdk20,sdk21,sdk22,sdk23 ... still no result I also have the android.permission.BODY_SENSORS in my manifest

Question : How to get the sensor working, what can I do?

package com.x.firstapp;

import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.Toast;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.WindowManager;


public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mHeartSensor;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
    stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
        @Override
        public void onLayoutInflated(WatchViewStub stub) {
        }
    });

    // keep watch screen on 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    Toast.makeText(getApplicationContext(), "Hi Oleg", Toast.LENGTH_LONG).show();


    mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
    mHeartSensor = mSensorManager.getDefaultSensor(65538); //wellness sensor
    mSensorManager.registerListener(this, mHeartSensor, SensorManager.SENSOR_DELAY_NORMAL);

}


public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == 65538) {
        String msg = "" + (int) event.values[0];
        Log.d("Main Activity", msg);
    }
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
    Log.d("Main Activity", "accuracy : " + accuracy + " sensor : " + sensor.getName());
}

@Override
protected void onStop() {
    super.onStop();
    mSensorManager.unregisterListener(this);
}

}

only output out of this "wellness" sensor (only when app starts) :

D/Main Activity: accuracy : 3 sensor : Wellness Passive Sensor

D/Main Activity: 0

Oleg
  • 1,479
  • 3
  • 21
  • 42

3 Answers3

3

As you know ,the value of TYPE_HEART_RATE is not equal to the Wellness Passive Sensor, but when I set as below:

Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);

I find, I get the heart beat values. By the way, don't forget to add permission.

Gepser Hoil
  • 3,998
  • 4
  • 24
  • 34
alvin
  • 46
  • 2
0

I remember having huge problems specifically on the Moto 360 (first gen) when trying to read heart rate data. You're doing the correct thing using the passive wellness sensor as there isn't a heart rate monitor reported in the list of sensors.

Have a look at the Github repo here for inspiration (that's what I did to figure it out): https://github.com/pocmo/SensorDashboard

It's worth noting that even if you get it working, it's incredibly flaky. It's even flaky through the built in apps - have a play around with the Google Fit and Moto Body to take your heart rate, you'll see what I mean.

Ben Pearson
  • 7,532
  • 4
  • 30
  • 50
0

Google have API for fitness sensors, look at the following links https://developers.google.com/fit/android/sensors And project for example https://github.com/googlesamples/android-fit/tree/master/BasicSensorsApi