Android Google fit recording API not working -


i wanted integrate google fit recording api application. , want read data using history api. phone have uninstalled google fit application can make sure recording api integration working perfect.

please find code below have done. when retrieving data using history api, getting buckets walks done data point coming empty. can me.

client = new googleapiclient.builder(context)                 .addapi(fitness.history_api)                 .addapi(fitness.recording_api)                 .addscope(new scope(scopes.fitness_activity_read_write))                 .addconnectioncallbacks(                         new googleapiclient.connectioncallbacks() {                             @override                             public void onconnected(bundle bundle) {                                 log.i(google_fit_tag, "connected!");                                 subscribe();                                 bus.post(new googlefitconnectevent());                             }                              @override                             public void onconnectionsuspended(int i) {                                 string errormessage = "connection lost. ";                                 if (i == googleapiclient.connectioncallbacks.cause_network_lost) {                                     errormessage += "cause: network lost.";                                     log.i(google_fit_tag, errormessage);                                 } else if (i == googleapiclient.connectioncallbacks.cause_service_disconnected) {                                     errormessage = "reason: service disconnected";                                     log.i(google_fit_tag, errormessage);                                 }                                  bus.post(new googlefitconnectionerrorevent(errormessage));                             }                         }                 )                 .build();  public void subscribe() {         fitness.recordingapi.subscribe(client, datatype.type_activity_sample)                 .setresultcallback(new resultcallback<status>() {                     @override                     public void onresult(status status) {                         if (status.issuccess()) {                          } else {                             log.i(google_fit_tag, "there problem subscribing.");                         }                     }                 });     } //read data history api:  fitness.historyapi.readdata(client, buildquery(starttime, endtime))                 .setresultcallback(new resultcallback<datareadresult>() {                     @override                     public void onresult(datareadresult datareadresult) {                         set<workout> parsedworkouts = parseworkoutsfromfitnessdata(datareadresult);                     }                 }, constants.google_fit_timeout, constants.google_fit_timeout_timeunit);    private datareadrequest buildquery(long starttime, long endtime) {         datareadrequest readrequest = new datareadrequest.builder()                  .aggregate(datatype.type_step_count_delta, datatype.aggregate_step_count_delta)                              .bucketbyactivitysegment(1, timeunit.minutes)                 .enableserverqueries()                 .settimerange(starttime, endtime, timeunit.milliseconds)                 .build();          return readrequest;     }  private set<workout> parseworkoutsfromfitnessdata(datareadresult datareadresult) {         list<workout> workouts = new arraylist<>();          (bucket bucket : datareadresult.getbuckets()) {              (dataset dataset : bucket.getdatasets()) {                  (datapoint dp : dataset.getdatapoints()) {                      (field field : dp.getdatatype().getfields()) {                         log.i(google_fit_tag, "\tfield: " + field.getname() + " value: " + dp.getvalue(field) + " ");                     }                          if (bucket.getactivity().equals(fitnessactivities.running) || bucket.getactivity().equals(fitnessactivities.walking)) {                             long duration = dp.getendtime(timeunit.minutes) - dp.getstarttime(timeunit.minutes);                          }                  }             }         } 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -