Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to read steps session wise. #18

Open
codingjeremy opened this issue Sep 10, 2019 · 0 comments
Open

How to read steps session wise. #18

codingjeremy opened this issue Sep 10, 2019 · 0 comments
Labels
migrated googlesamples Migrated from old googlesamples repos

Comments

@codingjeremy
Copy link
Contributor

Issue by krunal93
Monday Jul 02, 2018 at 13:53 GMT
Originally opened as googlearchive/android-fit#37


I am in need to show steps time line wise like below.

Time 10 am - 56 steps
Time 11 am - 156 steps
Time 4.30 pm - 236 steps

I don't want to aggregate by hour or anything , i just want the actual data that is currently google fit app is showing in timeline using steps filter.

However i am able to retrieve steps using bucketBySession that entered manually into google fit app but not able to retrieve those steps history which is generated automatically.

Please let me know how to overcome this.

Below is my sample code.

       // Build a session read request
       SessionReadRequest readRequest = new SessionReadRequest.Builder()
               .setTimeInterval(times[0], times[1], TimeUnit.MILLISECONDS)
               .readSessionsFromAllApps()
               .read(DataType.TYPE_STEP_COUNT_DELTA)
               .enableServerQueries()
               .build();

       Fitness.getSessionsClient(mContext, GoogleSignIn.getLastSignedInAccount(mContext))
               .readSession(readRequest)
               .addOnSuccessListener(new OnSuccessListener<SessionReadResponse>() {
                   @Override
                   public void onSuccess(SessionReadResponse sessionReadResponse) {
                       // Get a list of the sessions that match the criteria to check the result.
                       List<Session> sessions = sessionReadResponse.getSessions();
                       Log.i(TAG, "Session read was successful. Number of returned sessions is: "
                               + sessions.size());

                       for (Session session : sessions) {
                           // Process the session
                           dumpSession(session);

                           // Process the data sets for this session
                           List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
                           for (DataSet dataSet : dataSets) {
                               dumpDataSet(dataSet);
                           }
                       }
                   }
               })
               .addOnFailureListener(new OnFailureListener() {
                   @Override
                   public void onFailure(@NonNull Exception e) {
                       Log.i(TAG, "Failed to read session");
                   }
               });

    final DataReadRequest req = new DataReadRequest.Builder()
               .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
               .aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
               .enableServerQueries()
               .bucketBySession(1, TimeUnit.MINUTES)
               .setTimeRange(times[0], times[1], TimeUnit.MILLISECONDS)
               .build();

   Fitness.getHistoryClient(mContext, GoogleSignIn.getLastSignedInAccount(mContext))
               .readData(req)
               .addOnSuccessListener(
                       dataReadResponse -> readData(dataReadResponse, MESSAGE_HEALTH_DATA_LIST_KEY))
               .addOnFailureListener(
                       e -> {
                       });

I am trying with the both client , session as well as history but didn't get any suceess.
thanks,
Krunal

@codingjeremy codingjeremy added the migrated googlesamples Migrated from old googlesamples repos label Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migrated googlesamples Migrated from old googlesamples repos
Projects
None yet
Development

No branches or pull requests

1 participant