Steps Data receive from History api is not matched with google fit











up vote
1
down vote

favorite
1












I want google fit steps count in my application, for that I am using History api, provided by google. I found that steps receive from history api is not matched with google fit even if i used same code provided by google. Below is my code.



  Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
long startTime = cal.getTimeInMillis();

DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();

DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);


Any Help will be highly appreciated, I am stuck with this issue from long time and even not finding any proper tutorial from google.










share|improve this question




























    up vote
    1
    down vote

    favorite
    1












    I want google fit steps count in my application, for that I am using History api, provided by google. I found that steps receive from history api is not matched with google fit even if i used same code provided by google. Below is my code.



      Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    long endTime = cal.getTimeInMillis();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    long startTime = cal.getTimeInMillis();

    DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
    .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
    .setType(DataSource.TYPE_DERIVED)
    .setStreamName("estimated_steps")
    .setAppPackageName("com.google.android.gms")
    .build();

    DataReadRequest readRequest = new DataReadRequest.Builder()
    .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
    .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
    .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
    .bucketByTime(1, TimeUnit.DAYS)
    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
    .build();

    Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
    GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);


    Any Help will be highly appreciated, I am stuck with this issue from long time and even not finding any proper tutorial from google.










    share|improve this question


























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I want google fit steps count in my application, for that I am using History api, provided by google. I found that steps receive from history api is not matched with google fit even if i used same code provided by google. Below is my code.



        Calendar cal = Calendar.getInstance();
      Date now = new Date();
      cal.setTime(now);
      long endTime = cal.getTimeInMillis();
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      long startTime = cal.getTimeInMillis();

      DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
      .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
      .setType(DataSource.TYPE_DERIVED)
      .setStreamName("estimated_steps")
      .setAppPackageName("com.google.android.gms")
      .build();

      DataReadRequest readRequest = new DataReadRequest.Builder()
      .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
      .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
      .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
      .bucketByTime(1, TimeUnit.DAYS)
      .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
      .build();

      Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
      GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);


      Any Help will be highly appreciated, I am stuck with this issue from long time and even not finding any proper tutorial from google.










      share|improve this question















      I want google fit steps count in my application, for that I am using History api, provided by google. I found that steps receive from history api is not matched with google fit even if i used same code provided by google. Below is my code.



        Calendar cal = Calendar.getInstance();
      Date now = new Date();
      cal.setTime(now);
      long endTime = cal.getTimeInMillis();
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      long startTime = cal.getTimeInMillis();

      DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
      .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
      .setType(DataSource.TYPE_DERIVED)
      .setStreamName("estimated_steps")
      .setAppPackageName("com.google.android.gms")
      .build();

      DataReadRequest readRequest = new DataReadRequest.Builder()
      .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
      .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
      .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
      .bucketByTime(1, TimeUnit.DAYS)
      .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
      .build();

      Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
      GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);


      Any Help will be highly appreciated, I am stuck with this issue from long time and even not finding any proper tutorial from google.







      android google-api-client google-fit google-fit-sdk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 8 at 4:44









      Mike Stockdale

      4,68832533




      4,68832533










      asked Nov 3 at 6:06









      Harsh Trivedi

      695622




      695622
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          see the FAQ, which explain the behavior quite literally, which you're descibing.



          this is possibly the closest one can get; assuming the latest Play Services installed on device:



          DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
          .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
          .setType(DataSource.TYPE_DERIVED)
          .setStreamName("estimated_steps")
          .setAppPackageName("com.google.android.gms")
          .build();

          DataReadRequest readRequest = new DataReadRequest.Builder()
          .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
          .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
          .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
          .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
          .bucketByTime(1, TimeUnit.DAYS)
          .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
          .build();


          it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.






          share|improve this answer




























            up vote
            0
            down vote













            I am using history api in my app and compared the output with Google FIT app, they are quite same.



            val c = GregorianCalendar()
            c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
            c.set(Calendar.MINUTE, 0)
            c.set(Calendar.SECOND, 0)
            var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
            var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
            val readRequest = DataReadRequest.Builder()
            .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
            .bucketByTime(1 , TimeUnit.DAYS)
            .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
            .build()
            val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
            pendingResult.setResultCallback(this)





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128859%2fsteps-data-receive-from-history-api-is-not-matched-with-google-fit%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote













              see the FAQ, which explain the behavior quite literally, which you're descibing.



              this is possibly the closest one can get; assuming the latest Play Services installed on device:



              DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
              .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
              .setType(DataSource.TYPE_DERIVED)
              .setStreamName("estimated_steps")
              .setAppPackageName("com.google.android.gms")
              .build();

              DataReadRequest readRequest = new DataReadRequest.Builder()
              .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
              .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
              .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
              .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
              .bucketByTime(1, TimeUnit.DAYS)
              .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
              .build();


              it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.






              share|improve this answer

























                up vote
                1
                down vote













                see the FAQ, which explain the behavior quite literally, which you're descibing.



                this is possibly the closest one can get; assuming the latest Play Services installed on device:



                DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
                .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                .setType(DataSource.TYPE_DERIVED)
                .setStreamName("estimated_steps")
                .setAppPackageName("com.google.android.gms")
                .build();

                DataReadRequest readRequest = new DataReadRequest.Builder()
                .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
                .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
                .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
                .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
                .bucketByTime(1, TimeUnit.DAYS)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build();


                it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  see the FAQ, which explain the behavior quite literally, which you're descibing.



                  this is possibly the closest one can get; assuming the latest Play Services installed on device:



                  DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
                  .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                  .setType(DataSource.TYPE_DERIVED)
                  .setStreamName("estimated_steps")
                  .setAppPackageName("com.google.android.gms")
                  .build();

                  DataReadRequest readRequest = new DataReadRequest.Builder()
                  .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
                  .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
                  .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
                  .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
                  .bucketByTime(1, TimeUnit.DAYS)
                  .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                  .build();


                  it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.






                  share|improve this answer












                  see the FAQ, which explain the behavior quite literally, which you're descibing.



                  this is possibly the closest one can get; assuming the latest Play Services installed on device:



                  DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
                  .setDataType(DataType.TYPE_STEP_COUNT_DELTA)
                  .setType(DataSource.TYPE_DERIVED)
                  .setStreamName("estimated_steps")
                  .setAppPackageName("com.google.android.gms")
                  .build();

                  DataReadRequest readRequest = new DataReadRequest.Builder()
                  .aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
                  .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
                  .aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
                  .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
                  .bucketByTime(1, TimeUnit.DAYS)
                  .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                  .build();


                  it's quite the same, except TYPE_CALORIES_EXPENDED. alternatively, you could record you own sessions - which are not just estimated_steps, but have a unique session identifier.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 18 at 19:10









                  Martin Zeitler

                  12.2k33560




                  12.2k33560
























                      up vote
                      0
                      down vote













                      I am using history api in my app and compared the output with Google FIT app, they are quite same.



                      val c = GregorianCalendar()
                      c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
                      c.set(Calendar.MINUTE, 0)
                      c.set(Calendar.SECOND, 0)
                      var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
                      var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
                      val readRequest = DataReadRequest.Builder()
                      .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                      .bucketByTime(1 , TimeUnit.DAYS)
                      .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                      .build()
                      val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
                      pendingResult.setResultCallback(this)





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        I am using history api in my app and compared the output with Google FIT app, they are quite same.



                        val c = GregorianCalendar()
                        c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
                        c.set(Calendar.MINUTE, 0)
                        c.set(Calendar.SECOND, 0)
                        var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
                        var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
                        val readRequest = DataReadRequest.Builder()
                        .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                        .bucketByTime(1 , TimeUnit.DAYS)
                        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                        .build()
                        val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
                        pendingResult.setResultCallback(this)





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I am using history api in my app and compared the output with Google FIT app, they are quite same.



                          val c = GregorianCalendar()
                          c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
                          c.set(Calendar.MINUTE, 0)
                          c.set(Calendar.SECOND, 0)
                          var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
                          var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
                          val readRequest = DataReadRequest.Builder()
                          .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                          .bucketByTime(1 , TimeUnit.DAYS)
                          .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                          .build()
                          val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
                          pendingResult.setResultCallback(this)





                          share|improve this answer












                          I am using history api in my app and compared the output with Google FIT app, they are quite same.



                          val c = GregorianCalendar()
                          c.set(Calendar.HOUR_OF_DAY, 0) //anything 0 - 23
                          c.set(Calendar.MINUTE, 0)
                          c.set(Calendar.SECOND, 0)
                          var endTime = /*date.time + dayInMS*/(getCurrentUTCDate()*1000)
                          var startTime = (ConfigVariable.appLastUpdateTime*1000) //converting last updated data from second to MS
                          val readRequest = DataReadRequest.Builder()
                          .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
                          .bucketByTime(1 , TimeUnit.DAYS)
                          .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                          .build()
                          val pendingResult = Fitness.HistoryApi.readData(mGoogleApiClient,readRequest)
                          pendingResult.setResultCallback(this)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 19 at 6:17









                          Rakez Bohara

                          112




                          112






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53128859%2fsteps-data-receive-from-history-api-is-not-matched-with-google-fit%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Xamarin.form Move up view when keyboard appear

                              Post-Redirect-Get with Spring WebFlux and Thymeleaf

                              Anylogic : not able to use stopDelay()