1

Currently I'm working with google fit History API on Android for getting the steps count.

I have a problem when developing my application on multiple devices, I will summary it as below.

  1. Device A has 1000 steps today (this device have google fit application)

  2. Device B login with the same google account of device A (this device don't have google fit application). Then I use History API to get the steps count but it return the 0 step.

Can you help me find out why it return 0 step instead of 1000 steps

This is my code for getting the steps count

Fitness.getHistoryClient(this, GoogleSignIn.getLastSignedInAccount(this))
        .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
        .addOnSuccessListener(
            new OnSuccessListener<DataSet>() {
              @Override
              public void onSuccess(DataSet dataSet) {
                long total =
                    dataSet.isEmpty()
                        ? 0
                        : dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt();
                Log.i(TAG, "Total steps: " + total);
              }
            })
        .addOnFailureListener(
            new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "There was a problem getting the step count.", e);
              }
            });
Hien Tran
  • 11
  • 4

0 Answers0