Getting list of activities(Movements) from google fit api

女生的网名这么多〃 提交于 2019-12-19 03:37:23

问题


I am creating application which can use google fit api. I want to get all the activities(Movements) available in the google fit. Here the list of activities in google fit Reference.

Edited

I know the way how to get the activities which performed by user, But i want complete list of activities which available in the google fit API (Not only the activity which performed by user, need whole list of activities) like the list available in the above link.


回答1:


The Google Fit activities are listed in the FitnessActivities class.

You can programmatically get a list of all these fields using:

FitnessActivities.class.getFields()



回答2:


Had similar problem when started playing with Google Fit API on Android.

There are videos with code samples as well as more detailed API documentation on Google Fit website.

It helped me a lot -- https://developers.google.com/fit/android/get-started

Check both videos and later how to save and get data types:

https://developers.google.com/fit/android/data-types

To have some data available install Google Fit app on your android phone. Use it for a while and then you will have some real data in Google Fit database available.

EDIT:

If I get your edited question correctly, then you need something like the following code. Please note that I use this in my own app that lists activities recorded by Google Fit Andorid app. I'm not sure if it will list other activities, for example custom data types recorded by other apps.

Request "activites" (like STILL, RUNNING, WALKING) from Google Fit:

        DataReadRequest readRequest = new DataReadRequest.Builder()
            .read(DataType.TYPE_ACTIVITY_SEGMENT)
            // maybe you want to limit data to specific time range?
            //.setTimeRange(today.startTime, today.endTime, TimeUnit.MILLISECONDS)
            .build();

Then parse the response. While parsing there will be activity time available:

        Fitness.HistoryApi.readData(mClient, readRequest).setResultCallback(new ResultCallback<DataReadResult>() {
        @Override
        public void onResult(DataReadResult dataReadResult) {
            for (DataSet dataSet : dataReadResult.getDataSets()) {
                for (DataPoint dataPoint : dataSet.getDataPoints()) {
                    DataType dataType = dataPoint.getDataType();
                    if (dataType.equals(DataType.TYPE_ACTIVITY_SEGMENT)) {
                        String activity = FitnessActivities.getValue(dataPoint);

                        /* process as needed */
                        /* the `activitity' string contains values as described here:
                         * https://developer.android.com/reference/com/google/android/gms/fitness/FitnessActivities.html
                         */

                    }
                }
            }
        }
    });

Like I said it works for me -- in my own app I list activities (and their type, ie. walking, running, etc) recorded by Google Fit app for Android.




回答3:


Hope this can help others...

List<Session> sessions = sessionReadResponse.getSessions();

for (Session session : sessions) {
    dumpSession(session);
    Log.i(TAG, "Activity Name: "+sessions.get(position).getActivity());
    position++;
    List<DataSet> dataSets = sessionReadResponse.getDataSet(session);
    for (DataSet dataSet : dataSets) {
        dumpDataSet(dataSet);
    }
}


来源:https://stackoverflow.com/questions/27163326/getting-list-of-activitiesmovements-from-google-fit-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!