Working with the Google Fit API at the moment and having a bit of trouble with the Sensors API. I'm trying to get user's current speed for my app's workouts but the documentation is a bit confusing.
In this code snippet is an example from Google's info page:
Fitness.SensorsApi.add(
mClient,
new SensorRequest.Builder()
// Optional but recommended for custom data sets.
.setDataType(DataType.TYPE_SPEED)// Can't be omitted.
.setSamplingRate(1, TimeUnit.SECONDS).setAccuracyMode(SensorRequest.ACCURACY_MODE_HIGH)
.build(), mListener3)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
Log.i(TAG, "Listener registered!");
} else {
Log.i(TAG, "Listener not registered.");
}
}
});
//Adding a Listener
mListener3 = new OnDataPointListener() {
@Override
public void onDataPoint(DataPoint dataPoint) {
final float speed = dataPoint.getValue(Field.FIELD_SPEED).asFloat();
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i(TAG, "In Speed" + speed );
speedTxtView.setText("" + speed );
}
});
}
Currently, I am getting all other datatype values like distance, heart rate ,step count and current activity but unable to get user's current speed. Is i am doing correctly?